Permalink
Browse files

Add ^ prefix and $ suffix to string-based step definition regexps (#77)

  • Loading branch information...
1 parent 3768a4c commit 729f92748f9ad21b54dfb2a4d3a7aadae0233054 @jbpros jbpros committed Oct 9, 2012
@@ -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
@@ -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;
@@ -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);
@@ -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 () {

0 comments on commit 729f927

Please sign in to comment.