cucumber/cucumber-jvm — Issue #210: Hooks for Scenario Outlines don't work
Author: gisode
Created: 2012-02-17 14:15:40+00:00
State: open

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.