Skip to content

Instantly share code, notes, and snippets.

@abeger
Created April 13, 2012 17:09
Show Gist options
  • Save abeger/2378414 to your computer and use it in GitHub Desktop.
Save abeger/2378414 to your computer and use it in GitHub Desktop.
Setting up web testing with Cucumber and Capybara
Feature: Testing a web site with Capybara and Cucumber
Useful resources:
The Cucumber wiki: https://github.com/cucumber/cucumber/wiki
Capybara RDocs: http://rubydoc.info/github/jnicklas/capybara/file/README.md
Rspec RDocs: http://rubydoc.info/github/rspec/rspec/frames
The Cucumber Book: http://pragprog.com/book/hwcuc
Ruby Toolbox for Gem Selection: https://www.ruby-toolbox.com/
Interesting discussion of Cucumber and BDD: http://gfxmonk.net/2011/01/26/how-i-replaced-cucumber.html
Scenario: Set up Cucumber
Given I have Ruby installed
When I type "sudo gem install cucumber"
And I type "sudo gem install rspec"
And I type "cucumber --help"
Then I should see Cucumber help text
Scenario: Set up Capybara
Given I have Ruby installed
And I have Qt installed (http://bit.ly/HvCG2s)
When I type "sudo gem install capybara"
And I type "sudo gem install capybara-webkit"
Then I should be good to go
Scenario: Set up a Cucumber folder structure
Given I have Cucumber installed
And I am in the directory in which I want to store my tests
When I create a directory called "features"
And I create a directory called "features/step_definitions"
And I create a directory called "support"
Then I should be ready to start building my test environment
Scenario: Create the Cucumber/Capybara test environment
Given I have created the Cucumber folder structure
And I have installed Cucumber
And I have installed Capybara
When I create a file called "env.rb" in "features/support"
And I type "require 'capybara/webkit'" in env.rb
And I type "require 'capybara/cucumber'" in env.rb
And I create a file called "hooks.rb" in "features/support"
And I type "Capybara.app_host = 'http://my_site_to_test.com'" in hooks.rb
And I type "Capybara.default_driver = :webkit" in hooks.rb
And I type "Capybara.javascript_driver = :webkit" in hooks.rb
Then I should be ready to start testing
Scenario: Creating Cucumber tests
Given I have created the Cucumber folder structure
And I have installed Cucumber
When I create a file called "myfeature.feature" in "features"
And I write Cucumber tests in "myfeature.feature"
And I create a file called "mysteps_steps.rb" in "features/step_definitions"
And I write Ruby code implementing the steps
Then I should have Cucumber tests that can be executed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment