Most of the Cucumber tests that I’ve written don’t need stubbing. But the other day I was trying to test a particular feature which integrated with an external service.
Then, stubbing a call to the external service seemed like the best way to go. Fortunately, since Cucumber 0.8.4, mocking and stubbing is now possible without hacks. See: Mocking and Stubbing with Cucumber.
Here is the gist.
Add this line to your env.rb
1 | require 'spec/stubs/cucumber' |
Start stubbing methods in your steps.rb files
For example:
1 2 | ExternalService.should_receive(:send).and_return(my_response) User.should_receive(:customer_add_success?).and_return(true) |
Next thing I’d like to do is use stubbing to test features in the future. For example: Test a feature involving recurring events around daylight time savings time.
