I’ve just upgraded from Rspec 2.99 to 3.9, and have discovered that
“allow_any_instance_of” is no longer supported. I’m not sure how best to go
about replacing it, as it is in use in most of my tests. I have a User class,
and most tests involve a user. Behind the scenes, many of the user methods call
the Stripe API to adjust subscriptions, view and preview invoices, etc.
Currently, I’ve got the following in “spec_helper.rb”:
config.before(:each) do
allow_any_instance_of(User).to receive(:send_to_stripe).and_return(true)
end
In most cases the calls to the Stripe API go through that method (I used
instance stubs as necessary in tests that use other facets of the Stripe API).
I understand that the preferred approach is to stub an instance rather than a
whole class. But to do this, everywhere I create a user I would have to add
“allow(xxx).to receive(:send_to_stripe).and_return(true). Most (if not all) of
my users are created with calls to FactoryBot.In the interest of DRYing my
tests, is there a way I can leverage that to set a stub on the instance being
created by FactoryBot?
--
You received this message because you are subscribed to the Google Groups
"rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/rspec/A5D160EE-A4CD-4D1F-9158-BD508A139EAB%40pobox.com.