Skip to content

Instantly share code, notes, and snippets.

@bgswan
Created December 31, 2010 16:06
Show Gist options
  • Save bgswan/761110 to your computer and use it in GitHub Desktop.
Save bgswan/761110 to your computer and use it in GitHub Desktop.
Example of a mock test and the same test with a spy
# Checking an interaction with a mock
it "should notify bidders in a mocky way" do
bidder = mock( :bidder )
bidder.should_receive( :bid_changed ).with( '10.00' )
auctioneer = Auctioneer.new
auctioneer.add_bidder( bidder )
auctioneer.accept_bid( '10.00' )
end
# Checking an interaction with a spy
it "should notify bidders" do
bidder = stub( :bidder ).as_null_object
auctioneer = Auctioneer.new
auctioneer.add_bidder( bidder )
auctioneer.accept_bid( '10.00' )
assert bidder.received_message?( :bid_changed, '10.00' )
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment