Testing a wizard with Cucumber


#1

Assuming you have a multi-step wizard like thing, with lots of different
states and paths through it. What approach would your use to write a
feature
for it? What I want to do is do the separate states and then reuse these
things in more complex scenarios that cover paths. For example
Scenario: State A
Given I’m …
And I’m …
When I …
Then I should see
And I at state A

Now I’d like to reuse this to make my scenario from going from A to B
shorter e.g

Scenario: Test A to B
Given State A
When I …

Instead of

Scenario: Test A to B
Given I’m …
And I’m …
When I …
Then I should see
And I at state A
When I …

Is this possible? Do you have any other pointers about simplifying and
organising complex scenarios? Thanks in advance…


#2

On 4 Nov 2008, at 15:41, Andrew P. wrote:

Then I should see

Is this possible? Do you have any other pointers about simplifying
and organising complex scenarios? Thanks in advance…

There’s a relatively new (and possibly undocumented) feature in
cucumber[1] where you can call steps from within other steps.

So for example, you can have one scenario like this:

 Scenario: Log in as admin

Given I visit the login page
And I enter the username “matt”
And I enter the password “secret”
And I press “Submit”
Then I should be on the admin page

And another one like this:
Scenario: View admin reports
Given I log in as admin
And I view the reports page
Then I should see “reports”

When you write the ruby step matcher for the first step in this
scenario, you just call the step matchers that you wrote for the first
scenario, like this:

Given /I log in as admin/ do
Given “I visit the login page”
Given ‘I enter the username “matt”’
Given ‘I enter the password “secret”’
Given ‘I press “Submit”’
end

Does that make sense? Does it help?

cheers,
Matt

[1]http://rspec.lighthouseapp.com/projects/16211/tickets/3-create-givenscenario-dependency-accross-feature-files


#3

Thanks Matt, just what I was looking for :slight_smile:
Andrew

2008/11/4 Matt W. removed_email_address@domain.invalid


#4

Andrew P. wrote:

Thanks Matt, just what I was looking for :slight_smile:

Andrew

You could also use GivenScenario. It works like this:

Scenario: State A
Given I’m …
And I’m …
When I …
Then I should see
And I at state A

Scenario: Test A to B
GivenScenario A
When I …

Or you could do a combination of this approach and what Matt suggested.
Meaning, you could make a more descriptive “Given” step that simply
calls the “GivenScenario State A” internally. Make sense?

HTH,
Ben


#5

On 4 Nov 2008, at 17:42, Ben M. wrote:

Andrew P. wrote:

Thanks Matt, just what I was looking for :slight_smile:

Andrew

You could also use GivenScenario.

Dude, that is soooo “Story Runner”.

:wink:


#6

On Nov 04, 2008, at 6:18 pm, Matt W. wrote:

You could also use GivenScenario.

Dude, that is soooo “Story Runner”.

And soooo deprecated too, right?


http://www.patchspace.co.uk/


#7

Ashley M. wrote:

On Nov 04, 2008, at 6:18 pm, Matt W. wrote:

You could also use GivenScenario.

Dude, that is soooo “Story Runner”.

And soooo deprecated too, right?

Oh really? Hmm… I assumed it was still there. :slight_smile:

-Ben


#8

On Nov 04, 2008, at 7:28 pm, Ben M. wrote:

Oh really? Hmm… I assumed it was still there. :slight_smile:

Search for Aslak’s comments, I’m pretty sure it will be pulled in
Cucumber 0.3.

Calling steps is much neater from inside other steps is much neater,
and doesn’t produce the visible step-explosion you get with
GivenScenario.

Ashley


http://www.patchspace.co.uk/


#9

Its still there in source.

You can read why people felt calling steps from steps was a better
approach
here:
http://rspec.lighthouseapp.com/projects/16211/tickets/3-create-givenscenario-dependency-accross-feature-files


Joseph W.
http://www.joesniff.co.uk