Skip to content

Instantly share code, notes, and snippets.

@elvanja
Created January 6, 2013 21:40
Show Gist options
  • Save elvanja/4470437 to your computer and use it in GitHub Desktop.
Save elvanja/4470437 to your computer and use it in GitHub Desktop.
An example of using VCR to speed up integration testing Amazon API over Vacuum gem
require 'spec_helper_without_rails'
require 'vacuum'
describe "search by keywords golden path" do
let(:credentials) { YAML::load(File.open("config/amazon.yml"))["test"] }
let(:provider) { Vacuum.new.tap { |provider| provider.configure(credentials) } }
let(:search_matcher) {
lambda do |new_request, saved_request|
new_keywords = new_request.uri[/Keywords=(.*)Operation=.*/, 1]
saved_keywords = saved_request.uri[/Keywords=(.*)Operation=.*/, 1]
new_keywords == saved_keywords
end
}
it "returns the desired items" do
service = AmazonService.new(provider)
search = SearchAmazon.new(service)
VCR.use_cassette("search_by_keywords_returns_the_desired_items", match_requests_on: [:method, search_matcher]) do
result = search.with_keywords("Practical Object-Oriented Design in Ruby")
expect(result).to be_a(SearchResult)
expect(result.items.first.title).to eq("Practical Object-Oriented Design in Ruby: An Agile Primer (Addison-Wesley Professional Ruby Series)")
end
end
end
require 'vcr'
VCR.configure do |c|
c.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
c.hook_into :excon # Vacuum uses it
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment