ampedandwired/bora

Use Aws::ClientStubs

Closed this issue · 5 comments

aws-sdk has mocking capability built in.

http://docs.aws.amazon.com/sdkforruby/api/Aws/ClientStubs.html

Would this be better to use than OpenStruct in some of the spec tests?

Possibly, and coincidentally I was looking at that just the other day.

Anyway, the specs are a bit of a mess, I'm planning on cleaning them up soon, so will consider ClientStubs as part of it.

I'll give it a try for the resolvers as a bit of a learning exercise ..

One thing you can't do with the AWS stubbing functionality is set expectations, for example:

expect(cloudformation_api).to receive(:delete_stack).with(stack_name: "my-stack").and_return(my_mock_response)

As I recall that is why I originally didn't go down that path. Worth revisiting though.

You can do this:

expect_any_instance_of(Aws::S3::Client).to receive(:put_object)
.with({bucket: 'mybucket', body: 'file/path', key: 'myfilename'})

But if you need to deal with responses and the response is complicated it gets messy. Kind of using the AWS stubs at times but they're not awesome.

I've cleaned up the specs a bit and replaced the OpenStructs with Hashie::Mash which is easier to use.

I think the main advantage of using the AWS client stubs over this setup is that the client stubs validate your responses against the AWS schema, which could catch some errors. On the downside, there doesn't seem to be an easy way to set expectations on the stubs, as per my example above in a previous comment.

So neither solution seems completely ideal, however all other things being equal I'd prefer to be able to easily use rspec expectations on the AWS APIs. I'll close this issue for now, however I could be swayed if it turns out there's a way to get request expectations as well as response schema validation using AWS stubs.