[Cucumber] Scenario Outline Requires Quoted Var Placeholders in Steps?

797 views
Skip to first unread message

Tim Walker

unread,
Dec 3, 2015, 10:22:20 AM12/3/15
to cu...@googlegroups.com
The following was with these jars:
gherkin-2.12.2.jar
cucumber-jvm-deps-1.0.5.jar
cucumber-core-1.2.4.jar
cucumber-java-1.2.4.jar

Hi,

This is probably an old question but I searched the groups and i just didn't see an answer. I am seeing this in both Ruby and Java versions and this seems different from the books and existing documentation, as well as my examples and understanding. That is, String values in Scenario Outlines: generate a snippet for each row in the table unless the <variable> in the step is surrounded by double quotes, i.e. "<variable>".  I just don't recall seeing this and am hoping someone can help.

 

 My example -

 Feature:

   Scenario Outline:
     Given Bob says <a>
     When Bill says <b>
     Then Bernie says <c>

     Examples:
     | a | b | c |
     | z | y | x |
     | w | v | u |
     | t | s | r |
     | q | p | o |

 You can implement step definitions for undefined steps with these snippets:

   Given(/^Bob says z$/) do
   pending # express the regexp above with the code you wish you had
   end

   When(/^Bill says y$/) do
   pending # express the regexp above with the code you wish you had
   end

   Then(/^Bernie says x$/) do
   pending # express the regexp above with the code you wish you had
   end

   Given(/^Bob says w$/) do
   pending # express the regexp above with the code you wish you had
   end

   When(/^Bill says v$/) do
   pending # express the regexp above with the code you wish you had
   end

   Then(/^Bernie says u$/) do
   pending # express the regexp above with the code you wish you had
   end

   Given(/^Bob says t$/) do
   pending # express the regexp above with the code you wish you had
   end

   When(/^Bill says s$/) do
   pending # express the regexp above with the code you wish you had
   end

   Then(/^Bernie says r$/) do
   pending # express the regexp above with the code you wish you had
   end

     Given(/^Bob says q$/) do
   pending # express the regexp above with the code you wish you had
   end

     When(/^Bill says p$/) do
   pending # express the regexp above with the code you wish you had
   end

     Then(/^Bernie says o$/) do
   pending # express the regexp above with the code you wish you had
   end

 ----------------------------- But -----------------------------
 Feature:

   Scenario Outline:
     Given Bob says "<a>"
     When Bill says "<b>"
     Then Bernie says "<c>"

     Examples:
     | a | b | c |
     | z | y | x |
     | w | v | u |
     | t | s | r |
     | q | p | o |

 You can implement step definitions for undefined steps with these snippets:

 Given(/^Bob says "(.*?)"$/) do |arg1|
   pending # express the regexp above with the code you wish you had
 end

 When(/^Bill says "(.*?)"$/) do |arg1|
   pending # express the regexp above with the code you wish you had
 end

 Then(/^Bernie says "(.*?)"$/) do |arg1|
   pending # express the regexp above with the code you wish you had
 end

Replicated with: 

gherkin-2.12.2.jar
cucumber-jvm-deps-1.0.5.jar
cucumber-core-1.2.4.jar
cucumber-java-1.2.4.jar

What gives? Really makes scenario outlines ugly! 

Thank you very much! Love Cucumber! 

Sincerely, 

Tim

Tim Walker

unread,
Dec 9, 2015, 9:15:38 AM12/9/15
to cu...@googlegroups.com

Any thoughts on this?

George Dinwiddie

unread,
Dec 9, 2015, 10:42:32 AM12/9/15
to cu...@googlegroups.com
Tim,

How often do you encounter this issue? I worry that the snippet
generator could become big and complicated, making me think more about
its rules than about the functionality I'm describing. Then, I don't
have much problem editing the regexes on my own.

I generally just put quotes around the scenario outline fields to
generate the snippets, and then remove the quotes from the gherkin and
snippets.

I don't run into this problem much because I start with a scenario
before generalizing it to a scenario outline.

- George

On 12/9/15 9:15 AM, Tim Walker wrote:
> Any thoughts on this?
>
> On Dec 3, 2015 08:22, "Tim Walker" <walk...@gmail.com
> --
> Posting rules: http://cukes.info/posting-rules.html
> ---
> You received this message because you are subscribed to the Google
> Groups "Cukes" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to cukes+un...@googlegroups.com
> <mailto:cukes+un...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.

--
----------------------------------------------------------------------
* George Dinwiddie * http://blog.gdinwiddie.com
Software Development http://www.idiacomputing.com
Consultant and Coach http://www.agilemaryland.org
----------------------------------------------------------------------

Andrew Premdas

unread,
Dec 10, 2015, 1:19:20 AM12/10/15
to cu...@googlegroups.com
Personally I think the snippet generator is doing roughly the correct thing, if you think about how outlines and arguments work.

You could have a think about why are you using outlines in the first place. Nowadays, having using Cucumber for many years, I see outlines as a smell and just don't use them. Instead I push that programming down into the step definitions.

Any thoughts on this?

--
Posting rules: http://cukes.info/posting-rules.html
---
You received this message because you are subscribed to the Google Groups "Cukes" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+un...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
------------------------
Andrew Premdas

Tim Walker

unread,
Dec 15, 2015, 7:59:26 AM12/15/15
to cu...@googlegroups.com
On Wed, Dec 9, 2015 at 9:42 AM, George Dinwiddie <li...@idiacomputing.com> wrote:
Tim,

How often do you encounter this issue? I worry that the snippet generator could become big and complicated, making me think more about its rules than about the functionality I'm describing. Then, I don't have much problem editing the regexes on my own.

I generally just put quotes around the scenario outline fields to generate the snippets, and then remove the quotes from the gherkin and snippets.

I don't run into this problem much because I start with a scenario before generalizing it to a scenario outline.

[tim] Thanks for the response George! I can see that as a workable solution but it bugs me a bit because I don't believe this was always the case and this is how it is documented in the books, etc. Just curious when that started. It's very confusing to the folks just learning. Thanks again George! Tim
 
To unsubscribe from this group and stop receiving emails from it, send an email to cukes+un...@googlegroups.com.

Tim Walker

unread,
Dec 15, 2015, 8:05:08 AM12/15/15
to cu...@googlegroups.com
On Dec 9, 2015 23:19, "Andrew Premdas" <apre...@gmail.com> wrote:
Personally I think the snippet generator is doing roughly the correct thing, if you think about how outlines and arguments work.

[Tim] Thank you very, very much Andrew, but I'd have to respectfully disagree. The angle brackets in the lexicon would indicate a variable is being substituted in the regular expression in all cases. 
 
You could have a think about why are you using outlines in the first place. Nowadays, having using Cucumber for many years, I see outlines as a smell and just don't use them. Instead I push that programming down into the step definitions.

[Tim] I hear you except that I'd argue that it's a very valid way to express behavior that differs only in the data presented and that the power of data organized like this makes it easy to spot gaps in the test cases. One of the challenging parts of Specification by Example is the intersection of true concrete examples of behavior with an abstract declaration of intent. We use examples to remove ambiguity and increase understanding and then abstract the example back to a statement that can be replete with misunderstandings. Thanks again for the responses! Tim

Matt Wynne

unread,
Dec 15, 2015, 4:15:25 PM12/15/15
to Cukes


On Tuesday, December 15, 2015 at 7:59:26 AM UTC-5, Halfordian Golfer wrote:


On Wed, Dec 9, 2015 at 9:42 AM, George Dinwiddie <li...@idiacomputing.com> wrote:
Tim,

How often do you encounter this issue? I worry that the snippet generator could become big and complicated, making me think more about its rules than about the functionality I'm describing. Then, I don't have much problem editing the regexes on my own.

I generally just put quotes around the scenario outline fields to generate the snippets, and then remove the quotes from the gherkin and snippets.

I don't run into this problem much because I start with a scenario before generalizing it to a scenario outline.

[tim] Thanks for the response George! I can see that as a workable solution but it bugs me a bit because I don't believe this was always the case and this is how it is documented in the books, etc. Just curious when that started. It's very confusing to the folks just learning. Thanks again George! Tim

Can you tell me exactly what documentation you've seen elsewhere that contradicts the behaviour of Cucumber? If it's in The Cucumber Book I'd be surprised, but we can fix it if we know where the mistake is.

Björn Rasmusson

unread,
Dec 20, 2015, 5:09:56 AM12/20/15
to Cukes
To answer the question in the topic "Scenario Outline Requires Quoted Var Placeholders in Steps?":

No, quoted placeholders are not required. This is shown by the examples in the Cucumber-JVM repo, fo instance the step:
https://github.com/cucumber/cucumber-jvm/blob/master/examples/java-calculator/src/test/resources/cucumber/examples/java/calculator/basic_arithmetic.feature#L23
and the corresponding step definition:
https://github.com/cucumber/cucumber-jvm/blob/master/examples/java-calculator/src/test/java/cucumber/examples/java/calculator/RpnCalculatorStepdefs.java#L22


Halfordian Golfer wrote:
On Dec 9, 2015 23:19, "Andrew Premdas" <apre...@gmail.com> wrote:
Personally I think the snippet generator is doing roughly the correct thing, if you think about how outlines and arguments work.

[Tim] Thank you very, very much Andrew, but I'd have to respectfully disagree. The angle brackets in the lexicon would indicate a variable is being substituted in the regular expression in all cases. 
 
I would say that a more accurate description is that when the scenario outline is expanded to a set of scenarios/test-cases, then the angle brackets are replaces with the text from the examples table, to create new steps. Theses new steps are matched to step definitions. The step definitions matched may or may not capture part of the text as arguments. It is totally up to the person who write the step definitions and their regular expressions.

In defence of the snippet generator, if it sees a step text as:
foo bar 1

what should it do? The person wrote the step may think that "foo" should be captured as an argument to the step definition, or "bar" or "1", but how should the snippet generator know that?

In your example below, the snippet generator sees:
Bob says z

this is all the snippet generator knows, so it does the straight forward thing and generates the snippet:

   Given(/^Bob says z$/) do
   pending
# express the regexp above with the code you wish you had
   
end

It you would like to have a step definition with a different regex, you are free to write a step definition with that regex instead of using the snippet generators suggestion.
 
You could have a think about why are you using outlines in the first place. Nowadays, having using Cucumber for many years, I see outlines as a smell and just don't use them. Instead I push that programming down into the step definitions.

[Tim] I hear you except that I'd argue that it's a very valid way to express behavior that differs only in the data presented and that the power of data organized like this makes it easy to spot gaps in the test cases. One of the challenging parts of Specification by Example is the intersection of true concrete examples of behavior with an abstract declaration of intent. We use examples to remove ambiguity and increase understanding and then abstract the example back to a statement that can be replete with misunderstandings. Thanks again for the responses! Tim
 
On 9 December 2015 at 14:15, Tim Walker <walk...@gmail.com> wrote:

Any thoughts on this?

On Dec 3, 2015 08:22, "Tim Walker" <walk...@gmail.com> wrote:
The following was with these jars:
gherkin-2.12.2.jar
cucumber-jvm-deps-1.0.5.jar
cucumber-core-1.2.4.jar
cucumber-java-1.2.4.jar

Hi,

This is probably an old question but I searched the groups and i just didn't see an answer. I am seeing this in both Ruby and Java versions and this seems different from the books and existing documentation, as well as my examples and understanding.
Does these books and documentation really specify the snippets generated for steps expanded from scenario outlines?
I would imagine that book and documentation were more focused on the principles and use of scenario outlines, rather than the detail of the generation of snippets.

Regards
Björn
 
Reply all
Reply to author
Forward
0 new messages