views:

51

answers:

1

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' Can someone help me modify my above regex to

A: 

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
matth
thanks, I ended up not using the regular expression, and instead writing individual regexes for each case, but I just tried this and it definitely works.