Skip to content

Instantly share code, notes, and snippets.

@baldowl
Created December 6, 2010 07:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save baldowl/729996 to your computer and use it in GitHub Desktop.
Save baldowl/729996 to your computer and use it in GitHub Desktop.
Coercing Cucumber And Webrat To Cooperate
Scenario: Deleting a user
When I go to the users page
And follow "Delete" for the 2nd user
Then I should be on the users page
And should not see "user2"
<a href="/users/2" data-method="delete" rel="nofollow">Delete</a>
# Necessary evil thing: Rack::Test sports as default host
# "example.org", but Webrat and Ruby on Rails's integration test
# classes use "example.com"; this discrepancy leads to Webrat not
# being able to follow simple internal redirects.
#
# Drop in in features/support/
module Rack
module Test
DEFAULT_HOST = "example.com"
end
end
# Necessary evil thing: Rack::Test sports as default host
# "example.org", but Webrat and Ruby on Rails's integration test
# classes use "example.com"; this discrepancy leads to Webrat not
# being able to follow simple internal redirects.
#
# Drop in in features/support/
Kernel::silence_warnings { Rack::Test::DEFAULT_HOST = "example.com" }
# Webrat relies on the onclick attribute to "fake" HTTP request's
# method, so it cannot cope with the new Ruby on Rails 3's style
# which uses unobtrusive JavaScript and HTML5 data attributes.
When /^(?:|I )follow "([^\"]*)" for #{capture_model}$/ do |arg1, arg2|
id = "#user_#{model(arg2).id}"
case arg1
when 'Delete'
within id do
click_link arg1, :method => :delete
end
else
click_link_within id, arg1
end
end
# Cucumber 0.9.4 + Webrat 0.7.2: the generated env.rb still uses the
# :rails mode, but it's the wrong mode to use with Ruby on Rails 3.
# Here we reconfigure Webrat and include some missing modules in
# Cucumber's World.
#
# Drop it in features/support/
Webrat.configure do |config|
config.mode = :rack
config.open_error_files = false
end
World Rack::Test::Methods
World Webrat::Methods
World Webrat::Matchers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment