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

Added support for string-based matchers for step definitions. #48

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -34,6 +34,7 @@ Cucumber.js is still a work in progress. Here is its current status.
| [Undefined steps](https://github.com/cucumber/cucumber-tck/blob/master/undefined_steps.feature) | Done |
| [Wire protocol](https://github.com/cucumber/cucumber-tck/blob/master/wire_protocol.feature) | To do |
| [World](https://github.com/cucumber/cucumber-tck/blob/master/world.feature) | Done |
| [String defined step definitions](https://github.com/cucumber/cucumber-tck/blob/master/stringdefined.feature) | Done |
Copy link
Member

Choose a reason for hiding this comment

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

There is no such feature in cucumber-tck. Do you have it on your local repo?


1. Not certified by [Cucumber TCK](https://github.com/cucumber/cucumber-tck) yet.
2. Considered for removal from [Cucumber TCK](https://github.com/cucumber/cucumber-tck).
Expand Down
24 changes: 24 additions & 0 deletions features/step_definitions/cucumber_steps.js
Expand Up @@ -156,6 +156,10 @@ setTimeout(callback.pending, 10);\
callback();
});

Given('a feature is defined with a string', function( callback ) {
callback();
});

When(/^Cucumber executes the scenario$/, function(callback) {
this.runFeature({}, callback);
});
Expand Down Expand Up @@ -219,6 +223,22 @@ callback();\
this.runFeature({tags: [tag1, '~' + tag2, '~' + tag3]}, callback);
});

When('Cucumber executes scenarios with parameter $param1 and $param2 are not equal in a string', function( param1, param2, callback ) {
if( param1 != param2 ) {
callback();
} else {
throw(new Error('Params were equal'));
}
});

When('Cucumber executes scenarios with parameter $param1 and $param2 are equal in a string', function( param1, param2, callback ) {
if( param1 == param2 ) {
callback();
} else {
throw(new Error('Params were equal'));
}
});

Then(/^the scenario passes$/, function(callback) {
this.assertPassedScenario();
callback();
Expand Down Expand Up @@ -333,5 +353,9 @@ callback();\
this.assertExecutedNumberedScenarios(2, 3, 4);
callback();
});

Then('The string-defined scenario is finished', function(callback) {
callback();
Copy link
Member

Choose a reason for hiding this comment

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

The step definitions you added are not doing anything apart from calling back. I think you are missing something here :)

});
};
module.exports = cucumberSteps;
17 changes: 17 additions & 0 deletions lib/cucumber/support_code/step_definition.js
@@ -1,6 +1,23 @@
var StepDefinition = function(regexp, code) {
var Cucumber = require('../../cucumber');

var constructor = function() {
// Converts a string to a proper regular expression
var parseRegexString = function( regexString ) {

// Replace the $VARIABLES with the correct regex.
regexString = regexString.replace(/\$[a-zA-Z0-9]+/g, '([^"]*)');
return new RegExp( regexString );
}

if( typeof(regexp)=='string' ) {
// regexp is a string, convert it to a regexp.
regexp = parseRegexString(regexp);
}
}

constructor();

var self = {
matchesStepName: function matchesStepName(stepName) {
return regexp.test(stepName);
Expand Down