Browse files

Accept multiple features in volatile configuration (close #52)

  • Loading branch information...
1 parent 1fa696b commit f5417c02b33db8c95bc25f50314e97f87cafaea9 @jbpros jbpros committed Oct 9, 2012
View
19 features/step_definitions/cucumber_steps.js
@@ -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);
});
@@ -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) };
@@ -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();
@@ -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');
View
16 features/step_definitions/cucumber_world.js
@@ -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);
@@ -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();
View
11 lib/cucumber/volatile_configuration.js
@@ -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() {
View
32 spec/cucumber/volatile_configuration_spec.js
@@ -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);
@@ -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() {
@@ -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);
});

0 comments on commit f5417c0

Please sign in to comment.