# Cucumber Scenario syntax

**URL:** <https://www.ruby-forum.com/t/cucumber-scenario-syntax/148419>\
**Category:** RSpec\
**Created:** [September 12, 2008, 5:37pm UTC](https://www.ruby-forum.com/t/cucumber-scenario-syntax/148419 "2008-09-12T17:37:14Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![elight](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/35a633/32.png) [@elight](https://www.ruby-forum.com/u/elight)\
**Post date:** [September 12, 2008, 5:37pm UTC](https://www.ruby-forum.com/t/cucumber-scenario-syntax/148419/1 "2008-09-12T17:37:14Z")

</div>

Last night, I gave a presentation to the DC Ruby U. Group  
([http://dcrug.org](http://dcrug.org)  
) on Plain Text Stories with Ruby. I spoke on both RSpec Plain Text  
Stories, which I have used, and Cucumber which I started to dig into a  
couple of nights ago. You can see the presentation here  
([http://evan.tiggerpalace.com/2008/09/11/plain-text-stories-at-dcrug/](http://evan.tiggerpalace.com/2008/09/11/plain-text-stories-at-dcrug/)  
) if that floats your boat.

You may also note in the linked blog entry that the general consensus  
at DCRUG (and my own feeling as well) is that Cucumber’s scenario  
syntax perhaps assumes undue technical ignorance on the part of the  
scenario author(s).

It seems odd to me (and several DCRUGgers) that the hooks into the  
Scenario steps/substitution points are not apparent by reading the  
Scenario plain text. That is, you have to read the Scenario step  
implementations to figure out where the hooks are in the Scenario  
plain text.

This seems somewhat wrong-headed. As one DCRUGger said to me last  
night, we should at least assume that Scenario authors can handle a  
basic Excel spreadsheet. That is, that the Scenario could contain the  
FIT table column headers so that the Scenarios serve as templates that  
are specialized by rows in the FIT table. This seems more natural as  
the substitutions become far clearer just by looking at the plain text.

Disclaimer: My exposure to FIT is limited to a quick read of Ward  
Cunningham’s page on FIT and Cucumber.

Evan

---

<div class="post-metadata">

**Author:** ![elight](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/35a633/32.png) [@elight](https://www.ruby-forum.com/u/elight)\
**Post date:** [September 12, 2008, 6:02pm UTC](https://www.ruby-forum.com/t/cucumber-scenario-syntax/148419/2 "2008-09-12T18:02:30Z")

</div>

On Fri, Sep 12, 2008 at 10:35 AM, Evan David L.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> author(s).  
> rows in the FIT table. This seems more natural as the substitutions become  
> far clearer just by looking at the plain text.

Please keep in mind that this is an _additional_ way to do things -  
you can still write your steps exactly as you do in Story Runner,  
using regexps.

Cheers,  
David

---

<div class="post-metadata">

**Author:** ![elight](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/35a633/32.png) [@elight](https://www.ruby-forum.com/u/elight)\
**Post date:** [September 12, 2008, 6:05pm UTC](https://www.ruby-forum.com/t/cucumber-scenario-syntax/148419/3 "2008-09-12T18:05:25Z")

</div>

On Sep 12, 2008, at 11:51 AM, David C. wrote:

> Please keep in mind that this is an _additional_ way to do things -  
> you can still write your steps exactly as you do in Story Runner,  
> using regexps.

Ah, good point. I missed that nuance in your comment on my blog.

Perhaps the presence of the FIT table should alter Cucumber’s behavior  
WRT Scenario? This could allow the original Story Runner syntax to  
hold. However, it would also allow, in the presence of a FIT table,  
for a Scenario to serve as a template.

WDYT? (had to consider that acronym when I first saw it today).

Evan

---

<div class="post-metadata">

**Author:** ![elight](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/35a633/32.png) [@elight](https://www.ruby-forum.com/u/elight)\
**Post date:** [September 12, 2008, 6:06pm UTC](https://www.ruby-forum.com/t/cucumber-scenario-syntax/148419/4 "2008-09-12T18:06:36Z")

</div>

On Fri, Sep 12, 2008 at 10:35 AM, Evan David L.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> author(s).  
> rows in the FIT table. This seems more natural as the substitutions become  
> far clearer just by looking at the plain text.
> 
> Disclaimer: My exposure to FIT is limited to a quick read of Ward  
> Cunningham’s page on FIT and Cucumber.

I commented on your blog.

Cheers,  
David

---

<div class="post-metadata">

**Author:** ![elight](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/35a633/32.png) [@elight](https://www.ruby-forum.com/u/elight)\
**Post date:** [September 12, 2008, 6:15pm UTC](https://www.ruby-forum.com/t/cucumber-scenario-syntax/148419/5 "2008-09-12T18:15:24Z")

</div>

I agree. Seems much more useful to me to think of the first one as  
being a template that stuff gets plugged in to.

Pat

---

<div class="post-metadata">

**Author:** ![elight](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/35a633/32.png) [@elight](https://www.ruby-forum.com/u/elight)\
**Post date:** [September 12, 2008, 6:15pm UTC](https://www.ruby-forum.com/t/cucumber-scenario-syntax/148419/6 "2008-09-12T18:15:24Z")

</div>

On Fri, Sep 12, 2008 at 11:04 AM, Evan David L.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Scenario? This could allow the original Story Runner syntax to hold.  
> However, it would also allow, in the presence of a FIT table, for a  
> Scenario to serve as a template.

What you’re proposing might look this:

Scenario: division  
Given a numerator  
And a denominator  
Then the calculator should provide a quotient

|numerator|denominator|quotient|

This will put some constraints on the phrasing that might be a good  
thing, might not.

What if we just allowed free text in there that was not at all bound  
to the table:

Examples: division  
When you divide a numerator by a denominator,  
the calculator should provide the quotient.

|numerator|denominator|quotient|

WDYTAT?

---

<div class="post-metadata">

**Author:** ![elight](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/35a633/32.png) [@elight](https://www.ruby-forum.com/u/elight)\
**Post date:** [September 12, 2008, 6:17pm UTC](https://www.ruby-forum.com/t/cucumber-scenario-syntax/148419/7 "2008-09-12T18:17:45Z")

</div>

On Sep 12, 2008, at 11:50 AM, David C. wrote:

> I commented on your blog.

Yup, I know. I know very well who you are, David. 😉 I’ve seen you  
speak a few times and even chatted with you briefly outside RailsConf  
'08 about this crazy idea that I had to redo RSpec Plain Text Stories  
in Treetop. Then you told me that Aslak already did it. 😉

Evan

---

<div class="post-metadata">

**Author:** ![elight](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/35a633/32.png) [@elight](https://www.ruby-forum.com/u/elight)\
**Post date:** [September 12, 2008, 6:22pm UTC](https://www.ruby-forum.com/t/cucumber-scenario-syntax/148419/8 "2008-09-12T18:22:26Z")

</div>

On Sep 12, 2008, at 12:14 PM, David C. wrote:

> thing, might not.

I agree that my proposal is not necessarily the answer.

> What if we just allowed free text in there that was not at all bound  
> to the table:
> 
> Examples: division  
> When you divide a numerator by a denominator,  
> the calculator should provide the quotient.
> 
> |numerator|denominator|quotient|
> 
> WDYTAT?

I believe that binding the table to the phrasing would be immensely  
useful and perhaps even crucial to Scenario authors.

Also, couldn’t your second example also support binding to the table  
headers?

Evan

---

<div class="post-metadata">

**Author:** ![elight](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/35a633/32.png) [@elight](https://www.ruby-forum.com/u/elight)\
**Post date:** [September 12, 2008, 6:24pm UTC](https://www.ruby-forum.com/t/cucumber-scenario-syntax/148419/9 "2008-09-12T18:24:12Z")

</div>

On Fri, Sep 12, 2008 at 11:16 AM, Evan David L.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> On Sep 12, 2008, at 11:50 AM, David C. wrote:
> 
> > I commented on your blog.
> 
> Yup, I know. I know very well who you are, David. 😉 I’ve seen you speak  
> a few times and even chatted with you briefly outside RailsConf '08 about  
> this crazy idea that I had to redo RSpec Plain Text Stories in Treetop.  
> Then you told me that Aslak already did it. 😉

I remember you well from RailsConf and associated Werewolf games. I  
was really responding to try to keep the conversation in one place 🙂

Cheers,  
David

---

<div class="post-metadata">

**Author:** ![elight](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/35a633/32.png) [@elight](https://www.ruby-forum.com/u/elight)\
**Post date:** [September 12, 2008, 8:29pm UTC](https://www.ruby-forum.com/t/cucumber-scenario-syntax/148419/10 "2008-09-12T20:29:06Z")

</div>

On Fri, Sep 12, 2008 at 11:19 AM, Evan David L.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > |numerator|denominator|quotient|  
> > to the table:  
> > useful and perhaps even crucial to Scenario authors.  
> > Can you give an example of how this would be helpful?

> ```
> Also, couldn't your second example also support binding to the table
> 
> ```
> 
> headers?

Anything is possible 🙂 How would you envision that working. What  
would trigger binding one word in a phrase to a header?

---

<div class="post-metadata">

**Author:** ![elight](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/35a633/32.png) [@elight](https://www.ruby-forum.com/u/elight)\
**Post date:** [September 12, 2008, 9:10pm UTC](https://www.ruby-forum.com/t/cucumber-scenario-syntax/148419/11 "2008-09-12T21:10:50Z")

</div>

On Sep 12, 2008, at 12:26 PM, David C. wrote:

> > ```
> > I believe that binding the table to the phrasing would be  
> > 
> > ```
> > 
> > immensely  
> > useful and perhaps even crucial to Scenario authors.
> 
> Can you give an example of how this would be helpful?

I’ll try.

Let’s define a couple of roles for, the sake of discussion. Features  
are written in plain text by a “business person” or “domain expert”  
who is not a programmer and that the Steps are implemented by a “code  
monkey”.

I believe that code monkeys could be confused by the following:

Given a Widget  
When I supply a line of text that starts with a foo  
Then it should output bar

|type of widget|text\_input|result|  
|Widget2 |blech |foobar|

Looking at the Scenario above, I can’t tell, by reading the Given,  
When, or Then lines where “widget\_2”, “blech”, and “foobar” will be  
used respectively.

However, if I could say:

Given a type of widget  
When I supply a line of text that starts with my text input  
Then it should output the desired output

|type of widget|my text input|the desired output|  
…

I believe that the latter is a fair bit cleaner. Again, this approach  
would use the FIT table headers as metadata that informs the use of  
the Scenario as a template for running Scenarios.

To nitpick my suggestion just a tad, I wonder whether trimming the  
matched FIT column headers is a good idea or not; however, padding the  
FIT table headers with a little white space may also make them a  
little more readable.

Evan

---

<div class="post-metadata">

**Author:** ![elight](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/35a633/32.png) [@elight](https://www.ruby-forum.com/u/elight)\
**Post date:** [September 12, 2008, 8:29pm UTC](https://www.ruby-forum.com/t/cucumber-scenario-syntax/148419/12 "2008-09-12T20:29:41Z")

</div>

On Sep 12, 2008, at 12:19 PM, David C. wrote:

> > a few times and even chatted with you briefly outside RailsConf '08  
> > about  
> > this crazy idea that I had to redo RSpec Plain Text Stories in  
> > Treetop.  
> > Then you told me that Aslak already did it. 😉
> 
> I remember you well from RailsConf and associated Werewolf games

Hrm. You witnessed one of my crappier Werewolf games. Feel free to  
erase that memory at your convenience. 😉

> . I  
> was really responding to try to keep the conversation in one place 🙂

Roger roger. I’d rather have it here than on my blog as well. The  
more, the merrier.

---

<div class="post-metadata">

**Author:** ![elight](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/35a633/32.png) [@elight](https://www.ruby-forum.com/u/elight)\
**Post date:** [September 12, 2008, 10:01pm UTC](https://www.ruby-forum.com/t/cucumber-scenario-syntax/148419/13 "2008-09-12T22:01:43Z")

</div>

Evan David L. wrote:

> On Sep 12, 2008, at 12:26 PM, David C. wrote:
> 
> > > ```
> > > I believe that binding the table to the phrasing would be  
> > > 
> > > ```
> > > 
> > > immensely  
> > > useful and perhaps even crucial to Scenario authors.
> > 
> > Can you give an example of how this would be helpful?
> 
> I’ll try.
> 
> Let’s define a couple of roles for, the sake of discussion. Features  
> are written in plain text by a “business person” or “domain expert”  
> who is not a programmer and that the Steps are implemented by a “code  
> monkey”.
> 
> I believe that code monkeys could be confused by the following:
> 
> Given a Widget  
> When I supply a line of text that starts with a foo  
> Then it should output bar
> 
> |type of widget|text\_input|result|  
> |Widget2 |blech |foobar|
> 
> Looking at the Scenario above, I can’t tell, by reading the Given,  
> When, or Then lines where “widget\_2”, “blech”, and “foobar” will be  
> used respectively.
> 
> However, if I could say:
> 
> Given a type of widget  
> When I supply a line of text that starts with my text input  
> Then it should output the desired output
> 
> |type of widget|my text input|the desired output|  
> …
> 
> I believe that the latter is a fair bit cleaner. Again, this approach  
> would use the FIT table headers as metadata that informs the use of  
> the Scenario as a template for running Scenarios.
> 
> To nitpick my suggestion just a tad, I wonder whether trimming the  
> matched FIT column headers is a good idea or not; however, padding the  
> FIT table headers with a little white space may also make them a  
> little more readable.
> 
> Evan

Interesting idea. The problem I see is that the steps would have to  
bind:

> Given a type of widget  
> When I supply a line of text that starts with my text input  
> Then it should output the desired output

Given(‘a type of widget’) do  
…  
end

But you would want values given by your FIT table.

Given(/a .+/) do |widget|  
…  
end

So now you have a Scenario in plain text which is never run though it  
matches the Given step, unlike any other scenario not using FIT.

So far in Cucumber the first scenario is executable, the following FIT  
values run the scenario with the different values. In terms of  
consistency and matching plain text to steps it feels like header  
matchers complicate things.

I agree there is difficulty with FIT values and bindings. I find using  
good descriptive columns names really helps and quoting bound values in  
the plain text. I find this much easier to match up:

Given a ‘Widget’  
When I supply a line of text that starts with a ‘foo’  
Then it should output ‘bar’

But as you said it still leaves some instances where its confusing. I’m  
also playing with a tool I’ve written to allow business people to edit  
FIT values in cucumber through a web interface. I’m starting to feel  
that I’m happy writing plain text features/scenarios but FIT tables are  
the sort of thing I would really rather do through a FITness style wiki.

If quotes are a pain perhaps this is something that could be combated by  
IDEs and a clever syntax highlighting plugin (using colour maybe)?

–  
Joseph W.  
[http://www.joesniff.co.uk](http://www.joesniff.co.uk)

---

<div class="post-metadata">

**Author:** ![elight](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/35a633/32.png) [@elight](https://www.ruby-forum.com/u/elight)\
**Post date:** [September 18, 2008, 8:12am UTC](https://www.ruby-forum.com/t/cucumber-scenario-syntax/148419/14 "2008-09-18T08:12:04Z")

</div>

On Sep 12, 2008, at 4:01 PM, Joseph W. wrote:

> > I’ll try.  
> > Then it should output bar  
> > Given a type of widget
> 
> Given(/a .+/) do |widget|
> 
> I’m
> 
> ## – Joseph W. [http://www.joesniff.co.uk](http://www.joesniff.co.uk)
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> * * *
> 
> rspec-users mailing list  
> [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> [http://rubyforge.org/mailman/listinfo/rspec-users](http://rubyforge.org/mailman/listinfo/rspec-users)

I’d be happy to see variable substitutions occur in the plain text,  
before they even get to the step code. For example

```
Given a [type of widget]
When I supply a line of text that starts with [my text input]
Then it should output [the desired output]

 | type of widget | my text input | the desired output |
 | widget1 | foo |

```

bar |

Also then table variables can be used in multiple steps

```
 And there should be a link with text [type of widget]
 And an email should be generated with subject [the desired output]

```

etc

Perhaps that’s less “plain text” than you like, but it would be  
mighty useful 🙂

linoj

---

<div class="post-metadata">

**Author:** ![elight](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/35a633/32.png) [@elight](https://www.ruby-forum.com/u/elight)\
**Post date:** [September 12, 2008, 11:50pm UTC](https://www.ruby-forum.com/t/cucumber-scenario-syntax/148419/15 "2008-09-12T23:50:00Z")

</div>

On Sep 12, 2008, at 4:01 PM, Joseph W. wrote:

> I agree there is difficulty with FIT values and bindings. I find using  
> good descriptive columns names really helps

Couldn’t agree more there.

> and quoting bound values in  
> the plain text. I find this much easier to match up:
> 
> Given a ‘Widget’  
> When I supply a line of text that starts with a ‘foo’  
> Then it should output ‘bar’

This is a clever hack around a current weakness in Cucumber. I really  
like it. However, it would sit better with me if Cucumber enforced  
that syntax.

---

<div class="post-metadata">

**Author:** ![elight](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/35a633/32.png) [@elight](https://www.ruby-forum.com/u/elight)\
**Post date:** [February 27, 2010, 5:50am UTC](https://www.ruby-forum.com/t/cucumber-scenario-syntax/148419/16 "2010-02-27T05:50:06Z")

</div>

Hi,

Searched for this everywhere, so here goes.

I am having trouble matching multiline strings with leading whitespace  
in them using the “”" operator.

E.g.  
Then the output should be  
“”"  
Usage:  
mygem [options] destination  
Template Options:  
-r, --ruby install the ruby template  
–ruby-19 install the ruby-19 template  
General options:  
-f, --force force overwriting files, don’t ask  
-s, --skip skip file if it exists  
-q, --quiet runs quietly, no output  
-V, --verbose Show lots of output  
-v, --version Show this version  
-p, --pretend dry run, show what would have  
happened  
-x, --debug Show debugging output  
-h, --help Show this help  
“”"

I am generating this (almost) t am I doing wrongexact output with 5  
leading space before the options, but the expected string is  
collapsing them down to one leading space:  
Diff:

```
  @@ -1,15 +1,14 @@
  +Ok
  +
   Usage:
   mygem [options] destination
  -Template Options:
  - -r, --ruby install the ruby template
  - --ruby-19 install the ruby-19 template
   General options:
  - -f, --force force overwriting files, don't 

```

ask  
- -s, --skip skip file if it exists  
- -q, --quiet runs quietly, no output  
- -V, --verbose Show lots of output  
- -v, --version Show this version  
- -p, --pretend dry run, show what would have  
happened  
- -x, --debug Show debugging output  
- -h, --help Show this help  
+ -f, --force force overwriting files,  
don’t ask  
+ -s, --skip skip file if it exists  
+ -q, --quiet runs quietly, no output  
+ -V, --verbose Show lots of output  
+ -v, --version Show this version  
+ -p, --pretend dry run, show what would  
have happened  
+ -x, --debug Show debugging output  
+ -h, --help Show this help

What am I doing wrong?

Thanks

Cheers,  
Ed

Ed Howland

> **[Green Programming - Blogging about Ruby, jQuery and Beyond!](https://greenprogrammer.wordpress.com/)**
>
> Just another WordPress.com weblog

[http://twitter.com/ed\_howland](http://twitter.com/ed_howland)

---

<div class="post-metadata">

**Author:** ![elight](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/35a633/32.png) [@elight](https://www.ruby-forum.com/u/elight)\
**Post date:** [September 18, 2008, 11:56am UTC](https://www.ruby-forum.com/t/cucumber-scenario-syntax/148419/17 "2008-09-18T11:56:49Z")

</div>

Hi all,

We’re using Cucumber here at [songkick.com](http://songkick.com) and it’s working really well  
for us. I’ve created a  
branch here with some extra features that we needed:  
[Commits · songkick/cucumber · GitHub](http://github.com/songkick/cucumber/commits/master)

Specifically, we’ve made the transactional fixtures optional in Rails  
(necessary for when running  
with Firewatir) and removed the Rails and Cucumber portions of the  
backtrace in errors.

Feel free to make use of these changes if they can be useful.

best,  
Dan

---

<div class="post-metadata">

**Author:** ![elight](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/35a633/32.png) [@elight](https://www.ruby-forum.com/u/elight)\
**Post date:** [February 27, 2010, 10:47am UTC](https://www.ruby-forum.com/t/cucumber-scenario-syntax/148419/18 "2010-02-27T10:47:22Z")

</div>

On Sat, Feb 27, 2010 at 5:17 AM, Ed Howland [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> Hi,
> 
> Searched for this everywhere, so here goes.
> 
> I am having trouble matching multiline strings with leading whitespace  
> in them using the “”" operator.

Cucumber intentionally removes all the space characters left of the  
leftmost  
triple quote.  
Just indent everything relative to the leftmost triple quote and you’ll  
be  
ok.

Aslak
