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






Now read this

The Pragmatic Programmer notes

The cat ate my source code. It’s your responsibility to come up with solutions, not excuses. Sure there’s many things to be taken into account but regardless, JFDI. Broken window theory. Momentum of bad code fucks shit up. Be on top of... Continue →