Hi,

given stories are treated as independent stories, as far the before/after annotations go. We could introduce an optional flag that would distinguish between methods that are executed only for given stories. But this would not solve all the issues you may have. I think there is a glass ceiling in using the before/after annotations if you're trying to execute repeated behaviour. I find that often using explicit steps, possibly abstracted in a setup story that you can invoke via GivenStories may be a better practice than using a @BeforeStory annotated method. Remember that the annotated before/after methods are not visible to the story writers so they should be used with care. Also, the before/after annotated methods are collected and executed all together so it's at present not at all easy to correlate one against the other, nor is it possible to pass parameters. For that, parametrised steps in scenarios are better. Amongst other things, you can use meta parameters to tag a story as a given story and adapt the behaviour accordingly.

Alternatively, you may try to keep state in your @BeforeStory implementation class using the @AfterStory as well to determine if you're running a given story or not.

Hope this helps. If you want to provide more details on your specific scenario, perhaps we can provide a more specific solution.

Cheers

On 02/08/2012 10:06, Ádám Csordás wrote:
Hi,
I have created a story that has GivenStories block with two stories. Both given story has a method annotated with BeforeStory. When the main story runs both BeforeStory method is called before each given story, which cause me a problem. Also I think it is not the expected behavior in this case. Dose anybody have a solution for this? Thanks in advance.
Br,
Adam

Reply via email to