Mocha with Cucumber

Tagged with mocha cucumber Rails

Language: Apache

For most cases, you shouldn’t need to use mocking and stubbing with Cucumber. However, there are certain cases in which you need to write stories to work around external services (such as OpenID logins or Paypal transactions.) Mocha makes it dirt simple to write around those services, but it’s not included in the Cucumber setup.

Simply create the file mocha.rb in your features/setup folder and paste this coe. You can now use mocks in your steps.

View as text

## features/support/mocha.rb  
 
require "mocha"

World(Mocha::Standalone)
 
Before do
  mocha_setup
end
 
After do
  begin
    mocha_verify
  ensure
    mocha_teardown
  end
end
Original snippet written by Brian Hogan
Last updated at 09:20 AM on May 05, 2009 by Brian Hogan

SnippetStash costs money to host and develop. The service is free for everyone to use
but if you found it useful please consider making a small donation.