Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test for same feature with multiple backgrounds in cucumber

Tags:

I've got a feature (a .feature file) that are working fine in cucumber.

The background of all the scenarios in the feature just sets up a user, and then logs in as a supervisor, e.g.

   Background:      Given I am logged in as a supervisor with an existing supervisee     ...loads of scenarios 

However the design/goals of the application has changed and the same scenarios should all work whether you are logged in as a supervisor or as the user. This is not true for most of the rest of the application where the design is not symmetrical for supervisors/users.

Is there any sane way to avoid copying and pasting the whole of the feature file with a different background? It doesn't seem like there's a way to either parameterize background (e.g. with an Either: Or: stanza) or alternatively a way to pull in an external file with a load of scenarios. Ideas?

   Background:      Given I am logged in as an existing supervisee     ...same loads of scenarios 

Here's some fantasy gherkin syntax (that doesn't exist)

   Background Outline:      Given I am logged in as a <user>     Backgrounds:      | user                                   |      | supervisor with an existing supervisee |      | an existing supervisee                 |     ...loads of scenarios 

Alternatively different fantasy Gherkin syntax :

   Background:      Given I am logged in as an existing supervisee     Include Scenarios:      supervisor.features 
like image 933
Tim Diggins Avatar asked Oct 30 '12 15:10

Tim Diggins


1 Answers

If it was me, I would just suck up the duplication:

http://dannorth.net/2008/06/30/let-your-examples-flow/

An alternative would be to use a tag on the feature that indicates you want to run the scenarios against both user groups. Then use an Around hook to run the scenario twice, once for each type of user.

We've talked about things like Background Outlines before, but the conclusion we came to was that it wouldn't be worth the extra complexity to implement it.

like image 116
Matt Wynne Avatar answered Oct 24 '22 10:10

Matt Wynne