The Flexibility of Mocha
Posted by kev Fri, 01 Sep 2006 18:18:00 GMT
Using Flexmock (and my custom method):
def test_process_exit delegate_methods_to_mock!(RailsFCGIHandler, :close_connection) do fcgi = flexmock() fcgi.should_receive(:close_connection) @handler.mock = fcgi @handler.stubs(:when_ready).returns(:exit) @handler.process! end end
It works but it’s none too pretty. Flexmock people, if there’s a better way speak up.
Here’s the equivalent using Mocha:
def test_process_exit @handler.expects(:close_connection) @handler.stubs(:when_ready).returns(:exit) @handler.process! end
I can place expectations directly on my object (even though I didn’t create it as a mock) and it takes care of it for me. That is *so* much clearer and I’ve saved 3 lines that didn’t tell me anything new about my test. I think I’m in love.