Created
December 6, 2010 07:52
-
-
Save baldowl/729996 to your computer and use it in GitHub Desktop.
Coercing Cucumber And Webrat To Cooperate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<a href="/users/2" data-method="delete" rel="nofollow">Delete</a> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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" } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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