Forum: RSpec Testing a wizard with Cucumber

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
85d99e7678d8720f6e00ab0f60fe6ea9?d=identicon&s=25 Andrew Premdas (Guest)
on 2008-11-04 16:43
(Received via mailing list)
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...
Cdf378de2284d8acf137122e541caa28?d=identicon&s=25 Matt Wynne (mattwynne)
on 2008-11-04 17:31
(Received via mailing list)
On 4 Nov 2008, at 15:41, Andrew Premdas 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/tick...
85d99e7678d8720f6e00ab0f60fe6ea9?d=identicon&s=25 Andrew Premdas (Guest)
on 2008-11-04 17:55
(Received via mailing list)
Thanks Matt, just what I was looking for :)
Andrew

2008/11/4 Matt Wynne <matt@mattwynne.net>
C694a032be7518a0d704318895f8fe1d?d=identicon&s=25 Ben Mabey (mabes)
on 2008-11-04 19:11
(Received via mailing list)
Andrew Premdas wrote:
> Thanks Matt, just what I was looking for :)
>
> 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
Cdf378de2284d8acf137122e541caa28?d=identicon&s=25 Matt Wynne (mattwynne)
on 2008-11-04 19:31
(Received via mailing list)
On 4 Nov 2008, at 17:42, Ben Mabey wrote:

> Andrew Premdas wrote:
>> Thanks Matt, just what I was looking for :)
>>
>> Andrew
>
> You could also use GivenScenario.

Dude, that is soooo "Story Runner".

;)
2ce9c0106b5851b2294ba5eb9f5c04bd?d=identicon&s=25 Ashley Moran (Guest)
on 2008-11-04 20:26
(Received via mailing list)
On Nov 04, 2008, at 6:18 pm, Matt Wynne wrote:

>> You could also use GivenScenario.
>
> Dude, that is soooo "Story Runner".


And soooo deprecated too, right?

--
http://www.patchspace.co.uk/
http://aviewfromafar.net/
C694a032be7518a0d704318895f8fe1d?d=identicon&s=25 Ben Mabey (mabes)
on 2008-11-04 20:30
(Received via mailing list)
Ashley Moran wrote:
>
> On Nov 04, 2008, at 6:18 pm, Matt Wynne 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. :)


-Ben
2ce9c0106b5851b2294ba5eb9f5c04bd?d=identicon&s=25 Ashley Moran (Guest)
on 2008-11-04 21:42
(Received via mailing list)
On Nov 04, 2008, at 7:28 pm, Ben Mabey wrote:

> Oh really?  Hmm.. I assumed it was still there. :)

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/
http://aviewfromafar.net/
F68f69615423aa3851bd445409754dbf?d=identicon&s=25 Joseph Wilk (joesniff)
on 2008-11-04 21:44
(Received via mailing list)
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/tick...

--
Joseph Wilk
http://www.joesniff.co.uk
This topic is locked and can not be replied to.