From: Jonatas Paganini on
Hi, I'm trying to use scenario outline, but I have some steps that I
want to execute once before start steps with < >.

Scenario Outline: Execute Steps
Given some steps that I want to run once
When...
Then...

Given <step> like <description>
Example:
| step | description |
| 1 | first |
| 2 | second |



I want to execute Given, When and Then once before start with Scenario
Outline Iterator. This steps are running for each row. How can I create
a subscenario or something like that?

There's a way to do it?
--
Posted via http://www.ruby-forum.com/.

From: Jacob Mitchell on
[Note: parts of this message were removed to make it a legal post.]

On Thu, Jan 14, 2010 at 1:08 PM, Jonatas Paganini <jonatasdp(a)gmail.com>wrote:

> Hi, I'm trying to use scenario outline, but I have some steps that I
> want to execute once before start steps with < >.
>
> Scenario Outline: Execute Steps
> Given some steps that I want to run once
> When...
> Then...
>
> Given <step> like <description>
> Example:
> | step | description |
> | 1 | first |
> | 2 | second |
>
>
>
> I want to execute Given, When and Then once before start with Scenario
> Outline Iterator. This steps are running for each row. How can I create
> a subscenario or something like that?
>

Do you have a concrete example? That would make it easier to find a good
solution.

>
> There's a way to do it?
>

Here are some approaches that might be worth looking into.

Given-When-Then statements are functions that can call each other. Have a
look at this example (
http://wiki.github.com/aslakhellesoy/cucumber/calling-steps-from-step-definitions)
to see what I mean. When calling steps from a step definition, it's a good
idea to keep the step types consistent. In other words, avoid calling a
Then statement from a Given statement definition. Compound steps may not be
what you need because they will run once for each iteration of the Scenario
Outline.

If you want a set of Givens to run only once for the entire Scenario
Outline, use Background (
http://wiki.github.com/aslakhellesoy/cucumber/background). The potential
downside here is Background statements are run before each Scenario
(Outline) in the Feature, thereby restricting the Scenarios you can use in
the Feature.

Lastly, take a look at Tagged Hooks (
http://wiki.github.com/aslakhellesoy/cucumber/hooks). These can be used if
you want some Ruby code to run before (or after) every Scenario with a
particular tag. A big downside here is there's no indication, aside from
the tag, that additional Ruby code is running. You can get the same effect
using a Given statement, which is certainly clearer than a Hook.

> --
> Posted via http://www.ruby-forum.com/.
>
>

From: Jonatas Paganini on
Thanks Jacob!
Excelent explanation!
I think that Background do exactly what I want. :D
--
Posted via http://www.ruby-forum.com/.