test/integration_helper.rb in peddler-0.6.5 vs test/integration_helper.rb in peddler-0.7.0

- old
+ new

@@ -1,19 +1,52 @@ require 'yaml' +require 'vcr' + require 'helper' +VCR.configure do |c| + c.hook_into :excon + c.cassette_library_dir = 'test/vcr_cassettes' + + c.before_record do |interaction| + interaction.ignore! if interaction.response.status.code >= 400 + end + + nondeterministic_params = %w( + AWSAccessKeyId SellerId Signature Timestamp StartDate CreatedAfter + Destination.AttributeList.member.1.Value + ) + matcher = VCR.request_matchers.uri_without_param(*nondeterministic_params) + c.default_cassette_options = { + match_requests_on: [:method, matcher], + record: :new_episodes + } +end + class IntegrationTest < MiniTest::Test - class << self - attr_accessor :api + def api_name + self.class.name.match(/(.*)Test/)[1] end - def accounts - skip if ENV['SKIP_INTEGRATION'] - YAML.load_file(File.expand_path('../fixtures/mws.yml', __FILE__)) - rescue Errno::ENOENT - skip('Credentials missing') + def clients + accounts = begin + YAML.load_file(File.expand_path('../mws.yml', __FILE__)).shuffle + rescue Errno::ENOENT + warn('Skipping integration tests') + [] + end + + accounts.map do |account| + MWS.const_get(api_name).new.configure do |c| + account.each { |k, v| c.send("#{k}=", v) } + end + end end def setup - @clients = accounts.map { |mws| self.class.api.const_get(:Client).new(*mws.values) } + VCR.insert_cassette(api_name) + end + + def teardown + VCR.eject_cassette end end