VCR in doctests?

There is exvcr and there are doctests. Can they be married somehow?

I’ve never gotten into VCR testing, but it looks like exvcr has a start_cassette/1 and stop_cassette/0. Doctests use setup blocks same as regular tests. So you could probably do something like

setup do
  start_cassette("my_cassette")
  # will run in a separate process--will that be an issue?
  on_exit(&stop_cassette/0)
end

If you need different cassettes for different doctests, you can wrap doctests for each function in a describe block with its own setup and passing the :only (or :except) option into doctest/2.

1 Like