acuminous / yadda

A BDD javascript library
412 stars 73 forks source link

Feature request - background Where table support #168

Closed riaan53 closed 9 years ago

riaan53 commented 9 years ago

Hi there,

I need to be able to run the a lot of features over different backgrounds.

Will it be possible to add Where table support for the background?

Simplified example:

Background:

    Given im loggen in as [level]

      Where:
          level
          admin
          user
          guest

At the moment I need to add the same data table to every scenario, which becomes a mess if that scenario already have a Where table, or create a duplicate feature for each.

Any suggestions?

Thanks!

Regards, Riaan

cressie176 commented 9 years ago

I understand the problem, but not sure background example tables are the way to go. Background steps get pre-pended to each scenarios steps, but I'd have to treat a background example table differently - duplicating each scenario for every line.

I'll give it some thought and see if I can come up with an alternative

riaan53 commented 9 years ago

Thank you! :)

cressie176 commented 9 years ago

How about annotating the scenarios

@roles=['user', 'admin', 'guest']

Then running the suite or feature multiple times either from the command line

['user', 'admin', 'guest'].forEach(function(role) {
    scenarios(feature.scenarios, function(scenario) {
        if (scenario.annotations.indexOf(role) {
            steps(scenario.steps, function(step, done) {
                yadda.run(step, done);
            });
       });
    });
});

The same approach would work at feature level too.

Another alternative would be to run the test suite multiple times and specify the role as an environment variable, e.g.

ROLE=user npm test
ROLE=admin npm test
ROLE=guest npm test
riaan53 commented 9 years ago

@cressie176 Thank you! I think that might do the trick :)