8

I have a step definition, below, that does what I want it to do i.e. it checks the url of the page against the 'page' element of 'PAGES' hash.

Then(/^I should( still)? be at the "(.*)" page$/) do |still, page|
  BROWSER.url.should == PAGES[page]
end

The step definition is used for both

  • I should be at the ... page
  • I should still be at the ... page

However, I don't need "still" to be passed into the block. I just need it to be optional for matching to the step but not passed into the block. How can I do that?

Thanks.

Karl Cummins
  • 93
  • 1
  • 1
  • 8

1 Answers1

14

You want to mark the "still" group as non-capturing. This is done by starting the group with ?:.

Then(/^I should(?: still)? be at the "(.*)" page$/) do |page|
  BROWSER.url.should == PAGES[page]
end
Justin Ko
  • 46,526
  • 5
  • 91
  • 101
  • What if I need the "still" to be passed into the block (if it's there), how would I do that? – Richard Nov 11 '19 at 13:39
  • 1
    @Richard, you would not specify the non-capturing flag, basically it would be back to what was in the original question. – Justin Ko Nov 11 '19 at 13:55