[cucumber] How to DRY up table data that I'm seeing across tests?


#1

I have the following step that I want to re-use in several scenarios.
It
looks like this:

When I submit the form
|form_field_id |value|
|billingAddress.email |removed_email_address@domain.invalid|
|billingAddress.firstName |Mickey|
|billingAddress.lastName |Mouse|
|billingAddress.street1 |249 Cross Road|
|billingAddress.city |Sanford|
|billingAddress.subCountry |ME|
|billingAddress.zipPostalCode|04073|
|billingAddress.country |US|

This step fills out a form using Selenium behind the scenes. It’s been
copied into several scenarios and I want to DRY it up. I DRY’d this up
by
moving this table data into a fixture file (mickey_mouse.yml), but then
the
test becomes less descriptive - the original scenario step above turned
into
a one-liner:

When I submit the form for “mickey_mouse”

I think ideally, I would like some kind of “include_step” feature in
cucumber - where we can write partial snippets and include them wherever
I
want. When cucumber runs, it can replace the included step. So I could
keep my tests DRY with something like:

When I submit the form
  Include 'submit_form_for_mickey_mouse'

but when I run the test, cucumber would spit out the partial contents in
place of the Include to make the test more descriptive.

Is there anything in cucumber that would help me out right now? What
I’m
currently looking into is hooking into the formatting and overriding
some
rendering - but it feels like a bad hack.

John G. RADSoft / Better Software Faster
removed_email_address@domain.invalid Lean/Agile/XP/Scrum Coaching and
Training
http://www.radsoft.com Ruby on Rails and Java Solutions


#2

Another thing I’m looking into is trying to hook into the
visitor/formatting
stuff and just spit out the extra data fixture data when the test
runs…
thoughts anyone?


#3

Hehe.

It’s funny I was after something just like this about a week ago…

Basically it’d be cool if there was an option to get cucumber to
explicitly say (on running) exactly which steps it was doing,
regardless of whether they were in a .feature file, or a _steps.rb file.

Julian.

Blog: http://random8.zenunit.com/
Learn: http://sensei.zenunit.com/
Twitter: http://twitter.com/random8r


#4

|billingAddress.subCountry |ME|

Right now the pretty formatter output is the same as the input (feature
source), because it’s also used as the foundation of --autoformat.
I also think that making the output different than the input could
potentially be confusing.

You get the # stepdef.rb:line comment, so finding the data shouldn’t be
hard.

Have you considered calling steps from step definitions and define the
table
in Ruby instead of in yml?
http://wiki.github.com/aslakhellesoy/cucumber/calling-steps-from-step-definitions

Aslak


#5

building, or just noise?

Hi Matt,

I thought about that noise thing - at first I thought it was just noise.
But then it turns out that specifying the values in the test actually
exposed errors that the customer did care about - so they would like
to
see them in the tests. I’ll rethink if it’s really just noise or not.
For
now, I think I’ll just pull it from the tests and see if anyone misses
not
seeing the tables in the test. If they don’t, then it was just noise.

Still, how hard would it be to have some kind of a include_partial
‘…’
behavior to cucumber tests ? There are always going to be times when
the
details are important enough that they should be seen in the test and we
want to express it as reuse table-like data.


#6

On 6 May 2009, at 19:28, John G. wrote:

|form_field_id |value|
been copied into several scenarios and I want to DRY it up. I DRY’d

When I submit the form
  Include 'submit_form_for_mickey_mouse'

but when I run the test, cucumber would spit out the partial
contents in place of the Include to make the test more descriptive.

Is there anything in cucumber that would help me out right now?
What I’m currently looking into is hooking into the formatting and
overriding some rendering - but it feels like a bad hack.

Why not write a wrapper step, something like

Given /I submit the billing address form with valid data/ do
submit_form {
:email => ‘removed_email_address@domain.invalid’,
:firstName => ‘Mickey’} # etc
end

And call that from your feature? Do you really need to see all the
fields in the formatted output? Are they relevant to the particular
scenario you’re building, or just noise?

Matt W.
http://blog.mattwynne.net
http://www.songkick.com