With Cucumber, you write stories and user acceptance tests in plain English, something a lot of people seem to like.
Feature: Search
As a user
I want to find information
So I can learn more
Scenario: Find what I'm looking for
Given I am on the Google search page
When I search for "rspec"
Then I should see a link to RSpec-1.2.4: Home
Then you need to write your “step” files, where you add blocks with regular expressions that must match your plain English user stories and user acceptance tests. Inside those blocks you add your actual Ruby code. If you are using Cucumber for testing Rails or Sinatra, then your step definitions will look like this:
Given 'I am on the Google search page' do
visit('http://www.google.com/')
end
When /I search for "(.*)"/ do |query|
fill_in('q', :with => query)
click_button 'Google Search'
selenium.wait_for_page_to_load
end
Then /I should see a link to (.*)/ do |expected_url|
click_link expected_url
end
Now that you have your plain English features files and your step files, you can finally run your tests. As a result, you will get a nice output of the user stories and user acceptance tests in plain English. But just to clarify that: the output is the same plain English stories you wrote at the beginning. The cost for this is to keep in sync two files for mostly the same thing.
In Citrusbyte we have a different workflow. We agree on the user stories with the client, and we put into instructions the user acceptance tests. We do that using Stories, which is a small add on for Contest. It allows you to declare user stories, scenarios and steps using Webrat. The same example, this time with Stories, would look like this:
class SearchStoriesTest < ActionController::IntegrationTest
story "As a user I want to find information so I can learn more" do
scenario "Find what I'm looking for" do
visit "http://www.google.com/"
fill_in "q", :with => "Citrusbyte Stories"
click_button "Google Search"
assert_contain "citrusbyte's stories"
click_link "citrusbyte's stories at master - GitHub"
assert_contain "Stories and User Acceptance Tests"
end
end
end
When you run that with the stories runner, you get this output:
As a user I want to find information so I can learn more
— Find what I'm looking for
Go to “http://www.google.com”
Fill in “q” with “Citrusbyte Stories”
Click “Google Search”
I should see “citrusbyte's stories”
Click “citrusbyte's stories at master - GitHub”
I should see “Stories and User Acceptance Tests”
Now you can redirect that output to a text file and email it to your client, or you can use the stories-pdf runner, send the PDF straight to your client and get a delicious cake in return. Don’t believe me? Check this post.
You will have all your tests in one place, you will be writing Ruby, your clients will be happier than ever and the overhead will be minimal. Grab the gem from github and start impressing your clients today!
{ 13 comments }
