Skip to content

Commit

Permalink
Accept multiple features in volatile configuration (close #52)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbpros committed Oct 9, 2012
1 parent 1fa696b commit f5417c0
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 16 deletions.
19 changes: 18 additions & 1 deletion features/step_definitions/cucumber_steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,15 @@ setTimeout(callback.pending, 10);\
callback();
});

Given(/^several features$/, function(callback) {
this.features = [
["feature1", "Feature: One\n\n Scenario:\n"],
["feature2", "Feature: Two\n\n Scenario:\n"],
["feature3", "Feature: Three\n\n Scenario:\n"],
];
callback();
});

When(/^Cucumber executes the scenario$/, function(callback) {
this.runFeature({}, callback);
});
Expand Down Expand Up @@ -205,6 +214,10 @@ setTimeout(callback.pending, 10);\
this.runFeature({}, callback);
});

When(/^Cucumber runs the features$/, function(callback) {
this.runFeatures({}, callback);
});

When(/^Cucumber runs the scenario with steps for a calculator$/, function(callback) {
RpnCalculator = require('../support/rpn_calculator');
var supportCode = function() { require('./calculator_steps').initialize.call(this, RpnCalculator) };
Expand Down Expand Up @@ -306,6 +319,11 @@ callback();\
callback();
});

Then(/^all features are run$/, function(callback) {
this.assertPassedFeatures();
callback();
});

Then(/^the failure message "([^"]*)" is output$/, function(message, callback) {
this.assertFailureMessage(message);
callback();
Expand All @@ -328,7 +346,6 @@ callback();\
callback();
});


Then(/^the (before|after) hook is fired (?:before|after) the scenario$/, function(hookType, callback) {
if (hookType == 'before')
this.assertCycleSequence(hookType, 'step 1');
Expand Down
16 changes: 15 additions & 1 deletion features/step_definitions/cucumber_world.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,21 @@ proto.runFeature = function runFeature(options, callback) {
this.runFeatureWithSupportCodeSource(supportCode, options, callback);
};

proto.runFeatures = function runFeatures(options, callback) {
this.runFeaturesWithSupportCodeSource(this.features, function() {}, options, callback);
};

proto.runFeatureWithSupportCodeSource = function runFeatureWithSupportCodeSource(supportCode, options, callback) {
this.runFeaturesWithSupportCodeSource(this.featureSource, supportCode, options, callback);
};

proto.runFeaturesWithSupportCodeSource = function runFeaturesWithSupportCodeSource(features, supportCode, options, callback) {
var world = this;
var Cucumber = require('../../lib/cucumber');
options = options || {};
var tags = options['tags'] || [];

var cucumber = Cucumber(this.featureSource, supportCode, {tags: tags});
var cucumber = Cucumber(features, supportCode, {tags: tags});
var formatter = Cucumber.Listener.ProgressFormatter({logToConsole: false});

cucumber.attachListener(formatter);
Expand Down Expand Up @@ -155,6 +163,12 @@ proto.assertPassedFeature = function assertPassedFeature() {
this.assertSuccess();
};

proto.assertPassedFeatures = function assertPassedFeatures() {
this.assertNoPartialOutput("failed", this.runOutput);
this.assertPartialOutput("3 scenarios (3 passed)", this.runOutput);
this.assertSuccess();
};

proto.assertPassedScenario = function assertPassedScenario() {
this.assertPartialOutput("1 scenario (1 passed)", this.runOutput);
this.assertSuccess();
Expand Down
11 changes: 7 additions & 4 deletions lib/cucumber/volatile_configuration.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
var VolatileConfiguration = function VolatileConfiguration(featureSource, supportCodeInitializer, options) {
var VolatileConfiguration = function VolatileConfiguration(features, supportCodeInitializer, options) {
var Cucumber = require('../cucumber');

var supportCodeLibrary = Cucumber.SupportCode.Library(supportCodeInitializer);

options = options || {};
var tagGroupStrings = options['tags'] || [];

var self = {
getFeatureSources: function getFeatureSources() {
var featureNameSourcePair = [VolatileConfiguration.FEATURE_SOURCE_NAME, featureSource];
return [featureNameSourcePair];
if (features.replace) { // single source
var featureNameSourcePair = [VolatileConfiguration.FEATURE_SOURCE_NAME, features];
return [featureNameSourcePair];
} else { // multiple features
return features;
}
},

getAstFilter: function getAstFilter() {
Expand Down
32 changes: 22 additions & 10 deletions spec/cucumber/volatile_configuration_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ require('../support/configurations_shared_examples.js');
describe("Cucumber.VolatileConfiguration", function() {
var Cucumber = requireLib('cucumber');

var featureSource, supportCodeInitializer, configuration;
var featureSources, supportCodeInitializer, configuration;
var supportCodeLibrary;
var context = {};

beforeEach(function() {
supportCodeLibrary = createSpy("support code library");
spyOn(Cucumber.SupportCode, 'Library').andReturn(supportCodeLibrary);
featureSource = createSpy("feature source");
featureSources = createSpy("feature source");
supportCodeInitializer = createSpy("support code initializer");
configuration = Cucumber.VolatileConfiguration(featureSource, supportCodeInitializer);
context['configuration'] = configuration;
configuration = Cucumber.VolatileConfiguration(featureSources, supportCodeInitializer);
context.configuration = configuration;
});

itBehavesLikeAllCucumberConfigurations(context);
Expand All @@ -26,11 +26,23 @@ describe("Cucumber.VolatileConfiguration", function() {
});

describe("getFeatureSources()", function() {
it("returns the feature source and its volatile name", function() {
var featureNameSourcePair = [Cucumber.VolatileConfiguration.FEATURE_SOURCE_NAME, featureSource];
var featureSources = [featureNameSourcePair];
expect(configuration.getFeatureSources()).toEqual(featureSources);
})
describe("when a single feature source string is passed", function () {
beforeEach(function () {
featureSources.replace = function () {};
});

it("returns the feature source and its volatile name", function() {
var featureNameSourcePair = [Cucumber.VolatileConfiguration.FEATURE_SOURCE_NAME, featureSources];
var featureSourceArray = [featureNameSourcePair];
expect(configuration.getFeatureSources()).toEqual(featureSourceArray);
});
});

describe("when an array of features is passed", function () {
it("returns the array", function() {
expect(configuration.getFeatureSources()).toEqual(featureSources);
});
});
});

describe("getAstFilter()", function() {
Expand Down Expand Up @@ -77,7 +89,7 @@ describe("Cucumber.VolatileConfiguration", function() {
beforeEach(function() {
tagGroupStrings = [createSpy("tag group string 1"), createSpy("tag group string 2"), createSpy("tag group string 3")];
rules = [createSpy("rule 1"), createSpy("rule 2"), createSpy("rule 3")];
configuration = Cucumber.VolatileConfiguration(featureSource, supportCodeInitializer, {tags: tagGroupStrings});
configuration = Cucumber.VolatileConfiguration(featureSources, supportCodeInitializer, {tags: tagGroupStrings});
spyOn(configuration, 'buildAstFilterRuleFromTagGroupString').andReturnSeveral(rules);
});

Expand Down

0 comments on commit f5417c0

Please sign in to comment.