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
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.