Test Driven Development in Ruby tuts+ course - Stubs and Mocks notes

Stubbing - A technique used in TDD/BDD allowing you to simulate using third party dependencies for your own code. #



Example, retrieving data from a database, you pass a “splat” = dummy data to a stub.
We have no control over what our data model is; as an example for the usage of stubbing.


pass a stub to a list for fake data

before { competition.stub(:questions => [stub] ) }


Mocking - A technique used to allow you to assert messages; specifically method calls without actually implementing any code for that method. #



Example, a competition class should be able to receive and react to a competition.close method once it has started. However we may assume that the close method logic is not going to be written or implemented by us truly. In real life situations, simulate API calls and pretend that we have data received from such a third party method call.

context:“when started” do

it “is closed” do

competition.should_receive(:close)

competition.start

end

end

 
0
Kudos
 
0
Kudos

Now read this

Notes from The Developer’s Code book

Start from the most interesting task first. We’re allowed to do that as developers, a more realistic timeline can be established once we have practical experience in doing. Only then will we know how much time is accurately required to... Continue →