[rspec-users] Cucumber - Ambiguous steps

Joseph Wilk lists at ruby-forum.com
Mon Sep 15 04:54:17 EDT 2008


>>> 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?

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?

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/.


More information about the rspec-users mailing list