'Will' vs 'Should' in Then steps

27 views
Skip to first unread message

Matt Wynne

unread,
Oct 12, 2011, 10:37:01 AM10/12/11
to cu...@googlegroups.com, Dan North
We've had some feedback for the The Cucumber Book that we should encourage people to use the word "will" in their Then steps instead of "should". For example:

Given I have 2 cucumbers in my belly
When I eat another cucumber
Then I will have 3 cucumbers in my belly

As opposed to:

Given I have 2 cucumbers in my belly
When I eat another Cucumber
Then I should have 3 cucumber in my belly

I don't really know what I think about this. I'm so used to using 'should' in cukes I do it without really thinking about it. Has anybody tried this? Any experiences or opinions to share?

cheers,
Matt

--
Freelance programmer & coach
Author, http://pragprog.com/book/hwcuc/the-cucumber-book (with Aslak Hellesøy)
Founder, http://relishapp.com
+44(0)7974430184 | http://twitter.com/mattwynne

David Chelimsky

unread,
Oct 12, 2011, 10:42:31 AM10/12/11
to cu...@googlegroups.com, Dan North
On Oct 12, 2011, at 9:37 AM, Matt Wynne wrote:

> We've had some feedback for the The Cucumber Book that we should encourage people to use the word "will" in their Then steps instead of "should". For example:
>
> Given I have 2 cucumbers in my belly
> When I eat another cucumber
> Then I will have 3 cucumbers in my belly
>
> As opposed to:
>
> Given I have 2 cucumbers in my belly
> When I eat another Cucumber
> Then I should have 3 cucumber in my belly
>
> I don't really know what I think about this. I'm so used to using 'should' in cukes I do it without really thinking about it. Has anybody tried this? Any experiences or opinions to share?
>
> cheers,
> Matt

How about:

Given I have 2 cucumbers in my belly
When I eat another Cucumber

Then I have 3 cucumber in my belly

Feels more like a document of how it works, and removes the must/will/should debate.

WDYT?

Matt Wynne

unread,
Oct 12, 2011, 10:44:48 AM10/12/11
to cu...@googlegroups.com, Dan North

Yeah, that's nice in theory, but problem comes when you want to implement the step definition! There's no way to tell whether you're looking at a context setup or an outcome assertion step.

Doh!

Vamsi

unread,
Oct 12, 2011, 10:54:58 AM10/12/11
to cu...@googlegroups.com, Dan North
 "I don't really know what I think about this. I'm so used to using 'should' in cukes I do it without really thinking about it. Has anybody tried this? Any experiences or opinions to share?"

'Will'  makes more sense from a business prospective and  when a TPM or Businesss Analyst reads this in a feature file ; they find it more accurate in terms of business logic being applied .  

I bought your book and its really nice. Great Job !
Vamsi

Steve Tooke

unread,
Oct 12, 2011, 10:57:04 AM10/12/11
to cu...@googlegroups.com, Dan North
  Then there are 3 cucumbers in my belly

Steve
--
Heavies Limited
Registered Number: 7612561
Registered Address: Parmenter House, 57 Tower Street, Winchester SO23 8TD

Steve Tooke

unread,
Oct 12, 2011, 11:02:30 AM10/12/11
to cu...@googlegroups.com, Dan North
I guess the point is if you want to build living documentation for your system, you want to describe how the system works. Should doesn't read very well as documentation, as it seems to leave room for ambiguity.

But having either should or will scattered all over the scenarios makes for fairly dry text. Its about getting the balance right between making your steps readable for a business user, and removing ambiguity for the gherkin parser. Striking that balance depends very much on the audience for your scenarios and your application.

Vamsi

unread,
Oct 12, 2011, 11:18:17 AM10/12/11
to cu...@googlegroups.com, Dan North
I concur with Steve !

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

Mike Sassak

unread,
Oct 12, 2011, 12:21:14 PM10/12/11
to cu...@googlegroups.com
On Wed, Oct 12, 2011 at 9:44 AM, Matt Wynne <ma...@mattwynne.net> wrote:
>
> On 12 Oct 2011, at 15:42, David Chelimsky wrote:
>
>> On Oct 12, 2011, at 9:37 AM, Matt Wynne wrote:
>>
>>> We've had some feedback for the The Cucumber Book that we should encourage people to use the word "will" in their Then steps instead of "should". For example:
>>>
>>>   Given I have 2 cucumbers in my belly
>>>   When I eat another cucumber
>>>   Then I will have 3 cucumbers in my belly
>>>
>>> As opposed to:
>>>
>>>   Given I have 2 cucumbers in my belly
>>>   When I eat another Cucumber
>>>   Then I should have 3 cucumber in my belly
>>>
>>> I don't really know what I think about this. I'm so used to using 'should' in cukes I do it without really thinking about it. Has anybody tried this? Any experiences or opinions to share?
>>>
>>> cheers,
>>> Matt
>>
>> How about:
>>
>>   Given I have 2 cucumbers in my belly
>>   When I eat another Cucumber
>>   Then I have 3 cucumber in my belly
>>
>> Feels more like a document of how it works, and removes the must/will/should debate.
>>
>> WDYT?

+1

>
> Yeah, that's nice in theory, but problem comes when you want to implement the step definition! There's no way to tell whether you're looking at a context setup or an outcome assertion step.
>
> Doh!
>

I've been using this style for a while and haven't run into many
problems in practice. Whatever the case, I think the important part to
note is that the team's choice of language here is part of their
ubiquitous language in the DDD sense, so consistency and mutual
agreement trump any One Way.

Mike

> cheers,
> Matt
>
> --
> Freelance programmer & coach
> Author, http://pragprog.com/book/hwcuc/the-cucumber-book (with Aslak Hellesøy)
> Founder, http://relishapp.com
> +44(0)7974430184 | http://twitter.com/mattwynne
>

Scott Smith

unread,
Oct 12, 2011, 11:12:38 PM10/12/11
to cu...@googlegroups.com
+1  Succinctly put

Scott
 
Mike

> cheers,
> Matt
>
> --
> Freelance programmer & coach
> Author, http://pragprog.com/book/hwcuc/the-cucumber-book (with Aslak Hellesøy)
> Founder, http://relishapp.com
> +44(0)7974430184 | http://twitter.com/mattwynne
>
> --
> 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.
>
>

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




--
Scott Smith

http://twitter.com/_ofd (OldFartDeveloper)

Graham Agnew

unread,
Oct 13, 2011, 6:42:22 AM10/13/11
to cu...@googlegroups.com
I work with formal requirement specifications a fair bit (both as a producer and consumer).  We use "shall" as an unambiguous way to state what the system must do.  So if I was to use gherkin as requirements documentation, I think I would continue with this.  The word "should" implies something conditional, and I think is fine for use within the step definitions - the value should match something and if it doesn't you're step def will throw an exception.

Given I start with 2 cucumbers in my belly

When I eat another Cucumber
Then I shall have 3 cucumbers in my belly

However including "shall" everywhere affects the reuse of the step def.  So I like to make the word optional by enclosing it in a non-returned group in the regex.  The step definition can then be re-used to validate the initial conditions:

Given I start with 2 cucumbers in my belly
And I eat another Cucumber
And I have 3 cucumbers in my belly
When I eat another Cucumber
Then I shall have 4 cucumbers in my belly

And the step def:

Then /I (?:shall)? have (\d+) cucumbers in my belly/ do |count|
  @belly.cuke_count.should_equal count
end

The use of "shall" is recommended in RFC2119 and there's a discussion of Shall and Will on Wikipedia.

Cheers,
Gra.

byrnejb

unread,
Oct 13, 2011, 9:51:46 AM10/13/11
to Cukes


On Oct 12, 10:37 am, Matt Wynne <m...@mattwynne.net> wrote:
> We've had some feedback for the The Cucumber Book that we should encourage people to use the word "will" in their Then steps instead of "should". For example:
>
>     Given I have 2 cucumbers in my belly
>     When I eat another cucumber
>     Then I will have 3 cucumbers in my belly
>
> As opposed to:
>
>     Given I have 2 cucumbers in my belly
>     When I eat another Cucumber
>     Then I should have 3 cucumber in my belly
>
> I don't really know what I think about this. I'm so used to using 'should' in cukes I do it without really thinking about it. Has anybody tried this? Any experiences or opinions to share?
>

I would leave things alone in the book examples. The actual
implementation is a team based decision in any case and the use of
"should", while not universal, is pervasive elsewhere in the BDD
literature. That said, I can see nothing wrong with including in the
Cuke book a short description of the strengths and weaknesses of using
"must", "will" or "shall", or no qualifier at all, instead of "should"
in the Then steps. Actually, I think such a discussion might be
useful in a more general sense of why steps should be written a
certain way.

On Oct 12, 10:44 am, Matt Wynne <m...@mattwynne.net> wrote:
>
> Yeah, that's nice in theory, but problem comes when you want to implement the step definition! There's no way to tell whether you're looking at a context setup or an outcome assertion step.
>

My own practice is to preface "have" with "do(?:es)?( not)?" when
"have" (or other transitive verb) is used in the predicate manner and
vary using "shall"/"should" as a preface to "have" when used in the
result step. That way the negation step appears, to me, more
consistent with its positive counterpart inside the feature file.
Because I customarily write the negation step definition at the same
time as the positive the regex ambiguity that otherwise might result
is eliminated.:

Given I do have 4 apples
And I do not have 1 orange

As was pointed out to me on this list long ago, it is the precise
employment of the words used that is important and not precisely which
words are used.

Matt Wynne

unread,
Oct 14, 2011, 5:17:26 AM10/14/11
to cu...@googlegroups.com
On 13 Oct 2011, at 11:42, Graham Agnew wrote:

The use of "shall" is recommended in RFC2119 and there's a discussion of Shall and Will on Wikipedia.

I certainly didn't expect an RFC reference. Awesome answer!

Reply all
Reply to author
Forward
0 new messages