Uh oh!
There was an error while loading. Please reload this page.
This repository was archived by the owner on Feb 4, 2026. It is now read-only.
Example listing and filtering EC2 instances and using stubs - #3
Open
jkanywhere wants to merge 6 commits into
Open
Example listing and filtering EC2 instances and using stubs#3jkanywhere wants to merge 6 commits into
jkanywhere wants to merge 6 commits into
Conversation
Client side filter for EC2 instances based on a Name tag pattern. Use of RSpec to test that code using stubs. RSpec example currently fails, and I do not know why. Failures: 1) InstanceManager#instances returns only EC2 instances with matching Name tag Failure/Error: expect(subject.instances.map(&:id)).to eq ["i-1", "i-2"] expected: ["i-1", "i-2"] got: ["i-1", "i-2", "i-1", "i-2"] (compared using ==) # ./spec/instance_manager_spec.rb:54:in `block (3 levels) in <top (required)>'
A very simple RSpec example showing how stub_responses affects the Aws::EC2::Client interface correctly, but results in doubled resonses from the Aws::EC2::Resource interface.
The default stub returns non-empty strings for all possible string values. This causes the next token that trigger paging to appear like there is a next response. I updated your stubbs to use nil next tokens to avoid this issue. Please feel free to open this as an issue against aws/aws-sdk-ruby as this is a poor default experience.
Fix broken tests by using `nil` next tokens to avoid erroneous paging.
jkanywhere
commented
May 2, 2015
Author
cc @trevorrowe , and thanks for your help. |
And describe the `list_instances.rb`/`InstanceManager` example in the README.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The API reference for AWS Ruby SDK v2 is quite good and detailed, but I struggle to find more complex examples showing how to put it together to achieve common functionality.
This example code shows
Resourceinterface to list EC2 instancesNametag:stub_responsesto mock API return values within RSpecI hope this will help provide an even easier introduction to AWS Ruby SDK v2.