I am a bit new to mocking. I am trying to stub the ActiveMerchant::Billing::PaypalGateway#authorize method but not clear how to do it. This is my code and spec.
This is the pertinent code: module Payment def gateway ActiveMerchant::Billing::PaypalGateway.new( ... ) end def authorize_payment(payment_info, associated_record_type, associated_record_id) gateway.authorize(payment_info.amount ...... end I tried this: ActiveMerchant::Billing::PaypalGateway.should_receive(:authorize).and_return(authorize_payment_success_response) And it does work on its own, but when I call Payment.gateway.authorize, ActiveMerchant still goes out to the web. I perhaps am missing understanding something -- yes, calling gateway.authorize does create a new ActiveMerchant::Billing::PaypalGateway, but I thought by stubbing the class I should be ok. Or alternatively is there a way I can do something like: Payment.gateway.authorize.should_receive(:authorize).and_return(nil) I am guessing this question does not have to specifically do with ActiveMerchant but how to mock and stub through cascading levels of classes/objects. David
_______________________________________________ rspec-users mailing list rspec-users@rubyforge.org http://rubyforge.org/mailman/listinfo/rspec-users