Forum: RSpec regex help

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Jonathan L. (Guest)
on 2008-12-29 07:02
(Received via mailing list)
Hi,
Could someone help me resolve this conflict:


     Then the selected item should have a <label> tag with "Foo:"

  Multiple step definitions match "the selected item should have a
<label> tag with \"Foo:\"": (Cucumber::Multiple)

features/step_definitions/page_builder_steps.rb:355:in `/^the
(selected|first|second|last) item should have a \<(.*)\> tag with
"(.*)"/'

features/step_definitions/browser_steps.rb:117:in `/^the (.*) should
have a \<(.*)\> tag with "(.*)"/'


Perhaps tell it to ignore any matches with " item" in it, but dont
know how

linoj
Emmanuel P. (Guest)
on 2008-12-29 07:36
(Received via mailing list)
Are the steps doing anything different?  I mean it seems like selected|
first|second are part of  .* so you can put that specific logic in the
step I would thing and have one step to handle them all

Or then  just change slightly your sentence  so they don t overlap

Emmanuel
Stephen E. (Guest)
on 2008-12-29 08:09
(Received via mailing list)
On Sun, Dec 28, 2008 at 11:59 PM, Jonathan L.
<removed_email_address@domain.invalid> wrote:
>
> Perhaps tell it to ignore any matches with " item" in it, but dont know how

It's called a zero-width negative lookahead, and it looks like this:
/^the (?!\w+ item)(.*) should have a \<(.*)\> tag with "(.*)"/

I didn't test this to be sure, but I believe it should work.  But
rephrasing your steps so that one isn't a special case of the other
would probably be better.  Or just having one step that contains the
logic from both.


--
Have Fun,
   Steve E. (removed_email_address@domain.invalid)
   ESCAPE POD - The Science Fiction Podcast Magazine
   http://www.escapepod.org
Jonathan L. (Guest)
on 2008-12-29 19:55
(Received via mailing list)
Thanks that worked.

Normally I would combine them into one step, but this case, one is in
a general reusable steps file, and the other is specific to a
feature. I thought the word "item" would be sufficient to distinguish
the two.
This topic is locked and can not be replied to.