[rspec-users] Cucumber, more examples, tabular data input sets
Ben Mabey
ben at benmabey.com
Sat Oct 18 14:22:56 EDT 2008
Zach Dennis wrote:
> Writing feature inputs in the tabular format has recently been very
> helpful. However, there are some things that seem kind of funny when
> writing. For example, let's say we wanted to ensure that certain
> requests resulted in the access denied page:
>
> Given Joe is a staff member without the 'admin' privilege
> When I GET /admin as Joe
> Then I am notified that access was denied
>
> The possible variables here based on step implementations are:
>
> Given XXXX is a staff member without the 'XXXX' privilege
> When I XXX XXXX as XXXX
> Then I am notified that access was denied
>
> This requires the More Examples to look like:
>
> | name | privilege | request_method | path | name |
> | Joe | admin | POST | /invoices | Joe |
> | Joe | admin | PUT | /invoices/1 | Joe |
> etc...
>
> This isn't that bad, but it'd be nice if we could specify only the
> variable inputs that we care about -- the privilege, the request
> method and the path. As the scenario involves more steps you have to
> grow your tabular data, unless I am missing how to do something (which
> could be the case).
>
> It also seems somewhat odd that the first example is the scenario
> itself. It almost seems like the scenario should define the
> placeholders and the More Examples section should define all the input
> data sets. For example:
>
> Given Joe is a staff member without the '$privilege$' privilege
> When I $request$ $path$ as Joe
> Then I am notified that access was denied
>
> Examples:
> | privilege | request_method | path |
> | admin | GET | /admin |
> | admin | POST | /invoices |
> | admin | PUT | /invoices/1 |
>
> It would somewhat rely on using the \$\w+\$ pattern to denote what
> should be replaced by the Examples input data set. I'm not tied to how
> the inputs are grabbed, but it seems like moving in this direction
> allows the tabular inputs to be more streamlined to what you wanted to
> include in a scenario.
>
> WDYT?
>
>
Why is name even being used? Since you are talking in first person in
the other steps couldn't you remove the name altogether:
Given I'm a staff member without the 'admin' privilege
When I GET /admin
Then I am notified that access was denied
As far as your suggestion about using placeholders instead of a real example set- I like it. This was actually brought up a little while ago by Evan Light on this list so I think it is something that people naturally move towards. I think this way would be clearer to non-developers as well since the column names would appear in the actual scenario.
-Ben
More information about the rspec-users
mailing list