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

Cucumber BDD notes

Feature to be added -> Optional Text: -As a -I want to -So that Feature:Brush teeth As a human being, I want to brush my teeth So that they stay pain free Scenario: Expected outcome title Steps within scenario Given: Sets up initial... Continue →