[rspec-users] Testing a wizard with Cucumber
Matt Wynne
matt at mattwynne.net
Tue Nov 4 11:29:30 EST 2008
On 4 Nov 2008, at 15:41, Andrew Premdas wrote:
> 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...
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
More information about the rspec-users
mailing list