Skip to content

Instantly share code, notes, and snippets.

@ml242
Last active December 31, 2015 12:39
Show Gist options
  • Select an option

  • Save ml242/7987912 to your computer and use it in GitHub Desktop.

Select an option

Save ml242/7987912 to your computer and use it in GitHub Desktop.
Setting up some Cucumber tests
$ rails _3.2.14_ new cuke -T -d postgresql
// no tests -T
Gemfile
group :test do
gem 'cucumber-rails', require: false
gem 'rspec-rails'
gem 'guard-cucumber'
gem 'database-cleaner'
gem 'guard-rspec'
end
$ rails g rspec:install
$ rails g cucumber:install
touch features/user_registration.feature
// this file is written in plain text
e.g.
Feature: User Registration
as a unregistered user
I want to sign up
So that I can have a bank account
Scenario:
Given an unregistered user named "Judy"
When Judy signs up for the site
Then she should have an account
And it should say "Thanks for signing up"
// Cucumber will turn this into a step definition.
// it turns it into strings unless a keyword makes it a block
// create db
// fix database.yml with
This may be unnecessary:
// cucumber:
// <<: *test
// Start the magic by typing
$ bundle exec cucumber
// go to the step definitions folder and create a user_registration.rb file.
// copy in the results for bundle exec cucumber
// replace the "blah" with user_name, arg1 for welcome_message"
Interim:
Given(/^an unregistered user named "(.*?)"$/) do |user_name|
pending # express the regexp above with the code you wish you had
end
When(/^Judy signs up for the site$/) do
pending # express the regexp above with the code you wish you had
end
Then(/^she should have an account$/) do
pending # express the regexp above with the code you wish you had
end
Then(/^it should say "(.*?)"$/) do |welcome_message|
pending # express the regexp above with the code you wish you had
end
// replace pending tests
// create a welcome controller / index
// create a sign up button etc for this test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment