[rspec-devel] Thoughts after my initial experience with Cucumber Scenario Tables

David Chelimsky dchelimsky at gmail.com
Wed Nov 12 16:41:28 EST 2008


On Wed, Nov 12, 2008 at 3:37 PM, Josh Knowles <joshknowles at gmail.com> wrote:
> On Wed, Nov 12, 2008 at 10:53 AM, aslak hellesoy
> <aslak.hellesoy at gmail.com> wrote:
>> So what's next? A couple of things. I will focus on improving the
>> internal structure of features to make it easier to manipulate the
>> contents of features programmatically.
>> I'm planning to introduce a better AST. For users of Cucumber this
>> will not be noticeable, except that support for tables will be much
>> better. One thing I have in mind is
>> to be able to push actual values back into a table and open up for
>> custom interpretation of tables. I also want to make it possible to
>> customise how table "results" are
>> displayed (for example comparing actual and expected values inside
>> individual cells).
>
> I used the table feature for the first time this week, and while I'm
> quite happy with the end result I wanted to share some of the
> frustrations that I found as it seems like this feature is going to
> get some love in the near future.
>
> My pair and I were working on a story which included redirecting a
> user if they accessed a restricted URL.  My first pass at the scenario
> was written as follows:
>
>  Scenario: Accessing a group as a non-member
>      Given a group named Tigers
>      And I am not a member of the Tigers
>      When I access the media gallery
>      Then I should be redirected to the Tigers public page
>
> After getting this scenario to pass we decided that it made sense to
> use a Scenario Table to add the rest of the restricted URLs.  My first
> attempt at this is as follows:
>
>    Scenario: Accessing a group as a non-member
>      Given a group named Tigers
>      And I am not a member of the Tigers
>      When I access the media gallery
>      Then I should be redirected to the Tigers public page
>
>    More Examples:
>      | path                |
>      | the news page |
>      | the roster        |
>
> Unfortunately I didn't read the documentation closely enough, and what
> I learned is that Cucumber will use the table values to replace
> variables in the order that they are found, which makes sense, but
> this causes problems when you have steps above the places holders
> which you aren't intending be filled in via examples in the table,
> such as Given /a group named (\w+)/.
>
> I ended up re-writing my scenario to use the other style of table,
> which I've included below, but by doing so I had to create a
> state-variable to hold all of the path's which I then iterated over in
> the "Then".
>
>  Scenario: Accessing a group as a non-member
>
>    Given a group named Tigers
>    And I am not a member of the Tigers
>    When I access the following paths:
>      | path                    |
>      | the tigers' profile     |
>      | the tigers news page    |
>      | the tigers gallery page |
>      | the tigers' schedule    |
>      | the tigers' roster page |
>    Then I should be redirected to the Tigers' public page
>
>
> After digging into the code a bit I don't really have any suggestions
> on what could be done differently, but I wanted to start a
> conversation around this feature before going off and trying to solve
> it.

There's a thread you might want to participate in:
http://rspec.lighthouseapp.com/projects/16211/tickets/57

Cheers,
David

>
> --
> Josh Knowles
> phone: 509-979-1593
> email:  joshknowles at gmail.com
> web:    http://joshknowles.com


More information about the rspec-devel mailing list