The tutorial will show you how to install what is required to run cucumber then work through a simple demonstration. The tutorial will create a test that checks a page exists and contains some text.
How to install: RSPEC
mkdir -p ~/Library/Application\ Support/TextMate/Bundles/
cd ~/Library/Application\ Support/TextMate/Bundles
git clone git://github.com/bmabey/rspec-story-tmbundle.git RSpec\ Story.tmbundle
How to install: WEBRAT
mkdir -p ~/Library/Application\ Support/TextMate/Bundles/
cd ~/Library/Application\ Support/TextMate/Bundles
git clone git://github.com/bmabey/webrat-tmbundle.git Webrat.tmbundle
How to install: Cucumber
mkdir -p ~/Library/Application\ Support/TextMate/Bundles/
cd ~/Library/Application\ Support/TextMate/Bundles
git clone git://github.com/bmabey/cucumber-tmbundle.git Cucumber.tmbundle
Sudo gem install rspec-rails cucumber webrat
Create a new rails application
CD sites
Rails Hey
CD Hey
Ruby Script/Generate cucumber
mate .
Menu Bundles / Bundle Editor / Reload Bundles
Open the Bundle Editor / Filter Button / Uncheck RSPEC
Create a new file
/features/Homepage.feature
Open the file, press ctrl Apple T - Type Feature
Select Feature - cucumber
Also do this with Scenario - cucumber
Output to the file is:
Feature: title
In order to value
As a role
I want feature
Scenario: title
Given context
When event
Then outcome
Change this to:
Feature: view homepage
In order to love the website
As a viewer
I want to see a beautiful page
Scenario: visit homepage
Given Im on the "homepage"
Then I should see "Beauty"
note-- we have used the words "I should see" as it is a method that exists in the webrat_steps.rb file. There are many commonly used webrat steps within this file. using these saves us a lot of time:
Then /^I should see "(.*)"$/ do |text|
response.body.should =~ /#{text}/m
end
As Beauty is in quotes it is passed as the parameter
Apple R will run it and show that the first step is pending

Run:
script/cucumber features
This will return:

You can use these snippets to implement pending steps which have no step definition:
Given /^Im on the "homepage"$/ do
end
This tells us what to put in our step file:
So create our step definition:
/features/Step_definitions/site_steps.rb
Given /^Im on the "homepage"$/ do
visit "/sites"
end
Go back to the features file and apple R
Now the test fails as no page exists

Now that we have a test that fails we need to create the homepage file so that the test can pass
in terminal:
script/generate controller sites index
outputs:
mac1:hey Tyler6699$ script/generate controller sites index
exists app/controllers/
exists app/helpers/
create app/views/sites
exists test/functional/
create app/controllers/sites_controller.rb
create test/functional/sites_controller_test.rb
create app/helpers/sites_helper.rb
create app/views/sites/index.html.erb
mac1:hey Tyler6699$
Go to the feature file and press Apple R:
The page should now be found:

Edit file:
/app/views/sites/index.html.erb
add this line of code:
<p>Beauty</p>
Apple R from Feature File:
The test now passes as the word has been found.

Run this from terminal:
script/cucumber features
outputs:
j270-mac1:hey Tyler6699$ script/cucumber features
Feature: view homepage # features/Homepage.feature
In order to love the website
As a viewer
I want to see a beautiful page
Scenario: visit homepage # features/Homepage.feature:6
Given Im on the "homepage" # features/step_definitions/site_steps.rb:1
Then I should see "Beauty" # features/step_definitions/webrat_steps.rb:89
1 scenario
2 steps passed
Read through the webrat rb file "webrat_steps.rb" for all of the pre defined methods such as:
When /^I press "(.*)"$/ do |button|
click_button(button)
end
When /^I follow "(.*)"$/ do |link|
click_link(link)
end
When /^I fill in "(.*)" with "(.*)"$/ do |field, value|
fill_in(field, :with => value)
end
This will allow you to build more complex tests.