[rspec-users] Cucumber Tables

aslak hellesoy aslak.hellesoy at gmail.com
Wed May 13 11:05:07 EDT 2009

> I am running into this situation:
> Feature 1
>  Scenario A
>    ...
>    Then we should have currency exchange rates for "USD" on file
>      And we should ...
> Feature 2
>  Scenario D
>    ...
>    Then we should have currency exchange rates for "USD" on file
>        | code|
>        |"EUR"|
>        |"JPY"|
>        |"KRW"|
>        |"MXN"|
>      And we should not ...
> This arrangement presently gives a cucumber error because the step
> definition that matches will either have one argument too many or one
> too few.  However, from a user point of view it strikes me that this
> situation should not be an error at all.
> My reasoning is this.  The features statement as given is completely
> logical, straight-forward and applicable in either situation.

A common way to express step definitions that take multiline arguments
is to explicitly refer to the multiline argument in the step text. For

Then I should have the following shoes:
  |43  |Adidas Oslo|
  |41  |Nike Racer|

If you don't do this, the multiline argument is "dangling". Steps that
take multiline arguments should be formulated in such a way that
removing the multiline argument makes the sentence nonsensical. This
is not the case for your example. Remove the table and the sentence
still makes sense. That's very confusing. In fact, sticking a table
onto that sentence makes no sense at all to me. I have to guess how
that table is related to the sentence above it. Be explicit, and
you'll save yourself a lot of headache.

In your case I would do this:

Then we should have currency exchange rates for "USD" on file

Then we should have currency exchange rates for "USD" on file with the
following codes:
       | code|


> Having a
> requirement to create separate invocations for exactly the same test,
> depending only upon whether one wishes to do it once or several times,
> strikes me as bending the situation to the limitations of the
> implementation rather than elaborating the implementation to handle the
> situation.
> On the other hand, as this may be quite involved to solve I am not
> saying what I suggest MUST be the behavior, only that it seems to me
> that it should be.
> I seem to recall that when I first used cucumber in December last, that
> one could either provide additional examples to a matcher in a scenario
> or not.  In either case the matcher would work.  I think that this
> behaviour, if at all possible, might be more natural than requiring two
> separate matchers that exist only to match to different patterns.
> What do you all think?
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> rspec-users mailing list
> rspec-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/rspec-users

More information about the rspec-users mailing list