parroty / exvcr

HTTP request/response recording library for elixir, inspired by VCR.
MIT License
720 stars 131 forks source link

Add strict_mode option to ensure HTTP calls DO NOT get made #152

Closed LexMalta closed 4 years ago

LexMalta commented 4 years ago

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 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.

coveralls commented 4 years ago

Coverage Status

Coverage increased (+0.1%) to 93.164% when pulling b2cffa847cd6155ec1875ea5bf92c8f1d7068f04 on myxplor:strict-mode into b45c6af4231b087c83977485c1e0e3ae40bcacce on parroty:master.

parroty commented 4 years ago

Thanks!