Repository: cucumber/cucumber-jvm

Issue #209: Scneario Outlines appear to ignore tagged hooks
Created: 2012-02-17T02:58:30Z
I've attempted to use a tagged hook within a given step definition class and then reused one of the Given steps contained in the same class as the tagged hook across 2 feature files.  I've tagged a Scenario outline expecting to see the Before hook called prior to executing the Given step, but this does not appear to be happening.
It's a bit difficult to explain.  Please see the public gist I've shared at https://gist.github.com/1850089 for the feature files and accompanying step definition classes, along with what I would expect the outcome to be and what the actual result is.
First feature file
@feature_1
Feature: Feature one

    Scenario: A 
        Given a step in A
        When an action in A
        Then the expected outcome is X

    @feature_2
    Scenario Outline: B
        Given a step in C
        When an action in B
        Then the outline's expected outcome is <result>

        Examples:
        | result |
        | Y      |
        | W      |
Second feature file
Feature: Feature 2

    @feature_2
    Scenario: C
        Given a step in C
        When an action in C
        Then the expected outcome is Z
EXPECTED OUTPUT
[class org.stag.hello.StepDefsForFeature_1]: Inside GIVEN step A
[class org.stag.hello.StepDefsForFeature_1]: Inside WHEN step A
[class org.stag.hello.StepDefsForFeature_1]: Inside THEN step X
[class org.stag.hello.StepDefsForFeature_2]: Inside tagged BEFORE hook -- tag = @feature_2
[class org.stag.hello.StepDefsForFeature_2]: Inside GIVEN step C
[class org.stag.hello.StepDefsForFeature_1]: Inside WHEN step B
[class org.stag.hello.StepDefsForFeature_1]: Inside THEN step Y
[class org.stag.hello.StepDefsForFeature_2]: Inside tagged BEFORE hook -- tag = @feature_2
[class org.stag.hello.StepDefsForFeature_2]: Inside GIVEN step C
[class org.stag.hello.StepDefsForFeature_1]: Inside WHEN step B
[class org.stag.hello.StepDefsForFeature_1]: Inside THEN step W
[class org.stag.hello.StepDefsForFeature_2]: Inside tagged BEFORE hook -- tag = @feature_2
[class org.stag.hello.StepDefsForFeature_2]: Inside GIVEN step C
[class org.stag.hello.StepDefsForFeature_2]: Inside WHEN step C
[class org.stag.hello.StepDefsForFeature_2]: Inside THEN step Z

ACTUAL OUTPUT
[class org.stag.hello.StepDefsForFeature_1]: Inside GIVEN step A
[class org.stag.hello.StepDefsForFeature_1]: Inside WHEN step A
[class org.stag.hello.StepDefsForFeature_1]: Inside THEN step X
[class org.stag.hello.StepDefsForFeature_2]: Inside GIVEN step C
[class org.stag.hello.StepDefsForFeature_1]: Inside WHEN step B
[class org.stag.hello.StepDefsForFeature_1]: Inside THEN step Y
[class org.stag.hello.StepDefsForFeature_2]: Inside GIVEN step C
[class org.stag.hello.StepDefsForFeature_1]: Inside WHEN step B
[class org.stag.hello.StepDefsForFeature_1]: Inside THEN step W
[class org.stag.hello.StepDefsForFeature_2]: Inside tagged BEFORE hook -- tag = @feature_2
[class org.stag.hello.StepDefsForFeature_2]: Inside GIVEN step C
[class org.stag.hello.StepDefsForFeature_2]: Inside WHEN step C
[class org.stag.hello.StepDefsForFeature_2]: Inside THEN step Z

Duplicate issue #210: Hooks for Scenario Outlines don't work
Created: 2012-02-17T14:15:40Z
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.

Closing comment (2012-02-17T15:43:17Z): Whoops, seems this is a duplicate of #209. Didn't see that one until now. Sorry.