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:
- Small change to
SetupAndTeardown#teardown_stubs
suggested by Luke Redpath to allow use of Stubba with RSpec. - Reorganized directory structure and extracted addition of setup and teardown methods into SmartTestCase mini-library.
- Addition of auto-verify for Mocha (but not Stubba). This means there is more significance in the choice of expects or stubs in that any expects on a mock will automatically get verified.
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)