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.
Andrew P. (Guest)
on 2008-11-04 17: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...
Matt W. (Guest)
on 2008-11-04 18:31
(Received via mailing list)
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/tick...
Andrew P. (Guest)
on 2008-11-04 18:55
(Received via mailing list)
Thanks Matt, just what I was looking for :)
Andrew

2008/11/4 Matt W. <removed_email_address@domain.invalid>
Ben M. (Guest)
on 2008-11-04 20:11
(Received via mailing list)
Andrew P. 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
Matt W. (Guest)
on 2008-11-04 20:31
(Received via mailing list)
On 4 Nov 2008, at 17:42, Ben M. wrote:

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

Dude, that is soooo "Story Runner".

;)
Ashley M. (Guest)
on 2008-11-04 21:26
(Received via mailing list)
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/
http://aviewfromafar.net/
Ben M. (Guest)
on 2008-11-04 21:30
(Received via mailing list)
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. :)


-Ben
Ashley M. (Guest)
on 2008-11-04 22:42
(Received via mailing list)
On Nov 04, 2008, at 7:28 pm, Ben M. 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/
Joseph W. (Guest)
on 2008-11-04 22: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 W.
http://www.joesniff.co.uk
This topic is locked and can not be replied to.