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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
3f37c31a4f7c9ae3743b4464dbbd4652?d=identicon&s=25 John Goodsen (Guest)
on 2009-05-06 20:26
(Received via mailing list)
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        |mickey_mouse@test.com|
   |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 Goodsen                 RADSoft / Better Software Faster
jgoodsen@radsoft.com            Lean/Agile/XP/Scrum Coaching and
Training
http://www.radsoft.com          Ruby on Rails and Java Solutions
3f37c31a4f7c9ae3743b4464dbbd4652?d=identicon&s=25 John Goodsen (Guest)
on 2009-05-06 20:46
(Received via mailing list)
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?
4e13e53b030e7751b777e439357fe902?d=identicon&s=25 Julian Leviston (Guest)
on 2009-05-06 20:50
(Received via mailing list)
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
0be0e4aa42aacd9a8a95c792de273ca7?d=identicon&s=25 Aslak Hellesøy (aslakhellesoy)
on 2009-05-06 21:00
(Received via mailing list)
>    |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/call...

Aslak
Cdf378de2284d8acf137122e541caa28?d=identicon&s=25 Matt Wynne (mattwynne)
on 2009-05-06 21:03
(Received via mailing list)
On 6 May 2009, at 19:28, John Goodsen 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 => 'mickey_mouse@test.com',
     :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 Wynne
http://blog.mattwynne.net
http://www.songkick.com
3f37c31a4f7c9ae3743b4464dbbd4652?d=identicon&s=25 John Goodsen (Guest)
on 2009-05-06 23:46
(Received via mailing list)
> 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.
This topic is locked and can not be replied to.