Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/strict mode #211

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/cucumber/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,14 @@ var Cli = function(argv) {
summary : prints a summary only, after all\n\
scenarios were executed\n\
\n\
-S, --strict Fail if there are any undefined or pending steps.\n\
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jbpros - I've updated the shorthand flag to be inline with the ruby implementation, -S

\n\
--coffee Display step definition snippets in CoffeeScript.\n\
\n\
-v, --version Display Cucumber.js's version.\n\
\n\
-h, --help You're looking at it.\n");
-h, --help You're looking at it.\n\
");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aslakhellesoy Sorry I don't see it?
Looks like I/my editor dropped the "); down to a newline, was that it? Happy to move it back.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see now. Actually I like yours better.

callback(true);
},

Expand Down
12 changes: 11 additions & 1 deletion lib/cucumber/cli/argument_parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ var ArgumentParser = function(argv) {
definitions[ArgumentParser.TAGS_OPTION_NAME] = [String, Array];
definitions[ArgumentParser.FORMAT_OPTION_NAME] = String;
definitions[ArgumentParser.HELP_FLAG_NAME] = Boolean;
definitions[ArgumentParser.STRICT_FLAG_NAME] = Boolean;
definitions[ArgumentParser.VERSION_FLAG_NAME] = Boolean;
definitions[ArgumentParser.COFFEE_SCRIPT_SNIPPETS_FLAG_NAME] = Boolean;
return definitions;
Expand All @@ -76,11 +77,17 @@ var ArgumentParser = function(argv) {
getShortenedOptionDefinitions: function getShortenedOptionDefinitions() {
var definitions = {};
definitions[ArgumentParser.REQUIRE_OPTION_SHORT_NAME] = [ArgumentParser.LONG_OPTION_PREFIX + ArgumentParser.REQUIRE_OPTION_NAME];
definitions[ArgumentParser.FORMAT_OPTION_SHORT_NAME] = [ArgumentParser.LONG_OPTION_PREFIX + ArgumentParser.FORMAT_OPTION_NAME];
definitions[ArgumentParser.FORMAT_OPTION_SHORT_NAME] = [ArgumentParser.LONG_OPTION_PREFIX + ArgumentParser.FORMAT_OPTION_NAME];
definitions[ArgumentParser.HELP_FLAG_SHORT_NAME] = [ArgumentParser.LONG_OPTION_PREFIX + ArgumentParser.HELP_FLAG_NAME];
definitions[ArgumentParser.STRICT_FLAG_SHORT_NAME] = [ArgumentParser.LONG_OPTION_PREFIX + ArgumentParser.STRICT_FLAG_NAME];
return definitions;
},

isStrictRequested: function isStrictRequested() {
var isStrictRequested = self.getOptionOrDefault(ArgumentParser.STRICT_FLAG_NAME, ArgumentParser.DEFAULT_STRICT_FLAG_VALUE);
return isStrictRequested;
},

isHelpRequested: function isHelpRequested() {
var isHelpRequested = self.getOptionOrDefault(ArgumentParser.HELP_FLAG_NAME, ArgumentParser.DEFAULT_HELP_FLAG_VALUE);
return isHelpRequested;
Expand Down Expand Up @@ -126,7 +133,10 @@ ArgumentParser.TAGS_OPTION_NAME = "tags";
ArgumentParser.TAGS_OPTION_SHORT_NAME = "t";
ArgumentParser.HELP_FLAG_NAME = "help";
ArgumentParser.HELP_FLAG_SHORT_NAME = "h";
ArgumentParser.STRICT_FLAG_NAME = "strict";
ArgumentParser.STRICT_FLAG_SHORT_NAME = "s";
ArgumentParser.DEFAULT_HELP_FLAG_VALUE = false;
ArgumentParser.DEFAULT_STRICT_FLAG_VALUE = false;
ArgumentParser.VERSION_FLAG_NAME = "version";
ArgumentParser.DEFAULT_VERSION_FLAG_VALUE = false;
ArgumentParser.COFFEE_SCRIPT_SNIPPETS_FLAG_NAME = "coffee";
Expand Down
5 changes: 5 additions & 0 deletions lib/cucumber/cli/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ var Configuration = function(argv) {
return isHelpRequested;
},

isStrictRequested: function isStrictRequested() {
var isStrictRequested = argumentParser.isStrictRequested();
return isStrictRequested;
},

isVersionRequested: function isVersionRequested() {
var isVersionRequested = argumentParser.isVersionRequested();
return isVersionRequested;
Expand Down
8 changes: 7 additions & 1 deletion lib/cucumber/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@ var Runtime = function(configuration) {
start: function start(callback) {
if (typeof(callback) !== 'function')
throw new Error(Runtime.START_MISSING_CALLBACK_ERROR);
var isStrictRequested;
try {
isStrictRequested = configuration.isStrictRequested();
} catch(e) {
isStrictRequested = false;
}
var features = self.getFeatures();
var supportCodeLibrary = self.getSupportCodeLibrary();
var astTreeWalker = Runtime.AstTreeWalker(features, supportCodeLibrary, listeners);
var astTreeWalker = Runtime.AstTreeWalker(features, supportCodeLibrary, listeners, isStrictRequested);
astTreeWalker.walk(callback);
},

Expand Down
8 changes: 7 additions & 1 deletion lib/cucumber/runtime/ast_tree_walker.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var AstTreeWalker = function(features, supportCodeLibrary, listeners) {
var AstTreeWalker = function(features, supportCodeLibrary, listeners, strictMode) {
var Cucumber = require('../../cucumber');

var world;
Expand Down Expand Up @@ -163,10 +163,16 @@ var AstTreeWalker = function(features, supportCodeLibrary, listeners) {
},

witnessPendingStep: function witnessPendingStep() {
if (strictMode) {
allFeaturesSucceded = false;
}
skippingSteps = true;
},

witnessUndefinedStep: function witnessUndefinedStep() {
if (strictMode) {
allFeaturesSucceded = false;
}
skippingSteps = true;
},

Expand Down
31 changes: 31 additions & 0 deletions spec/cucumber/cli/argument_parser_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ describe("Cucumber.Cli.ArgumentParser", function () {
expect(knownOptionDefinitions[Cucumber.Cli.ArgumentParser.FORMAT_OPTION_NAME]).toEqual(String);
});

it("defines a --strict flag", function () {
var knownOptionDefinitions = argumentParser.getKnownOptionDefinitions();
expect(knownOptionDefinitions[Cucumber.Cli.ArgumentParser.STRICT_FLAG_NAME]).toEqual(Boolean);
});

it("defines a --help flag", function () {
var knownOptionDefinitions = argumentParser.getKnownOptionDefinitions();
expect(knownOptionDefinitions[Cucumber.Cli.ArgumentParser.HELP_FLAG_NAME]).toEqual(Boolean);
Expand Down Expand Up @@ -102,6 +107,14 @@ describe("Cucumber.Cli.ArgumentParser", function () {
expect(shortenedOptionDefinitions[aliasName]).toEqual(aliasValue);
});

it("defines an alias to --strict as -s", function () {
var optionName = Cucumber.Cli.ArgumentParser.LONG_OPTION_PREFIX + Cucumber.Cli.ArgumentParser.STRICT_FLAG_NAME;
var aliasName = Cucumber.Cli.ArgumentParser.STRICT_FLAG_SHORT_NAME;
var aliasValue = [optionName];
var shortenedOptionDefinitions = argumentParser.getShortenedOptionDefinitions();
expect(shortenedOptionDefinitions[aliasName]).toEqual(aliasValue);
});

it("defines an alias to --help as -h", function () {
var optionName = Cucumber.Cli.ArgumentParser.LONG_OPTION_PREFIX + Cucumber.Cli.ArgumentParser.HELP_FLAG_NAME;
var aliasName = Cucumber.Cli.ArgumentParser.HELP_FLAG_SHORT_NAME;
Expand Down Expand Up @@ -303,6 +316,24 @@ describe("Cucumber.Cli.ArgumentParser", function () {
});
});

describe("isStrictRequested()", function () {
var isStrictRequested;

beforeEach(function () {
isStrictRequested = createSpy("is strict requested?");
spyOn(argumentParser, 'getOptionOrDefault').andReturn(isStrictRequested);
});

it("gets the 'strict' flag with a default value", function () {
argumentParser.isStrictRequested();
expect(argumentParser.getOptionOrDefault).toHaveBeenCalledWith(Cucumber.Cli.ArgumentParser.STRICT_FLAG_NAME, Cucumber.Cli.ArgumentParser.DEFAULT_STRICT_FLAG_VALUE);
});

it("returns the flag value", function () {
expect(argumentParser.isStrictRequested()).toBe(isStrictRequested);
});
});

describe("isHelpRequested()", function () {
var isHelpRequested;

Expand Down
48 changes: 43 additions & 5 deletions spec/cucumber/runtime/ast_tree_walker_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -624,13 +624,51 @@ describe("Cucumber.Runtime.AstTreeWalker", function() {
});

describe("didAllFeaturesSucceed()", function() {
it("returns true when no failure was encountered", function() {
expect(treeWalker.didAllFeaturesSucceed()).toBeTruthy();
describe("when strict mode is off", function() {
it("returns true when no failure was encountered", function() {
expect(treeWalker.didAllFeaturesSucceed()).toBeTruthy();
});

it("returns false when a failed step was encountered", function() {
treeWalker.witnessFailedStep();
expect(treeWalker.didAllFeaturesSucceed()).toBeFalsy();
});

it("returns true when a pending step was encountered", function() {
treeWalker.witnessPendingStep();
expect(treeWalker.didAllFeaturesSucceed()).toBeTruthy();
});

it("returns true when an undefined step was encountered", function() {
treeWalker.witnessUndefinedStep();
expect(treeWalker.didAllFeaturesSucceed()).toBeTruthy();
});
});

it("returns false when a failed step was encountered", function() {
treeWalker.witnessFailedStep();
expect(treeWalker.didAllFeaturesSucceed()).toBeFalsy();
describe("when strict mode is on", function() {
beforeEach(function() {
var isStrictMode = true;
treeWalker = Cucumber.Runtime.AstTreeWalker(features, supportCodeLibrary, listeners, isStrictMode);
});

it("returns true when no failure was encountered", function() {
expect(treeWalker.didAllFeaturesSucceed()).toBeTruthy();
});

it("returns false when a failed step was encountered", function() {
treeWalker.witnessFailedStep();
expect(treeWalker.didAllFeaturesSucceed()).toBeFalsy();
});

it("returns false when a pending step was encountered", function() {
treeWalker.witnessPendingStep();
expect(treeWalker.didAllFeaturesSucceed()).toBeFalsy();
});

it("returns false when an undefined step was encountered", function() {
treeWalker.witnessUndefinedStep();
expect(treeWalker.didAllFeaturesSucceed()).toBeFalsy();
});
});
});

Expand Down
6 changes: 4 additions & 2 deletions spec/cucumber/runtime_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ describe("Cucumber.Runtime", function() {
var configuration;
var runtime;
var supportCodeLibrary, listeners;
var isStrictRequested;

beforeEach(function() {
isStrictRequested = false;
listeners = createSpyWithStubs("listener collection", {add: null});
configuration = createSpy("configuration");
configuration = createSpyWithStubs("configuration", { isStrictRequested: isStrictRequested });
spyOn(Cucumber.Type, 'Collection').andReturn(listeners);
runtime = Cucumber.Runtime(configuration);
});
Expand Down Expand Up @@ -64,7 +66,7 @@ describe("Cucumber.Runtime", function() {

it("creates a new AST tree walker", function() {
runtime.start(callback);
expect(Cucumber.Runtime.AstTreeWalker).toHaveBeenCalledWith(features, supportCodeLibrary, listeners);
expect(Cucumber.Runtime.AstTreeWalker).toHaveBeenCalledWith(features, supportCodeLibrary, listeners, isStrictRequested);
});

it("tells the AST tree walker to walk", function() {
Expand Down