-1

This would be the same functionality as Webmock. Except it would take a cassette instead of a string.

Something like expect(Webmock)to receive...

B Seven
  • 44,484
  • 66
  • 240
  • 385
  • 4
    Why do you want to verify a specific message being sent? If another than the expected message was sent, then VCR would not pick the expected cassette and would therefore respond with a missing cassette or a different response. That means it implicitly verifies the correct outgoing message by design all the time. – spickermann Jun 28 '23 at 06:13
  • That's what I hoped, but when I edited the body of one of the messages the spec still passed. – B Seven Jun 28 '23 at 11:53
  • That depends on how you set up VCR and what you changed in your test. Would you mind sharing? – spickermann Jun 28 '23 at 12:02

1 Answers1

0

There is a config for this: match_requests_on.

Defaults to [:method, :uri]

VCR.configure do |config|
  config.default_cassette_options[:match_requests_on] = [:method, :uri, :body, :headers]
end

There is one more use case. Even if you match method, uri, body and headers, the spec will still pass even if the app does not make the expected requests.

To handle this, I write the url, headers and body as JSON to a file.

Then, in the spec use Webmock to validate it:

      message = JSON.parse(File.read(f), symbolize_names: true)
      expect(WebMock).to have_requested(:post, message[:url])
                     .with(headers: message[:headers], body: message[:body])

Reference: https://nicolasiensen.gitbook.io/vcr/configuration/default_cassette_options#match_requests_on-defaults-to-method-uri-when-it-has-not-been-set

https://nicolasiensen.gitbook.io/vcr/request-matching/body

B Seven
  • 44,484
  • 66
  • 240
  • 385