-
-
Save caironoleto/1353446 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 :status | |
def initialize(adapter = MyWhateverAdapter.new) | |
@adapter = adapter | |
end | |
def pay! | |
@response = @adapter.pay(self) | |
end | |
def paid? | |
@response.status | |
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(:adapter) { double("An Adapter") } | |
let(:response) { double("My Response") } | |
describe "A successful transaction" do | |
before do | |
adapter.should_receive(:pay).with(order).and_return(response) | |
response.should_receive(:status).and_return(true) | |
end | |
it "should be a paid order" do | |
order = Order.new(MyWhateverAdapter.new) | |
order.pay! | |
order.should be_paid | |
end | |
end | |
describe "An unsuccessful transaction" do | |
before do | |
adapter.should_receive(:pay).with(order).and_return(response) | |
response.should_receive(:status).and_return(false) | |
end | |
it "should not be a paid order" do | |
order = Order.new | |
order.pay! | |
order.should_not be_paid | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment