On Wed, Jul 11, 2012 at 3:37 PM, Matthew Fremont
<
mfre...@springpartners.com> wrote:
> As a newcomer to Cucumber, I'm trying to understand whether scenarios within
> the same feature should be written and implemented with the expectation that
> scenarios are executed independently. Specifically, I want to understand
> whether to expect that data created/modified by one scenario is visible to
> another scenario or each scenario starts with no lingering data from a prior
> scenario.
I had this question a while back, and have generally come to the
decision that a good practice is to let each scenario express and
populate its starting state. I don't know best practices for clean up,
but I sometimes clean up my scenarios by adding annotations that will
execute clean-up code. For example, if a scenario creates directories,
and I add a @creates_directories annotation to it, I would have an
AfterStep hook tied to the annotation that would delete any new
directories. This is nice because it doesn't pollute the scenario
description.
Here is a pretty in depth thread from my asking of this question:
https://groups.google.com/forum/#!msg/cukes/RpVRa3-cBfM/ljnhKQo_nMwJ
>
> For example, in the first actual project feature I'm trying to implement
> with Cucumber I have several overlapping "Given" clauses:
>
> Scenario: like a comment
> Given the user X
> When user X likes a page
> ...
>
> Scenario: create a comment
> Given the user X
> When user X creates a comment
> ...
>
> From what I've been able to determine, a feature with scenarios like my
> example will result in the "Given the user X" step being executed twice.
While this is still executed per scenario, you may find "Scenario
Background", another Cucumber feature to be useful.
>
> Should I be writing the step def for the Given in a way that assumes that
> the user may have been created by the step def being executed for a prior
> scenario?
>
> Similarly, should the When and Then step defs be written to presume that
> they could be executing in a context where the data may have been modified
> by another scenario in the same feature?
>
> Are scenarios always executed in the order in which they appear in the
> feature file?
>
> From my newcomer's perspective, I'd think that it would be desirable to
> write and implement scenarios which assume independence, since that removes
> any dependency on execution order and make the outcome of the specification
> deterministic, but I'm open to consider other points of view.
>
>
> Thanks,
>
> Matthew
>
>
>
>
>
> -- Rules --
>
> 1) Please prefix the subject with [Ruby], [JVM] or [JS].
> 2) Please use interleaved answers
>
http://en.wikipedia.org/wiki/Posting_style#Interleaved_style
> 3) If you have a question, don't reply to an existing message. Start a new
> topic instead.
>
> You received this message because you are subscribed to the Google Groups
> Cukes group. To post to this group, send email to
cu...@googlegroups.com. To
> unsubscribe from this group, send email to
>
cukes+un...@googlegroups.com. For more options, visit this group at
>
https://groups.google.com/d/forum/cukes?hl=en
--
Steve