Home · Blog · Talks · Projects

Mocha 0.2 released

I’ve just released a new version of the Ruby mocking and stubbing library, Mocha, that I first mentioned a while ago. Here are the release notes:

So instead of…

wotsit = Mocha.new
wotsit.expects(:thingummy).with(5).returns(10)
doobrey = Doobrey.new(wotsit)
doobrey.hoojamaflip
wotsit.verify

you need to do…

wotsit = mock()
wotsit.expects(:thingummy).with(5).returns(10)
doobrey = Doobrey.new(wotsit)
doobrey.hoojamaflip
# no need to verify

There are also shortcuts as follows…

instead of…

wotsit = Mocha.new
wotsit.expects(:thingummy).returns(10)
wotsit.expects(:summat).returns(25)

you can have…

wotsit = mock(:thingummy => 5, :summat => 25)

and instead of…

wotsit = Mocha.new
wotsit.stubs(:thingummy).returns(10)
wotsit.stubs(:summat).returns(25)

you can have…

wotsit = stub(:thingummy => 5, :summat => 25)
Contact · History · Colophon · Links