Do step definition prepositions not matter to Cucumber?

86 views
Skip to first unread message

Arve Knudsen

unread,
May 5, 2011, 9:39:37 AM5/5/11
to cu...@googlegroups.com
Hi

Is it correct that step definitions' prepositions (Given, When, Then) do not matter? The wiki says thatĀ 'The adjective/adverb hasĀ noĀ significance when Cucumber is registering or looking for Step Definitions.' I would think Given/When/Then are prepositions rather than adjectives/adverbs, but I guess that's what's referred to here?

Anyway, if it is indeed correct that Cucumber disregards the preposition (or whatever you want to call it) upon the loading of step definitions, what's the rationale for this behaviour? For instance, if I write a Given step definition 'Given /^something$/ do', this'll also match 'Then something'. I just found out about this today and it utterly confused me (I happened to write a Then step definition with the same pattern as a Given step definition).

Arve

Phillip Koebbe

unread,
May 5, 2011, 9:45:41 AM5/5/11
to cu...@googlegroups.com

I'm definitely not speaking as an authority on this, but I can tell you
from experience that the word (Given, When, Then) does not matter in the
_steps.rb files. I create absolutely all of mine using Given and have
had zero problems.

Peace,
Phillip

Tom ten Thij

unread,
May 5, 2011, 9:46:11 AM5/5/11
to cu...@googlegroups.com
> Is it correct that step definitions' prepositions (Given, When, Then) do not matter?

That is correct. If you are writing your steps with the intention for
them to behave differently based on what preposition is used, you are
writing steps that will become too confusing.

Tom.

-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~
Ā Tom ten Thij
Ā Unboxed Consulting, http://unboxedconsulting.com
Ā T: +44 20 3137 2943 F: +44 20 7183 4251
-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~-~


On Thu, May 5, 2011 at 2:39 PM, Arve Knudsen <arve.k...@gmail.com> wrote:
> Hi


> Cucumber is registering or looking for Step Definitions.' I would think
> Given/When/Then are prepositions rather than adjectives/adverbs, but I guess
> that's what's referred to here?
> Anyway, if it is indeed correct that Cucumber disregards the preposition (or
> whatever you want to call it) upon the loading of step definitions, what's
> the rationale for this behaviour? For instance, if I write a Given step
> definition 'Given /^something$/ do', this'll also match 'Then something'. I
> just found out about this today and it utterly confused me (I happened to
> write a Then step definition with the same pattern as a Given step
> definition).
> Arve
>

> --
> 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.
>

Jon Kern

unread,
May 5, 2011, 10:04:03 AM5/5/11
to cu...@googlegroups.com
from what i gather, the regex matcher becomes the "method" name... you
should not have two identical methods in a class :-)

use the Given/When/Then and Ands to make your scenarios read better in
the feature file. How they are implemented in the steps doesn't matter
(for example, reusing a prior "Then" from one scenario as an "And" in
another scenario).

The more logical you make your "methods" the easier it will be to reuse
them for subsequent scenarios. I often find myself writing less and less
step definitions as the feature scenarios for a given part of my
application grow over time. It is indeed a sweet thing.

I also find myself looking at some of my very first feature files and
throwing up a little at how stupid they look. So I refactor them :-)

jon
blog: http://technicaldebt.com
twitter: http://twitter.com/JonKernPA


Arve Knudsen said the following on 5/5/11 9:39 AM:

aslak hellesoy

unread,
May 5, 2011, 10:10:44 AM5/5/11
to cu...@googlegroups.com
On Thu, May 5, 2011 at 2:39 PM, Arve Knudsen <arve.k...@gmail.com> wrote:
Hi

Is it correct that step definitions' prepositions (Given, When, Then) do not matter? The wiki says thatĀ 'The adjective/adverb hasĀ noĀ significance when Cucumber is registering or looking for Step Definitions.' I would think Given/When/Then are prepositions rather than adjectives/adverbs, but I guess that's what's referred to here?


All dictionaries I have seen describe Given as an adjective and When/Then as adverbs (in the context they are used in Gherkin).
A preposition is a word that says something about an object's position - for example On the sofa, Behind the desk etc.
Ā 
Anyway, if it is indeed correct that Cucumber disregards the preposition (or whatever you want to call it) upon the loading of step definitions, what's the rationale for this behaviour? For instance, if I write a Given step definition 'Given /^something$/ do', this'll also match 'Then something'. I just found out about this today and it utterly confused me (I happened to write a Then step definition with the same pattern as a Given step definition).


The rationale of the decision is simplicity. Although not used a lot, all Gherkin adverb/adjectives are aliased with "* ", making it impossible to distinguish them if you say:

* I have 4 cukes in my basket
* I eat 1 cuke
* I have 1 cukes in my belly

I also second what Tom says - this "limitation" is also there to protect you from accidentally ambiguous language.

Aslak

Arve Knudsen

unread,
May 5, 2011, 10:37:37 AM5/5/11
to cu...@googlegroups.com
On Thu, May 5, 2011 at 4:10 PM, aslak hellesoy <aslak.h...@gmail.com> wrote:


On Thu, May 5, 2011 at 2:39 PM, Arve Knudsen <arve.k...@gmail.com> wrote:
Hi

Is it correct that step definitions' prepositions (Given, When, Then) do not matter? The wiki says thatĀ 'The adjective/adverb hasĀ noĀ significance when Cucumber is registering or looking for Step Definitions.' I would think Given/When/Then are prepositions rather than adjectives/adverbs, but I guess that's what's referred to here?


All dictionaries I have seen describe Given as an adjective and When/Then as adverbs (in the context they are used in Gherkin).
A preposition is a word that says something about an object's position - for example On the sofa, Behind the desk etc.

I would expect an adverb to modify a verb ("he runs fast"). I used this discussion as reference:Ā http://forum.wordreference.com/showthread.php?t=634026.
Ā 
Ā 
Anyway, if it is indeed correct that Cucumber disregards the preposition (or whatever you want to call it) upon the loading of step definitions, what's the rationale for this behaviour? For instance, if I write a Given step definition 'Given /^something$/ do', this'll also match 'Then something'. I just found out about this today and it utterly confused me (I happened to write a Then step definition with the same pattern as a Given step definition).


The rationale of the decision is simplicity. Although not used a lot, all Gherkin adverb/adjectives are aliased with "* ", making it impossible to distinguish them if you say:

* I have 4 cukes in my basket
* I eat 1 cuke
* I have 1 cukes in my belly

Aha, this was new to me.Ā 

I also second what Tom says - this "limitation" is also there to protect you from accidentally ambiguous language.

I don't see it as ambiguous myself (if you take the preposition into account). I think it's worse that a step definition intended for Given steps can be applied to When/Then steps, but that's my opinion.

ArveĀ 

Arve Knudsen

unread,
May 5, 2011, 10:43:20 AM5/5/11
to cu...@googlegroups.com
On Thu, May 5, 2011 at 4:10 PM, aslak hellesoy <aslak.h...@gmail.com> wrote:
All dictionaries I have seen describe Given as an adjective and When/Then as adverbs (in the context they are used in Gherkin).
A preposition is a word that says something about an object's position - for example On the sofa, Behind the desk etc.Ā 

Arve Knudsen

unread,
May 5, 2011, 10:46:59 AM5/5/11
to cu...@googlegroups.com
Looking up When and Then, though, I see they're classified as adverbs. Interesting :)

Arve

aslak hellesoy

unread,
May 5, 2011, 10:52:39 AM5/5/11
to cu...@googlegroups.com

Arve Knudsen

unread,
May 5, 2011, 1:30:35 PM5/5/11
to cu...@googlegroups.com
On Thu, May 5, 2011 at 4:52 PM, aslak hellesoy <aslak.h...@gmail.com> wrote:


On Thu, May 5, 2011 at 3:43 PM, Arve Knudsen <arve.k...@gmail.com> wrote:
On Thu, May 5, 2011 at 4:10 PM, aslak hellesoy <aslak.h...@gmail.com> wrote:
All dictionaries I have seen describe Given as an adjective and When/Then as adverbs (in the context they are used in Gherkin).
A preposition is a word that says something about an object's position - for example On the sofa, Behind the desk etc.Ā 




Hehe :) I got to learn something too!Ā 

ArveĀ 

Rick DeNatale

unread,
May 8, 2011, 6:12:11 PM5/8/11
to cu...@googlegroups.com
On Thu, May 5, 2011 at 10:10 AM, aslak hellesoy
<aslak.h...@gmail.com> wrote:
>
>
> On Thu, May 5, 2011 at 2:39 PM, Arve Knudsen <arve.k...@gmail.com> wrote:
>>
>> Hi
>> Is it correct that step definitions' prepositions (Given, When, Then) do
>> not matter? The wiki says thatĀ 'The adjective/adverb hasĀ noĀ significance
>> when Cucumber is registering or looking for Step Definitions.' I would think
>> Given/When/Then are prepositions rather than adjectives/adverbs, but I guess
>> that's what's referred to here?
>
> All dictionaries I have seen describe Given as an adjective and When/Then as
> adverbs (in the context they are used in Gherkin).
> A preposition is a word that says something about an object's position - for
> example On the sofa, Behind the desk etc.

FWIW, the New Oxford American Dictionary (the one which comes with OS
X) indicates that the usage of given in Cucumber steps IS a
preposition.

given |ˈgivən|
past participle of give .
adjective
1 specified or stated : our level of knowledge on any given subject.
2 [ predic. ] ( given to) inclined or disposed to : she was not
often given to anger.
3 conferred or bestowed as a gift : she squandered what was a given
opportunity.
4 archaic Law (of a document) signed and dated : given under my hand
this eleventh day of April.

preposition
taking into account : given the complexity of the task, they were
able to do a good job.

noun
a known or established fact or situation : at a couture house,
attentive service is a given.

And while some prepositions indicate positional relationships, the
word is more general than that:

preposition |ˌprepÉ™Ėˆzi sh ən|
noun Grammar
a word governing, and usually preceding, a noun or pronoun and
expressing a relation to another word or element in the clause, as in
ā€œthe man on the platform,ā€ ā€œshe arrived after dinner,ā€ ā€œwhat did you
do it for ?ā€


The words when, then, 'and' and but as used in Gherkin are used as conjunctions.

--
Rick DeNatale

Blog: http://talklikeaduck.denhaven2.com/
Github: http://github.com/rubyredrick
Twitter: @RickDeNatale
WWR: http://www.workingwithrails.com/person/9021-rick-denatale
LinkedIn: http://www.linkedin.com/in/rickdenatale

Reply all
Reply to author
Forward
0 new messages