Today I Learned

Stubbing responses from AWS services

We have started integration with Amazon SQS recently and did need to write some unit tests related to it. Unfortunately stubbing AWS client library the regular way turned out to be pretty cumbersome and challenging. Fortunately AWS SDK for ruby provides tools that make it pretty comfortable.

# Simple stubbing...
sqs_response_mock =
sqs_response_mock.messages << 'abc')
Aws.config[:sqs] = {
    stub_responses: {
        receive_message: sqs_response_mock

# ...allows properly polling the queue
poller ='')
poller.poll do |msg|
  puts msg.body

# => abc

Documentation can be found here