[rspec-users] Help with regexp in matcher

Ben Mabey ben at benmabey.com
Mon Jan 12 18:00:16 EST 2009


On 1/12/09 2:50 PM, James Byrne wrote:
> This is giving me an error:
>
> When /?:(log|sign)?:(i|o)n success message/ do
>    Then "welcome message"
> end
>    

The ?: needs to be inside your group if you don't want to capture it... so:

When /(?:log|sign)(?:i|o)n success message/ do

FWIW, I have found http://www.rubular.com an excellent resource when creating my steps.

-Ben


> To the effect that:
>
> /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in
> `gem_original_require':
> ./features/components/login/step_definitions/login_steps.rb:21: invalid
> regular expression; there's no previous pattern, to which '?' would
> define cardinality at 1: /?:(am|is) not ?:(logg|sign)ed ?:(i|o)n/
> (SyntaxError)
> ./features/components/login/step_definitions/login_steps.rb:25: invalid
> regular expression; there's no previous pattern, to which '?' would
> define cardinality at 1: /?:(log|sign) ??:(i|o)n request message/
> ./features/components/login/step_definitions/login_steps.rb:41: invalid
> regular expression; there's no previous pattern, to which '?' would
> define cardinality at 1: /?:(log|sign)?:(i|o)n success message/     from
> /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
>
>
> I would appreciate it very much if someone could tell me what i am doing
> wrong here.
>    



More information about the rspec-users mailing list