Hi Bart,
I think you mentioned above the solution most people come to: using
helper methods defined in the World rather than deeply nesting steps.
In my experience using helpers is much more maintainable than deeply
nested steps, and I'm sure I'm not alone on that point. Is there a
reason you're unsure about using World helpers?
Mike
>
> Kindly,
> Bart
>
> --
> 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.
>
>
Hi,
WIth only a small exaggeration, if you're not extending the World,
you're missing out on half of Cucumber. :-)
The wiki is helpful, as usual. These links should help get you started
* http://github.com/aslakhellesoy/cucumber/wiki/A-Whole-New-World
* http://drnicwilliams.com/2009/04/15/cucumber-building-a-better-world-object/
Mike
Hi Bart,
In your original email you said that debugging nested steps becomes
difficult when they are nested deeply. I suggested using extensions to
the World rather than nested steps, as the former are in my experience
far easier to debug and maintain than deeply nested steps. (Say nested
deeper than 1 level.) In other words, avoid nesting steps almost
entirely and start thinking of how to accomplish the same with "plain
old Ruby"--you can do everything in World extension modules that you
can in step definitions and more. Think of the step definitions
themselves as a very thin translation layer between the requirements
of your application expressed in natural language (in the feature
files) and a "World" layer written in the implementation language that
places your app into a certain state and then verifies that state
against expectations. If you're using Rails perhaps you've heard the
saying "Skinny Controller, Fat Model". Something kind of similar
applies to step definitions and extensions to World.
HTH,
Mike
On 9/30/10 6:47 PM, Mike Sassak wrote:
> In your original email you said that debugging nested steps becomes
> difficult when they are nested deeply. I suggested using extensions to
> the World rather than nested steps, as the former are in my experience
> far easier to debug and maintain than deeply nested steps. (Say nested
> deeper than 1 level.) In other words, avoid nesting steps almost
> entirely and start thinking of how to accomplish the same with "plain
> old Ruby"--you can do everything in World extension modules that you
> can in step definitions and more. Think of the step definitions
> themselves as a very thin translation layer between the requirements
> of your application expressed in natural language (in the feature
> files) and a "World" layer written in the implementation language that
> places your app into a certain state and then verifies that state
> against expectations. If you're using Rails perhaps you've heard the
> saying "Skinny Controller, Fat Model". Something kind of similar
> applies to step definitions and extensions to World.
Certainly this is one way to do things, but it's at odds with Cucumber
as an enabler of functional specification by non-programmers. I counsel
testers to take their imperative tests and push them down into step
definitions written in gherkin. As they do so, there seems to naturally
be multiple levels of these. And debugging mistakes seems to be the
biggest difficulty.
I think it's worth exploring what we can do better, here. Otherwise we
run the risk of creating yet another tool that speaks to the
programmers, but asks the testers and business people to take it on faith.
- George
--
----------------------------------------------------------------------
* George Dinwiddie * http://blog.gdinwiddie.com
Software Development http://www.idiacomputing.com
Consultant and Coach http://www.agilemaryland.org
----------------------------------------------------------------------
Hi George,
Can you elaborate on these points? I don't see how using moving
commonly-used functionality into extensions to the World would prevent
non-programmers from writing scenarios in Gherkin. The step names will
remain written in natural language--no problem for non-programmers
there--and most helpers are simple, imperative code as well.
Mike
> - George
>
> --
> ----------------------------------------------------------------------
> * George Dinwiddie * http://blog.gdinwiddie.com
> Software Development http://www.idiacomputing.com
> Consultant and Coach http://www.agilemaryland.org
> ----------------------------------------------------------------------
>
On 2 Oct 2010, at 13:41, George Dinwiddie wrote:
> Mike, et al,
>
> On 9/30/10 6:47 PM, Mike Sassak wrote:
>> In your original email you said that debugging nested steps becomes
>> difficult when they are nested deeply. I suggested using extensions to
>> the World rather than nested steps, as the former are in my experience
>> far easier to debug and maintain than deeply nested steps. (Say nested
>> deeper than 1 level.) In other words, avoid nesting steps almost
>> entirely and start thinking of how to accomplish the same with "plain
>> old Ruby"--you can do everything in World extension modules that you
>> can in step definitions and more. Think of the step definitions
>> themselves as a very thin translation layer between the requirements
>> of your application expressed in natural language (in the feature
>> files) and a "World" layer written in the implementation language that
>> places your app into a certain state and then verifies that state
>> against expectations. If you're using Rails perhaps you've heard the
>> saying "Skinny Controller, Fat Model". Something kind of similar
>> applies to step definitions and extensions to World.
>
> Certainly this is one way to do things, but it's at odds with Cucumber as an enabler of functional specification by non-programmers. I counsel testers to take their imperative tests and push them down into step definitions written in gherkin. As they do so, there seems to naturally be multiple levels of these. And debugging mistakes seems to be the biggest difficulty.
Certainly the way Cucumber is right now, I really would try to suggest that at that point, the tester goes to the original (imperative) step definition that they want to re-use within this other step definition, and extracts whatever contents it has into a helper method, then replaces use of the imperative step definition with a call to that method. Otherwise, apart from the specific debugging problem highlighted here, you have an unnecessary amount of indirection, and more complex dependencies going on in your codebase.
I think Mike also mentioned this, and I'm very much coming around to the opinion that the step definitions should be a very thin layer over a set of Ruby helpers that do all the hard work *in your domain language*. So rather than calling fill_in, click_button etc, they say log_in_as, and let that helper do all the hard work. To that end, I think it's important to help testers to feel comfortable extracting and creating their own Ruby methods.
I tried to talk about this in a blog post recently:
It sounds like you have a different perspective though. Do you think I'm going off in the wrong direction here?
> I think it's worth exploring what we can do better, here. Otherwise we run the risk of creating yet another tool that speaks to the programmers, but asks the testers and business people to take it on faith.
So are you saying that it would be useful to you to have a business-friendly way (i.e. more Gherkin than Ruby) to map an abstract step to a series of - more imperative - step definitions?
>
> - George
>
> --
> ----------------------------------------------------------------------
> * George Dinwiddie * http://blog.gdinwiddie.com
> Software Development http://www.idiacomputing.com
> Consultant and Coach http://www.agilemaryland.org
> ----------------------------------------------------------------------
>
> --
> 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.
>
cheers,
Matt
> I tried to talk about this in a blog post recently:
Sorry, forgot the link.
http://blog.mattwynne.net/2010/08/31/outside-in-vs-inside-out-comparing-tdd-approaches/
Let's look at a typical scenario. The tester starts out with a series
of imperative steps: enter this text in this field, check this checkbox,
click this button. These are a natural place to start, particularly for
a tester new to automation.
I then counsel them to push these actions down into step definitions
written in Gherkin. Now they have steps such as "login as <user>,"
"search for <partial name>," "add <product name> to cart," and "submit
order." These steps are still of the imperative style, but written in
terms of the application, rather than in terms of the implementation
details.
On top of that, we can build more declarative step declarations such as
"Given I have the following books in my cart" and "When I purchase using
a valid VISA card."
As a programmer, I can rewrite the lower steps in ruby, but I'm not sure
it's a good idea to do so. For non-programmers, it's now a leap of
faith that the test does what they think it does.
OK I'm with you I think. So the leap of faith comes when they switch from implementing the step definition using #steps to call other step definitions in gherkin, to implementing it using Ruby methods? Even Ruby methods like fill_in, click_button etc?
Yes, some business people are highly allergic to something that looks
like code. But from another point of view, why should I rewrite my
working gherkin steps in ruby?