Cucumber Step Definition Regex Exclude
I need some help with a regular expression in a Cucumber step definition file. Many of my steps are of the type:
Given I am on the search page
开发者_Go百科I use this general pattern for most of my step definitions, and use the default Webrat regex to pick it up that looks like this:
Given /^(?:|I )am on (.+)$/ do |page_name|
visit path_to(page_name)
end
The problem is that I need to handle a page titled 'results' differently, and I do not know how to modify the above regex to exclude lines that say 'Given I am on the results page'.
You can use a negative look ahead to resolve this one:
Given /^(?:|I )am on (?!the results)(.+)$/ do |page_name|
p page_name
end
Given /^I am on the results page$/ do
p 'We matched the results page'
end
精彩评论