Slide 6
Slide 6 text
The Problem
describe Customer do
describe “payment” do
it “processes the payment” do
credit_card = mock_model(CreditCard)
result = mock(CreditCardGatewayResult)
result.should_receive(:success?).
and_return(true)
gateway = mock(:gateway)
Gateway.stub(:new => gateway)
gateway.should_receive(:process).twice.
and_return(result)
credit_card.should_receive(:gateway).
exactly(2).times.and_return(result)
Subscription.stub_chain(:new, :add_data,
:make_live, :check).and_return(true)
customer = Customer.new
customer.pay(credit_card)
end
it “fails when the gateway refuses” do
...
end
end
end
1. Look at all this setup
code.
2. What’s going on with
that stub_chain?
3. This kind of thing is
duplicated all over this
file, and the whole
codebase.
4. Mocks cause lots of
trouble. I need to start
this test from scratch.
The Verdict