Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NBehave.Narrator.Framework.Hooks.BeforeScenario is not picked up #13

Open
muxa opened this issue Oct 23, 2013 · 5 comments
Open

NBehave.Narrator.Framework.Hooks.BeforeScenario is not picked up #13

muxa opened this issue Oct 23, 2013 · 5 comments

Comments

@muxa
Copy link

muxa commented Oct 23, 2013

When i use NBehave.Narrator.Framework.BeforeScenario the method is executed, but not when i use NBehave.Narrator.Framework.Hooks.BeforeScenario.

This is via command runner.

@MorganPersson
Copy link
Member

If you could give me a repro it would be awesome because what I tried worked as intended.

Here is the code i used:

    [ActionSteps, Hooks]
    public class Steps
    {
        private static List<string> events = new List<string>();

        [Given("text $nr")]
        [When("action $nr")]
        [Then("stuff $nr")]
        public void Something(int nr)
        {
        }

        [Given("a background")]
        public void Bg()
        {
            events.Add("Background Step");
        }

        [NBehave.Narrator.Framework.Hooks.BeforeRun]
        public void BeforeRun() { events.Add("BeforeRun"); }

        [NBehave.Narrator.Framework.Hooks.AfterRun]
        public void AfterRun()
        {
            events.Add("AfterRun");
            Console.WriteLine("=== Events triggered\n{0}", string.Join("\n", events));
        }

        [NBehave.Narrator.Framework.Hooks.BeforeFeature]
        public void BeforeFeature() { events.Add("BeforeFeature"); }
        [NBehave.Narrator.Framework.Hooks.AfterFeature]
        public void AfterFeature() { events.Add("AfterFeature"); }
        [NBehave.Narrator.Framework.Hooks.BeforeScenario]
        public void BeforeScenario() { events.Add("BeforeScenario"); }
        [NBehave.Narrator.Framework.Hooks.AfterScenario]
        public void AfterScenario() { events.Add("AfterScenario"); }
        [NBehave.Narrator.Framework.Hooks.BeforeStep]
        public void BeforeStep() { events.Add("BeforeStep"); }
        [NBehave.Narrator.Framework.Hooks.AfterStep]
        public void AfterStep() { events.Add("AfterStep"); }
    }

feature file:

Feature: title

Background: can have title
    Given a background

Scenario: title
    Given text 1
    When action 1
    Then stuff 1

@gilescope
Copy link

This happens because now a HooksAttribute is required as well as an ActionStepsAttribute. Previously this additional attribute wasn't required at the class level.

@gilescope
Copy link

That said there is definitely a bug here. Using the embeddedrunner, executetext, it instanciates the helper class twice, once when calling the hooks (methodhookmetadata.methodhookmetadata) and then again in actionstateparser.findactionstatemethods. It seems the instance that got tested was a different instance to the one the BeforeScenario hook was executed on.

@gilescope
Copy link

Scratch that, there's no bug. The double instantiation is to ensure you're using ScenarioContext.Current for your state rather than instance variables in your helper class. Also I note that parameter names in the step functions must now match the $ name. All good changes - just trip people up who are upgrading old tests.

@MorganPersson
Copy link
Member

The double instancing doesn't sound lso great. Maybe someone should fix that :-)
And the parameter names must match, I can't recall doing that on purpose either.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants