Transposing Example tables in Scenario Outlines

333 views
Skip to first unread message

Johnny Law

unread,
Sep 29, 2010, 8:29:02 PM9/29/10
to Cukes
I was wondering if there's an easy way to feed in transposed Examples
tables, mostly so I don't have such long tables running across the
page in my scenario outlines. It certainly seems that this is
possible, but without getting into the source code and making a mess
of things, I'm not seeing how.

In case my question is not clear, I want to do this:

Scenario Outline: Some Scenario with a Lot of Variables
Given... When I fill in "field1" with <field1>
And I fill in "field2" with <field2>
...
And I fill in "fieldN" with <fieldN>
Then I should see <expected_text>
Examples:
| field1 | stuff_case1 | stuff_case2 |
| field2 | stuff_case1 | stuff_case2 |
....
| fieldN | stuff_case1 | stuff_case2 |
| expected_text | stuff_case1 | stuff_case2 |
As N gets large, even 5 or 6, the normal table is unreadable, while
this transposed one is nice on the eyes.

Thank you.
John Lawrence

aslak hellesoy

unread,
Sep 30, 2010, 3:44:19 AM9/30/10
to cu...@googlegroups.com
This is an interesting idea, and I understand your motivation. There are some tricky parts to it though:

1) Formatting/Progress reporting. If the examples go downward, would you expect results to be printed downward too? (From left to right). That would give a kind of Matrix (the movie) effect, which would be kind of cool.

2) How does Cucumber decide whether the Examples table is oriented with keys on top, or to the left? I suppose we could use some heuristics here. Choose the orientation that gives the most matches against Scenario Outline Steps. In the (rare) case that they match equally well, just bail with an exception.

Non of this is impossible, but it is not trivial either. What do others think?

Aslak

Thank you.
John Lawrence

--
You received this message because you are subscribed to the Google Groups "Cukes" group.
To post to this group, send email to cu...@googlegroups.com.
To unsubscribe from this group, send email to cukes+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/cukes?hl=en.


Johnny Law

unread,
Sep 30, 2010, 3:47:06 PM9/30/10
to Cukes
Aslak,

Thank you for your reply. Regarding #1, I figured output could simply
remain the way it is. I mostly use a fairly "quiet" output format
anyhow, just really wanna know when something fails.

Your question #2 was really my question. I was wondering specifically
if there was a way in Gherkin to signify "the following Examples table
should be read as transposed"? It seems the answer is no.

I'm wondering too if I may be using Cucumber in ways it was not
intended, since you and others would probably have wanted to transpose
example tables before if doing what I'm doing. In my case I'm working
on an application that has a routing system that actually looks in the
database to decide which routes.rb files to include (sort of like meta-
programmed routes). Definitely not how I would have done things, but
difficult to change it at this point. As a result I cannot use Rspec
to test controllers, since it apparently looks for routing information
at a fairly low level and chokes on any routes not in ./config/
routes.rb (none of mine are). Cucumber on the other hand seems to
behave like a browser (less JScript) and can therefore do anything our
users can, so the specific case in which I'm needing a transposed
example table is testing to see that the controller behaves as
expected.

That's the long version. For now, I'll just go with the mile-wide
table. Thanks again.

John

On Sep 30, 12:44 am, aslak hellesoy <aslak.helle...@gmail.com> wrote:
> > cukes+un...@googlegroups.com <cukes%2Bunsu...@googlegroups.com>.

aslak hellesoy

unread,
Sep 30, 2010, 4:06:02 PM9/30/10
to cu...@googlegroups.com
On Thu, Sep 30, 2010 at 9:47 PM, Johnny Law <johnnyl...@gmail.com> wrote:
Aslak,

Thank you for your reply.  Regarding #1, I figured output could simply
remain the way it is.

Well, the philosophy of the pretty output is to output features exactly as their source. -And as they are being executed.
So we'd have to print column by column instead of row by row.
 
 I mostly use a fairly "quiet" output format
anyhow, just really wanna know when something fails.

Your question #2 was really my question.  I was wondering specifically
if there was a way in Gherkin to signify "the following Examples table
should be read as transposed"? It seems the answer is no.

I'm wondering too if I may be using Cucumber in ways it was not
intended, since you and others would probably have wanted to transpose
example tables before if doing what I'm doing.  

No, you're really the first person to ask for this feature. Like most features in Cucumber - they are there because one person had the idea first.
 
In my case I'm working
on an application that has a routing system that actually looks in the
database to decide which routes.rb files to include (sort of like meta-
programmed routes).  Definitely not how I would have done things, but
difficult to change it at this point.  As a result I cannot use Rspec
to test controllers, since it apparently looks for routing information
at a fairly low level and chokes on any routes not in ./config/
routes.rb (none of mine are).  Cucumber on the other hand seems to
behave like a browser (less JScript)

If you use Capybara+Selenium you have Javascript too.
 
and can therefore do anything our
users can, so the specific case in which I'm needing a transposed
example table is testing to see that the controller behaves as
expected.

That's the long version.  For now, I'll just go with the mile-wide
table.  Thanks again.


Ok. I'll keep it in mind the next time we rip the guts out of the internals. It might be easier to do after that happens.

Aslak
 
To unsubscribe from this group, send email to cukes+un...@googlegroups.com.

Matt Wynne

unread,
Oct 1, 2010, 7:58:14 AM10/1/10
to cu...@googlegroups.com

On 30 Sep 2010, at 20:47, Johnny Law wrote:

> I'm wondering too if I may be using Cucumber in ways it was not
> intended, since you and others would probably have wanted to transpose
> example tables before if doing what I'm doing.

I don't know if this will help in your case, but can you reduce the number of columns by pushing the details down inside the step definition? Is it possible to abstract the language of your step so that you give a general name to the combination, then look up the values implied by that name in a table you store inside the step definition?

So rather than a bunch of imperative steps that say:

Given... When I fill in "field1" with <field1>
And I fill in "field2" with <field2>
...
And I fill in "fieldN" with <fieldN>
Then I should see <expected_text>

... you can have something more like this:

Given I fill in the fields with an incomplete set of values
Then I should see "your form is incomplete"

Given I fill in the fields with a correct set of values
Then I should see "thanks"

...which would reduce into a much smaller examples table. See what I mean?

cheers,
Matt

http://blog.mattwynne.net
+44(0)7974 430184

Reply all
Reply to author
Forward
0 new messages