How can I wrap a factory in a block?

Viewed 126

I have a factory bot for my model, which has a before save callback that triggers a webservice call for which I am using VCR to mock in my specs. I don't want to wrap the create call because the factory is used in many many places so it's easier for me to do it in the factory itself.

In summary, what I want is to instead of having to do this:

VCR.use_cassette('my_casset', record: :new_episodes) do
  create(:my_model)
end

Just wrap the code in the factory itself.

Thank you!

0 Answers
Related