Categories
Cucumber Rails

Rails: Cucumber testing

The actual tests go under the “features” folders. You save it as:

features/some_feature.feature

Here’s a sample feature file:

Feature: Creating projects
In order to have projects to assign tickets to
As a user
I want to create them easily

Background:
  Given I am on the homepage
  When I follow "New Project"
Scenario: Creating a project
  And I fill in "Name" with "TextMate 2"
  And I press "Create Project"
  Then I should see "Project has been created."
  And I should be on the project page for "TextMate 2"
  And I should see "TextMate 2 - Projects - Ticketee"

Scenario: Creating a project without a name
  And I press "Create Project"
  Then I should see "Project has not been created."
  And I should see "Name can't be blank"

This is a sample of how you can add steps to expand the test above:

when /the project page for "([^"]*)"/
  project_path(Project.find_by_name!($1))

To run the tests:

$ rake cucumber:ok

If you want to run just one test (you should have run bundle install –binstubs in order to be able to do this:

bin/cucumber features/viewing_projects.feature

Or
rake cucumber FEATURE=features/your_feature.feature