Skip to content

Hooks for Scenario Outlines don't work #210

Closed
gisode opened this Issue Feb 17, 2012 · 2 comments

2 participants

@gisode
gisode commented Feb 17, 2012

Given a Scenario Outline with some Examples.
And a @Before hook matching the tag @tag

Given I add @tag to the Scenario Outline like so:

@tag 
Scenario Outline: Foo
    ...

    Examples:
        ...

When I run it
Then the before-hook is NOT executed.

After digging in the code I found that it should work when @tag is added like so:

Scenario Outline: Foo
    ...

    @tag 
    Examples:
        ...

But it doesn't either and here is why:

When the FeatureBuilder.examples() method is given the Gherkin Examples object containing the correctly parsed tag, it simply passes the reference to it into the current CucumberScenarioOutline which builds a new CucumberExamples instance that in turn simply stores the reference.

Later in CucumberExamples.createExampleScenarios() the tags are taken from the same Gherkin Examples instance whose reference was stored earlier and put into the newly created scenario for the current example. At that point, however, the List within the Gherkin Examples object containing the tags is empty, because that List is cleared in gherkin.formatter.FilterFormatter.replay() (examplesTags.clear(); currently at line 189).

The bug here is that Gherkin passes an object into the Formatter implementation - the FeatureBuilder - even though it is going to modify it later. Or that FeatureBuilder isn't prudent enough to make a copy of all objects that it is given.

I can't see how this can be fixed easily. For the project I use this in I guess I'll have FeatureBuilder make a copy of the Examples object, which is an ugly hack, oh well.

As an aside, I find it confusing that the tags must be added to the Examples section. I had expected that the example scenarios created at runtime would inherit all the tags from the Scenario Outline.

@gisode
gisode commented Feb 17, 2012

Whoops, seems this is a duplicate of #209. Didn't see that one until now. Sorry.

@aslakhellesoy
Cucumber member

Np - closing this. Your comments are valuable in fixing #209 anyway!

@gisode gisode pushed a commit to gisode/cucumber-jvm that referenced this issue Feb 21, 2012
@aslakhellesoy aslakhellesoy Fix tagged hooks for scenario outlines. Closes #209, closes #210 45d06e2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.