Reputation: 20560
I am trying to setup specs for my Checkout::Sale
class that employs ActiveMerchant
using credentials for a test Authorize.NET account that I set up the other day.
My plan was to use VCR to record the response for the gateway and run my specs against that, so I'm not hitting the gateway all the time when I run my specs.
Here's is my spec and my class that I'm testing.
My issue is, this code works perfectly if I'm am in the Rails console (development environment), but fails every time I run my specs (test environment). Specifically, the Authorize.NET API complains that my credentials are invalid...
(TESTMODE) The merchant login ID or password is invalid or the account is inactive.
... even though I use the exact same credentials in development and they work fine.
I have no ActiveMerchant
-related logic in either config/environments/development.rb
and config/environments/test.rb
.
I don't understand how the exact same code is working for me in development and not in test mode. Anyone know what's up with this?
I'm using activemerchant 1.20.2
, rspec 2.8.0
and rails 3.1.1
.
NOTE: This fails regardless if I'm using VCR or not; removing VCR seems to have no effect.
Upvotes: 1
Views: 678
Reputation: 20560
Aph, just figured it out.
Just passing test: true
only makes the transaction a test transaction, even though the gateway is still hitting the :production
gateway.
As this test runs without Rails loaded, I wasn't loading in my environment files, where I had specified for both dev and test:
ActiveMerchant::Billing::Base.mode = :test
Since loading the rails console does load Rails, that's why it was working in development but not in my tests. Throwing the above into a before
block solved my problem.
Upvotes: 1