Skip to content
This repository

Improve "real HTTP connections are not allowed" error messages #92

Closed
myronmarston opened this Issue · 1 comment

1 participant

Myron Marston
Myron Marston
Owner

Currently VCR just uses the same error message every time. However, I think it's often unclear to the end user exactly what they did wrong to get this message. It would be nice to improve this message (and maybe even have logic that is based on the current context). Examples:

  • VCR does not currently have an inserted cassette. You should insert a cassette or use the allow_http_connections_when_no_cassette option.
  • None of the HTTPInteractions in the current cassette match the new request. You might need to use a different :match_requests_on option.
Myron Marston

Here are some examples of what I have in mind...

An HTTP request has been made that VCR is not sure how to handle:
  GET http://foo.com/bar?search=q

Currently there is no cassette in use. There are a few ways
you can configure VCR to handle this request:

  * If you want VCR to record this request and play it back during future test
    runs, you should wrap your test (or this portion of your test) in a
    `VCR.use_cassette` block [1].
  * If you only want VCR to handle requests made while a cassette is in use,
    configure `allow_http_connections_when_no_cassette = true`. VCR will
    ignore this request since it is made when there is no cassette [2].
  * If you want VCR to ignore this request (and others like it), you can
    set an `ignore_request` callback [3].

[1] https://www.relishapp.com/myronmarston/vcr/docs/getting-started
[2] https://www.relishapp.com/myronmarston/vcr/docs/configuration/allow-http-connections-when-no-cassette
[3] https://www.relishapp.com/myronmarston/vcr/docs/configuration/ignore-request
An HTTP request has been made that VCR is not sure how to handle:
  GET http://foo.com/bar?search=q

Currently, VCR is using a cassette located at:
  path/to/cassette.yml

Under the current configuration VCR can not find a suitable HTTP interaction
to replay and is prevented from recording new requests. There are a few ways
you can deal with this:

  * The current record mode (:once) does not allow new requests to be recorded
    to a previously recorded set. You can delete the cassette file and re-run
    your tests to allow the cassette to be recorded with this request.
  * Use the `:new_episodes` record mode to allow VCR to record this new
    request to the existing cassette [1].
  * The cassette contains an HTTP interaction that could be replayed if
    your configured `:match_requests_on` option allowed less exact matches.
    These are the strictest request matchers that would allow a match:
    `[:method, :uri]`. Alternately, you can provide your own custom request
    matcher [2].
  * If you want VCR to ignore this request (and others like it), you can
    set an `ignore_request` callback [3].
  * The cassette contains an HTTP interaction that matches this request,
    but it has already been replayed.  If you wish to allow a single HTTP
    interaction to be replayed multiple times, set the `:allow_playback_repeats`
    cassette option [4].

[1] https://www.relishapp.com/myronmarston/vcr/docs/record-modes/new-episodes
[2] https://www.relishapp.com/myronmarston/vcr/docs/request-matching
[3] https://www.relishapp.com/myronmarston/vcr/docs/configuration/ignore-request
[4] https://www.relishapp.com/myronmarston/vcr/docs/request-matching/playback-repeats
Myron Marston myronmarston referenced this issue from a commit
Myron Marston myronmarston Change the unhandled request error class and message.
I'm going to be expanding this a lot for issue #92 but I wanted to get the basics in place and get the tests in a stable state so that they should continue to pass as I expand the error message.
2dfd533
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.