3

In my Ruby on Rails application there are 2 Localhost servers running. I am writing test cases for the 1st server and so I have to mock the 2nd server. For this I am using VCR to record the responses I get from the 2nd server and play the recorded cassette while running the tests on the 1st server.

I am stuck at the part where the 1st server makes a request to 2nd server(the session_id in the URL changes each time) and I want the response to be same every time it makes a request.

2 Answers2

2

Using VCR you can match requests on any parameters you wish (method, host, path, etc...) using the match_requests_on cassette option or a fully custom matcher - https://relishapp.com/vcr/vcr/v/3-0-3/docs/request-matching

Thomas Walpole
  • 48,548
  • 5
  • 64
  • 78
1

I made this work via params ignoring. So for you something like this could work:

VCR.use_cassette('name_of_your_cassette', match_requests_on: [:method, VCR.request_matchers.uri_without_params('session_id')]) do
  # here is your http query
end

In my case it was query that was changing so I ignored that in vcr request matcher.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Martin
  • 4,042
  • 2
  • 19
  • 29