[rspec-users] Trouble stubbing a method
mailing_lists at railsnewbie.com
Tue Nov 13 15:36:38 EST 2007
On Nov 13, 2007, at 3:23 PM, Matthew Lins wrote:
> Hey guys,
> I'll try to explain this without the model code at first, since
> there is so
> much, but if need be, I'll pastie it.
> I have an Order model that makes API calls to a payment
> gateway(TrustCommerce) during validation(to verify the credit card
> information). I'd like to stub this behavior to avoid thousands of
> calls to
> TrustCommerce a day(autotest).
> All the calls are made in one method: Order#payment_authorize. This is
> called from ActiveRecord#validate.
> So, my thinking was just to stub out Order#payment_authorize. So
> here is one
> of my specs:
> describe Order, "placed via the web" do
> include OrderSpecHelper
> before(:each) do
> @order = generate_valid_web_order
You probably want @order.stub!(:payment_authorize) - should_receive
is an assertion. It doesn't belong in a before(:each)/setup block.
If you want to test that the payment_authorize is called, you'll want
to pull the assertion that you gave below into your spec:
describe Order, "placed via the web" do
@order = generate_valid_web_order
it "should try to authorize the payment when validating the
More information about the rspec-users