Created
November 9, 2011 19:20
-
-
Save fellix/1352606 to your computer and use it in GitHub Desktop.
order
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Order | |
attr_accessor :id, :client, :products, :total, :status | |
def pay!(adapter) | |
response = adapter.pay(self) | |
status = response | |
end | |
def paid? | |
status == :paid | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
describe Order do | |
context "A valid order" do | |
let(:order){ Order.new(...) } | |
let(:adapter){ double("An Adapter") } | |
describe "A successfull transaction" do | |
before do | |
adapter.should_receive(:pay).and_return(:paid) | |
end | |
it "should be a paid order" do | |
order.pay!(adapter) | |
order.paid?.should be_true | |
end | |
end | |
describe "An unsuccessfull transaction" do | |
before do | |
adapter.should_receive(:pay).and_return(:rejected) | |
end | |
it "should not be a paid order" do | |
order.paid?.should be_false | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment