Skip to content

Instantly share code, notes, and snippets.

@9z0b3t1c
Created June 16, 2009 15:22
Show Gist options
  • Save 9z0b3t1c/130739 to your computer and use it in GitHub Desktop.
Save 9z0b3t1c/130739 to your computer and use it in GitHub Desktop.
Webrat Cucumber Mechanize steps to test google
require 'webrat'
require 'webrat/mechanize'
include Webrat::Methods
include Webrat::Matchers
Webrat.configure do |config|
config.mode = :mechanize
end
require 'webrat/core/matchers'
class MechanizeWorld < Webrat::MechanizeSession
require 'spec'
include Spec::Matchers
end
World do
MechanizeWorld.new
end
Feature: Google
In order to test a remote site
I surf to google
And take a look
Scenario: Surf to google
When I hit the google homepage
And I execute a query
Then I should see some results
When /^I hit the google homepage$/ do
visit "http://google.com/"
end
When /^I execute a query$/ do
fill_in "q", :with=>"GoGaRuCo"
click_button "Google Search"
end
Then /^I should see some results$/ do
dom.search("h3 a").each_with_index do |link, i|
announce "#{i+1} #{link['href']}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment