Forum: RSpec could one scenario depend on another in 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.
Newman H. (Guest)
on 2008-11-26 05:27
I think it is a common test case you would meet. For example, you want
to test a user registry scenario. You write:

Scenario: User Registry
   When I dosth
   Then I dosth
   ...

And now business has some changes. Register should have to activate his
account by a secret code sent by mobile phone. So you need to write the
other scenario:

Scenario: User Registry and Account Activation By Mobile
   When I dosth
   Then I dosth
   ...
   #above is the samed as User Registry scenario

   Then I visit "my setting" page
   And I fill in "activate code" with "code"
   ...

Because the second scenario is based on the first one, cucumber can do
the things like:

Scenario: User Registry and Account Activation By Mobile
   depend on [Scenario: User Registry]

??

If you use ant to write build file, or rake task, dependency is
supported. So cucumber also can do it, right?

Thanks.
Matt W. (Guest)
on 2008-11-26 10:19
(Received via mailing list)
On 26 Nov 2008, at 03:27, Newman H. wrote:

> account by a secret code sent by mobile phone. So you need to write
>   And I fill in "activate code" with "code"
> If you use ant to write build file, or rake task, dependency is
> supported. So cucumber also can do it, right?

You need the feature known as 'Call Steps From Steps':
http://rspec.lighthouseapp.com/projects/16211/tick...

This basically allows you to make a magic step which calls in some or
all of the steps from the other scenario.

Also, perhaps I might humbly recommend my blog post about the subject:
http://blog.mattwynne.net/2008/11/14/dry-up-your-c...

Hope that helps,
Matt
Pau C. (Guest)
on 2008-11-26 11:41
Newman H. wrote:
> I think it is a common test case you would meet. For example, you want
> to test a user registry scenario. You write:
>
> Scenario: User Registry
>    When I dosth
>    Then I dosth
>    ...
>
> And now business has some changes. Register should have to activate his
> account by a secret code sent by mobile phone. So you need to write the
> other scenario:
>
> Scenario: User Registry and Account Activation By Mobile
>    When I dosth
>    Then I dosth
>    ...
>    #above is the samed as User Registry scenario
>
>    Then I visit "my setting" page
>    And I fill in "activate code" with "code"
>    ...
>
> Because the second scenario is based on the first one, cucumber can do
> the things like:
>
> Scenario: User Registry and Account Activation By Mobile
>    depend on [Scenario: User Registry]
>

yes, try this:

Scenario: User Registry and Account Activation By Mobile
  GivenScenario: User Registry
  Then I visit "my setting" page
  And I fill in "activate code" with "code"
  ...

HTH
Paul
Matt W. (Guest)
on 2008-11-26 11:46
(Received via mailing list)
On 26 Nov 2008, at 09:41, Pau C. wrote:
>
> yes, try this:
>
> Scenario: User Registry and Account Activation By Mobile
>  GivenScenario: User Registry

I think I might be right in saying that technique is likely to be
deprecated in the future. I don't think it's recommended anymore. See
my earlier response.

cheers,
Matt
Pau C. (Guest)
on 2008-11-27 09:28
Matt W. wrote:
> I think I might be right in saying that technique is likely to be
> deprecated in the future. I don't think it's recommended anymore. See
> my earlier response.

Thanks Matt. That is good to know.

Paul
Newman H. (Guest)
on 2008-11-28 11:08
Matt W. wrote:
> On 26 Nov 2008, at 03:27, Newman H. wrote:
>
>> account by a secret code sent by mobile phone. So you need to write
>>   And I fill in "activate code" with "code"
>> If you use ant to write build file, or rake task, dependency is
>> supported. So cucumber also can do it, right?
>
> You need the feature known as 'Call Steps From Steps':
> 
http://rspec.lighthouseapp.com/projects/16211/tick...
>
> This basically allows you to make a magic step which calls in some or
> all of the steps from the other scenario.
>
> Also, perhaps I might humbly recommend my blog post about the subject:
> http://blog.mattwynne.net/2008/11/14/dry-up-your-c...
>
> Hope that helps,
> Matt

Hi, Matt

Thanks for your kind reply.

Yesterday I rethink such a test case need scenario dependency, and I
find a way to walk around it. We know cucumber defines the scenario
implementation in the steps ruby file. So all the scenario
reusing(dependency) should be a step reusing, and then we can define a
well-defined step for scenario dependency. Here is a sample:

Scenario: User Registry
   When I dosth
   Then I dosth

We can define it in the step:

Given /^I have registered with "(.*)" and "(.*)"$/ do |name,password|
   ...
end

and for the other scenario, we can describe it as this way:

Scenario: User Registry and Account Activation By Mobile
   Given I have registered with "somebody" and "password"
   Then I visit "my setting" page
   And I fill in "activate code" with "code"

Such a implementation would be more reasonable, for it is simple.
This topic is locked and can not be replied to.