[rspec-users] Cucumber - Ambiguous steps

aslak hellesoy
Mon, 15 Sep 2008 12:49:35 -0000

On Mon, Sep 15, 2008 at 2:40 PM, David Chelimsky <dchelimsky at gmail.com>
wrote:
> On Mon, Sep 15, 2008 at 3:54 AM, Joseph Wilk <lists at
ruby-forum.com> wrote:
>>>>> Then /I should see "(.*)" in the page/ do |text|
>>>
>>> That should raise an AmbiguousStep error if you also have /I should
>>> see "(.*)"/.
>>
>> Oops sorry, thanks for spotting that David.
>>
>> It seems that it would be good practice to use $ and ^ in all your
>> regular expression steps in order to minimise surprise conflicts.
>>
>> You can still use non-regular expression steps in Cucumber:
>>
>>>Then "I should see ''$value'' in the page"
do |value|
>>
>> This issue does make me think about the regular expressions to step
>> matching.
>>
>> My intuition would be that if a regular expression did not consume all
>> the tokens of a step string then it would not be a match for the step
>> (even though it would be in the regular expression domain). What do
>> people think?
>>

Isn''t that what Cucumber does though?

http://github.com/aslakhellesoy/cucumber/tree/master/lib/cucumber/step_mother.rb#L30
(prepending ^ and appending $ to the regexp that''s generated from the
string)

Aslak

>> I''ve been unable to think of a good example where I would want
only a
>> partial match of a step. Throwing away the unmatched characters. Does
>> anyone have good examples where they would?
>
> I think you''ve got this right and exposed a bug. Wanna report it
to
> lighthouse and/or fix it?
>
> Thanks,
> David
>
>>
>> Joseph Wilk
>> --
>> http://www.joesniff.co.uk
>>
>>
>> David Chelimsky wrote:
>>> On Sun, Sep 14, 2008 at 9:13 AM, Joseph Wilk <lists at
ruby-forum.com>
>>> wrote:
>>>>
>>>>> Then /I should see "(.*)" in the page/ do |text|
>>>
>>> That should raise an AmbiguousStep error if you also have /I should
>>> see "(.*)"/. What I''ve been doing is stuff like
...
>>>
>>>   Then /the list of (.*) should incude "(.*)"/
>>>
>>> ... in order to differentiate. I''ll say that I do allow
this to impose
>>> html element IDs:
>>>
>>>   Then /the list of (.*) should incude "(.*)"/ do
|list_of, text|
>>>     list_id = list_of.downcase.replace(''
'',''-'')
>>>     response.should have_tag("ul##{list_id}") do
>>>       with_tag("li",text)
>>>     end
>>>   end
>>>
>>> But this one step covers a lot of cases for me.
>>>
>>> Thoughts?
>>>
>>> David
>>
>> --
>> Posted via http://www.ruby-forum.com/.
>> _______________________________________________
>> rspec-users mailing list
>> rspec-users at rubyforge.org
>> http://rubyforge.org/mailman/listinfo/rspec-users
>>
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users
>