For testing your application, you specify features consisting of scenarios. Each scenario is defined by a set of steps and validations. Here’s a short example:
Feature Contact Form In order to tell us something users want to contact us online without having to leave their browser Scenario: Submitting with valid infos Given I am on the contact page When I fill in "Your Name" with "Matthias Marschall" And I fill in "Your Message" with "What's up?" And I press "Send" Then I should see "Thanks for your feedback!"
Usually, one would need to implement fixtures to bind steps to the application code. But cucumber comes with a very useful set of pre-defined steps for webrat, in fact, all of the above steps are already there. You should be able to successfully execute the above example out of the box (given your app already has the contact page up and running).
Full Cycle E-Mail Testing with rails and cucumber
Filling out the contact form should send an email to a feedback account with the information provided. There exists a very handy plugin for dealing with email verification in a rails test environment: rspec-email
After installing it, you can add steps like these to the scenario shown above:
And "[email protected]" should receive 1 email When "[email protected]" opens the email with subject "Feedback" Then I should see "What's up" in the email When I click the first link in the email Then ...
Again, all of the above steps are provided by the plugin (after calling script/generate….).
Without writing a single line of fixture code, I was already able to do a full integration test including form validations and email sending. Not too bad for 2 hrs worth of research. My next steps will be to try out the selenium integration and play around with setting up data in the database for driving my tests. Stay tuned by subscribing to our RSS feed.