This change adds a new option called strict_mode. When turned on, if a matching cassette cannot be found, an error will be thrown.
Problem
In a large codebase (e.g. has hundreds of tests) it is hard to validate if every HTTP call has a cassette defined for it. With strict_mode turned, an HTTP call without a cassette will cause a test to fail, making it easy to identify which calls are missing cassettes.
Some HTTP calls are destructive or mutate data and should never be called while running tests. Strict_mode enables ExVCR to be used for these HTTP calls without the risk of accidentally making an actual HTTP call
Why use throw not raise?
In practice there's a reasonable amount of code out in the wild that will handle any exception raised in order to give a reasonable default error message to an end user/consumer. For example, a controller might do something like:
def controller_handle_request(conn, params) do
make_http_call_that_may_raise()
rescue
_ -> return_nice_error()
end
Unfortunately if this controller is mocked by ExVCR an exception raised by strict_mode would also get handled by this controller :(
throw's sit outside of exceptions, and won't get clobbered by any kind of rescue, thus surfacing strict_mode errors to developers in this scenario.
Coverage increased (+0.1%) to 93.164% when pulling b2cffa847cd6155ec1875ea5bf92c8f1d7068f04 on myxplor:strict-mode into b45c6af4231b087c83977485c1e0e3ae40bcacce on parroty:master.
This change adds a new option called strict_mode. When turned on, if a matching cassette cannot be found, an error will be thrown.
Problem
Why use
throw
notraise
?In practice there's a reasonable amount of code out in the wild that will handle any exception raised in order to give a reasonable default error message to an end user/consumer. For example, a controller might do something like:
Unfortunately if this controller is mocked by ExVCR an exception raised by
strict_mode
would also get handled by this controller :(throw
's sit outside of exceptions, and won't get clobbered by any kind ofrescue
, thus surfacingstrict_mode
errors to developers in this scenario.