Created
November 24, 2008 04:19
-
-
Save ianwhite/28376 to your computer and use it in GitHub Desktop.
auto generate scoped versions of your webrat steps
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
# Stick this in features/step_definitions/scoped_webrat_steps.rb | |
# | |
# If your webrat steps defines: | |
# | |
# When /^I press "(.*)"$/ do |link| | |
# clicks_link(link) | |
# end | |
# | |
# Then this will also define: | |
# | |
# When /^within: (.*?), I press "(.*)"$/ |scoped, link| | |
# within(scope) {|s| s.clicks_link(link)} | |
# end | |
# | |
# When means you can do stuff like this: | |
# | |
# Scenario: click the 'home' in the crumbs bar | |
# When within: div#crumbs, I press "home" | |
# ... | |
# | |
__DIR__ = File.expand_path(File.dirname(__FILE__)) # thanks lachie | |
webrat_steps = File.read(File.join(__DIR__, 'webrat_steps.rb')) | |
within_steps = "# generated by parsing webrat_steps.rb\n" | |
webrat_steps.scan(/\nWhen \/\^(.*?)\$\/ do \|(.*?)\|\n\s+(.+?)\s*\nend\n/m) do | |
within_steps << <<-eod | |
When /^within: (.*?), #{$1}$/ do |scope, #{$2}| | |
within(scope) {|s| s.#{$3}} | |
end | |
eod | |
end | |
eval within_steps |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment