Skip to content

Commit

Permalink
Add ^ prefix and $ suffix to string-based step definition regexps (#77)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbpros committed Oct 9, 2012
1 parent 3768a4c commit 729f927
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 6 additions & 0 deletions lib/cucumber/support_code/step_definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ var StepDefinition = function (pattern, code) {
var regexpString = pattern
.replace(StepDefinition.QUOTED_DOLLAR_PARAMETER_REGEXP, StepDefinition.QUOTED_DOLLAR_PARAMETER_SUBSTITUTION)
.replace(StepDefinition.DOLLAR_PARAMETER_REGEXP, StepDefinition.DOLLAR_PARAMETER_SUBSTITUTION);
regexpString =
StepDefinition.STRING_PATTERN_REGEXP_PREFIX +
regexpString +
StepDefinition.STRING_PATTERN_REGEXP_SUFFIX;
regexp = RegExp(regexpString);
}
else
Expand Down Expand Up @@ -88,6 +92,8 @@ StepDefinition.DOLLAR_PARAMETER_REGEXP = /\$[a-zA-Z_-]+/;
StepDefinition.DOLLAR_PARAMETER_SUBSTITUTION = '(.*)';
StepDefinition.QUOTED_DOLLAR_PARAMETER_REGEXP = /"\$[a-zA-Z_-]+"/;
StepDefinition.QUOTED_DOLLAR_PARAMETER_SUBSTITUTION = '"([^"]*)"';
StepDefinition.STRING_PATTERN_REGEXP_PREFIX = '^';
StepDefinition.STRING_PATTERN_REGEXP_SUFFIX = '$';
StepDefinition.UNKNOWN_STEP_FAILURE_MESSAGE = "Step failure";

module.exports = StepDefinition;
4 changes: 2 additions & 2 deletions spec/cucumber/support_code/step_definition_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe("Cucumber.SupportCode.StepDefinition", function () {

beforeEach(function () {
regexp = createSpy("regexp");
regexpString = createSpy("regexp string");
regexpString = "regexp string";
quotedDollarParameterSubstitutedPattern = createSpyWithStubs("quoted dollar param substituted pattern", {replace: regexpString});
spyOnStub(pattern, 'replace').andReturn(quotedDollarParameterSubstitutedPattern);
global.RegExp.andReturn(regexp);
Expand All @@ -45,7 +45,7 @@ describe("Cucumber.SupportCode.StepDefinition", function () {

it("instantiates a new RegExp", function () {
stepDefinition.getPatternRegexp();
expect(global.RegExp).toHaveBeenCalledWith(regexpString);
expect(global.RegExp).toHaveBeenCalledWith("^" + regexpString + "$");
});

it("returns the new RegExp", function () {
Expand Down

0 comments on commit 729f927

Please sign in to comment.