I'm trying to write some unit tests for a class of mine that uses
ActiveMerchant (AM) to talk to Authorize.net (A.net). For the tests
though, I don't want AM to actually talk to A.net. Partly because it
slows the tests way, way down, partly because it creates a ton of bogus
data that clutters up our test account at A.net, and partly because the
purpose of the test is to just test *my* class, not AM.
This seemed to me like the perfect time to learn about and use Mock/Stub
objects for testing. However, I'm having serious issues getting
anything to work. When I stub out any of my other classes, things work
exactly like all the documentation I've read indicates, so I know I'm
doing something right. However, all the documentation talks about
stubbing out classes, but for AM, I think what I need to stub out is
ActiveMerchant::Billing::Base, which is a module, not a class. My test
just seems to ignore everything I do and uses the real
ActiveMerchant::Billing::Base in vendor/plugins, not my stubs.
I cannot possibly be the first person to try to stub out parts of AM so
that unit tests aren't constantly trying to talk to the gateway.
Anybody got a hint for me? Thanks!