-
-
Save myronmarston/2399294 to your computer and use it in GitHub Desktop.
VCR with placeholders
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
use_vcr_cassette 'some/cassette', :tag => :bad_staging_api |
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
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