Skip to content

Instantly share code, notes, and snippets.

@myronmarston
Forked from tommeier/some_spec.rb
Created April 16, 2012 15:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save myronmarston/2399294 to your computer and use it in GitHub Desktop.
Save myronmarston/2399294 to your computer and use it in GitHub Desktop.
VCR with placeholders
use_vcr_cassette 'some/cassette', :tag => :bad_staging_api
VCR.configure do |c|
c.cassette_library_dir = Rails.root.join('spec/fixtures/vcr_cassettes')
c.hook_into :webmock
c.default_cassette_options = { :record => :new_episodes }
newly_recorded_bad_staging_api_request = lambda do |req|
VCR.current_cassette &&
VCR.current_cassette.tags.include?(:bad_staging_api) &&
req.recordable?
end
# Needed for the 1st test run when the cassette is recorded, since the test
# assumes the value is 836.00.
c.after_http_request(newly_recorded_bad_staging_api_request) do |req, res|
res.body.gsub!(/TotalRate\=["']([^"']+)["']/, %q{TotalRate="836.00"})
end
c.before_record(:bad_staging_api) do |interaction, cassette|
interaction.response.body.gsub!(/TotalRate\=["']([^"']+)["']/, %q{TotalRate="<TOTAL_RATE>"})
end
# Needed for subsequent test runs...
c.before_playback(:bad_staging_api) do |interaction|
interaction.filter!('<TOTAL_RATE>', "836.00")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment