[RUBY] why --name uses just first line of scenario's name

108 views
Skip to first unread message

Oleg Sukhodolsky

unread,
Jan 23, 2013, 2:04:36 PM1/23/13
to cu...@googlegroups.com
Hi,

I'm working on RubyMine and RM allows use to run the specific scenario (we use --name for this).
Usually it works well but we have problems with scenarios which have multiline name.
E.g. we have the following scenario:

  Scenario: line1.
    line2.
  Given something
  And something else
  Then I've got something new

And we want to execute only this scenario so we're using --name param of cucumber's cli
Now the question: what is the name of the scenario?

By the output I've got from a regular run it look like the name is a multiline name.
If I've added before hook to print the name 
Before do |scenario|
end
and it prints "line1.\nline2." as the scenario name.
But if I run "cucumber <feature-file> --name "line1.\nline2."" cucumber finds no scenario.
After some debugging I've found that cucumber converts the string I've passed to regexp (which is used by Gherkin::Formatter::RegexpFilter)
but this filter is matched against first line of a scenario name only. And so the correct value for --name should be "line1.".

Is the behavior I see correct or it is a bug? How user is supposed to run scenario with multiline name?

Thanks in advance, Oleg.

Scott Smith

unread,
Jan 23, 2013, 3:24:06 PM1/23/13
to cu...@googlegroups.com
I may be off here, but my understanding is that the scenario name is just that, a name, and should be short enough to fit on one line.  More details, if necessary can go into comments within the scenario.

So, my suggestion is that your scenario naming is a code/test smell.

--
-- Rules --
 
1) Please prefix the subject with [Ruby], [JVM] or [JS].
2) Please use interleaved answers http://en.wikipedia.org/wiki/Posting_style#Interleaved_style
3) If you have a question, don't reply to an existing message. Start a new topic instead.
 
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 https://groups.google.com/d/forum/cukes?hl=en
 
 



--
Scott Smith

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

Tim Walker

unread,
Jan 23, 2013, 3:58:10 PM1/23/13
to cu...@googlegroups.com
Better yet, use a tag.

Tim

Oleg Sukhodolsky

unread,
Jan 23, 2013, 11:08:23 PM1/23/13
to cu...@googlegroups.com
Tag seldom can be used to run just one scenario :(

Oleg.

Oleg Sukhodolsky

unread,
Jan 23, 2013, 11:10:37 PM1/23/13
to cu...@googlegroups.com
I could agree that multi-line scenario name is a bad idea (though I'm sure some people will be disagree),
but this is doesn't explain the behavior I see (long name is reported, but short one is used for filtering)

Oleg.

Aslak Hellesøy

unread,
Jan 24, 2013, 4:30:35 AM1/24/13
to Cukes


On Jan 23, 7:04 pm, Oleg Sukhodolsky <os97...@gmail.com> wrote:
> Hi,
>
> I'm working on RubyMine and RM allows use to run the specific scenario (we
> use --name for this).
> Usually it works well but we have problems with scenarios which have
> multiline name.
> E.g. we have the following scenario:
>
>   Scenario: line1.
>     line2.
>   Given something
>   And something else
>   Then I've got something new
>
> And we want to execute only this scenario so we're using --name param of
> cucumber's cli
> Now the question: what is the name of the scenario?
>

In your example above, the scenario's _name_ is line_1. and the
scenario's _description_ is line2.

Feature/Scenario/Step names are always only one line. It's the text
immediately following the keyword until the end of line.

The --name option only matches against the name (and not the
description) because we thought that would be sufficient at the time.
It would be possible to change this, but it would be a little counter-
intuitive if --name matched against both name and description.

Aslak

Tim Walker

unread,
Jan 24, 2013, 9:45:18 AM1/24/13
to cu...@googlegroups.com
I hear ya and it may not be optimal but I do this (annotate a single
scenario with a tag) all the time. The next tool I'd reach for is the
scenario line number, before using the name, but that's my own
quirkiness I suppose. We have a series of tags to denote states in
progress and a few junit runners to accomodate the development phases,
which works out just fine for us. But, as others have mentioned there
are two fields at play, name and description.

Tim

Oleg Sukhodolsky

unread,
Jan 24, 2013, 1:27:12 PM1/24/13
to cu...@googlegroups.com
On Thu, Jan 24, 2013 at 1:30 PM, Aslak Hellesøy <aslak.h...@gmail.com> wrote:
On Jan 23, 7:04 pm, Oleg Sukhodolsky <os97...@gmail.com> wrote:
> Hi,
>
> I'm working on RubyMine and RM allows use to run the specific scenario (we
> use --name for this).
> Usually it works well but we have problems with scenarios which have
> multiline name.
> E.g. we have the following scenario:
>
>   Scenario: line1.
>     line2.
>   Given something
>   And something else
>   Then I've got something new
>
> And we want to execute only this scenario so we're using --name param of
> cucumber's cli
> Now the question: what is the name of the scenario?
>

In your example above, the scenario's _name_ is line_1. and the
scenario's _description_ is line2.

Feature/Scenario/Step names are always only one line. It's the text
immediately following the keyword until the end of line.

thank you for information. 

The --name option only matches against the name (and not the
description) because we thought that would be sufficient at the time.
It would be possible to change this, but it would be a little counter-
intuitive if --name matched against both name and description.

agree.

Just one little thing bother me: why scenario.name in Before hook contains multiline string?

Regards, Oleg.


Aslak

> By the output I've got from a regular run it look like the name is a
> multiline name.
> If I've added before hook to print the name
> Before do |scenario|
>   p [scenario.name]
> end
> and it prints "line1.\nline2." as the scenario name.
> But if I run "cucumber <feature-file> --name "line1.\nline2."" cucumber
> finds no scenario.
> After some debugging I've found that cucumber converts the string I've
> passed to regexp (which is used by Gherkin::Formatter::RegexpFilter)
> but this filter is matched against first line of a scenario name only. And
> so the correct value for --name should be "line1.".
>
> Is the behavior I see correct or it is a bug? How user is supposed to run
> scenario with multiline name?
>
> Thanks in advance, Oleg.

Matt Wynne

unread,
Jan 24, 2013, 2:30:01 PM1/24/13
to cu...@googlegroups.com
On 23 Jan 2013, at 20:24, Scott Smith <scottnel...@gmail.com> wrote:

I may be off here, but my understanding is that the scenario name is just that, a name, and should be short enough to fit on one line.  More details, if necessary can go into comments within the scenario.

The way it's parsed into Gherkin:

Scenario: <scenario name>
  <scenario description, which
  can span mutiple lines>
  Given <step name>
  When <step name>
  Then <step name>

The scenario name what's on the same line as the keyword.

Matt Wynne

unread,
Jan 25, 2013, 1:42:56 AM1/25/13
to cu...@googlegroups.com
That's a bug. Could you please raise a ticket for it in the issue tracker?

Oleg Sukhodolsky

unread,
Jan 25, 2013, 2:04:31 PM1/25/13
to cu...@googlegroups.com
Hmm.  Before filing the ticket I've read the code and found that method name which is available in Scenario and ScenarioOutline is implemented
in Cucumber::Ast::Names (https://github.com/cucumber/cucumber/blob/master/lib/cucumber/ast/names.rb) as concatenation of title and description.
So, now I'm not sure that this is a bug, I just check wrong property :(  Though it is not very intuitive that "--name" checks titles ;)
Perhaps it is better just improve documentation for the option?  What do you think?

Regards, Oleg.

Matt Wynne

unread,
Jan 25, 2013, 6:25:56 PM1/25/13
to cu...@googlegroups.com
I think it's a bug.

In the underlying Gherkin library, there is a name and a description. There's no such thing as a title. This code needs to be fixed.

Oleg Sukhodolsky

unread,
Jan 26, 2013, 1:35:42 AM1/26/13
to cu...@googlegroups.com

Regards, Oleg.

Александр Позитивин

unread,
Feb 1, 2013, 11:01:46 AM2/1/13
to cu...@googlegroups.com
Great, thank you, Oleg :)

суббота, 26 января 2013 г., 10:35:42 UTC+4 пользователь Oleg Sukhodolsky написал:
Reply all
Reply to author
Forward
0 new messages