[rspec-users] Help with regexp in matcher
sfeley at gmail.com
Mon Jan 12 18:00:33 EST 2009
On Mon, Jan 12, 2009 at 4:50 PM, James Byrne <lists at ruby-forum.com> wrote:
> When /?:(log|sign)?:(i|o)n success message/ do
> Then "welcome message"
It's a syntax error on that first question mark, the one right after
the slash. A ? in a regex signifies that whatever came just before it
may appear 0 or 1 times. Just like a + signifies that whatever came
before it _must_ appear 1 or more times, and a * signifies that
whatever came before it can appear any number of times. There are a
few other things a ? can mean (non-greedy matching, etc.) but they all
come *after* something. Not at the beginning of your expression.
That's the bug. Beyond that, what you're trying to do with the regex
itself seems just a little too clever; do your features or your app
messages really vary randomly between the terms "login," "logon,"
"signin" and "signon," all meaning the same thing? If so, jumping
hoops to account for it in the tests might be a hint to change your
app language just for clarity. But if you have to have them all, just
writing /(login|logon|signin|signon) success message/ would be a lot
easier to read and understand.
(Final nit, because I'm a smellfungus: what is this step supposed to
do, anyway? Do you really have scenarios that include the line "When
login success message?" 'When' steps imply action taken by the
imaginary user. What's the action here? What's the verb?)
Steve Eley (sfeley at gmail.com)
ESCAPE POD - The Science Fiction Podcast Magazine
More information about the rspec-users