Skip to content

Instantly share code, notes, and snippets.

@reagent
Created March 1, 2010 16:14
Show Gist options
  • Save reagent/318494 to your computer and use it in GitHub Desktop.
Save reagent/318494 to your computer and use it in GitHub Desktop.
Simple Cuke stuff
require 'rubygems'
require 'cucumber'
require 'capybara'
require 'capybara/cucumber'
require 'capybara/session'
Before do
Capybara.current_driver = :selenium
Capybara.app_host = 'http://yahoo.com'
end
Feature: Searching Yahoo
Scenario: Searching for a single term
Given I am on the home page
When I search for "Ruby"
Then I should see the following results:
| Title |
| Ruby - Wikipedia, the free encyclopedia |
| Ruby (programming language) - Wikipedia, the free encyclopedia |
| Ruby Programming Language |
| About Ruby |
| Ruby's Diner - rubys.com |
| Ruby on Rails |
| Ruby - english |
| Fresh Taste. Fresh Place. Enjoy the New Ruby Tuesday. |
| Ruby Annotation |
| Ruby Falls |
Scenario: Following the first link
Given I searched for "Ruby"
When I follow "Ruby - Wikipedia, the free encyclopedia"
Then I should be on "http://en.wikipedia.org/wiki/Ruby"
Given /^I am on the home page$/ do
visit "/"
end
Given /^I searched for "([^\"]*)"$/ do |search_term|
Given %{I am on the home page}
When %{I search for "#{search_term}"}
end
When /^I search for "([^\"]*)"$/ do |search_term|
fill_in 'p', :with => search_term
click_button 'Web Search'
end
When /^I follow "([^\"]*)"$/ do |link_text|
click_link link_text
end
Then /^I should see the following results:$/ do |table|
titles = table.hashes.map {|h| h['Title'] }
results = all("//h3/a[contains(@class, 'yschttl')]").map {|l| l.text }
results.should == titles
end
Then /^I should be on "([^\"]*)"$/ do |url|
current_url.should == url
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment