Details
Description
Wnen using jbehave with named parameters, order is not respected in parameter injection if the named parameters are sorrounded with non-white characters (for example, quotes).
Here is a simple test:
public class QuoteNamedParametersStory extends JUnitStory { public static class QuotNamedParametersSteps { @Then("\"$foo\" then \"$bar\"") public void otherOrderQuotes(@Named("bar") String bar, @Named("foo") String foo) { assertThat(foo, equalTo("foo")); assertThat(bar, equalTo("bar")); } } @Override public Configuration configuration() { return new MostUsefulConfiguration().useStoryReporterBuilder(new StoryReporterBuilder().withFormats(Format.CONSOLE).withFailureTrace(true)); } @Override public List<CandidateSteps> candidateSteps() { return new InstanceStepsFactory(configuration(), new QuotNamedParametersSteps()).createCandidateSteps(); } }
And the corresponding quote_named_parameters_story.story:
Scenario: quotes on named parameters are problematic... Then "foo" then "bar"
I was able to fix it (and pass the above test successfully) by changing org.jbehave.core.parsers.RegexPrefixCapturingPatternParser.Parameter to:
private class Parameter { private final int start; private final int end; private final String whitespaceIfAny; private final String name; public Parameter(String pattern, int start, int end, String whitespaceIfAny) { this.start = start; this.end = end; this.whitespaceIfAny = whitespaceIfAny; this.name = pattern.substring(start + prefix.length(), end - whitespaceIfAny.length()).trim(); } }
Activity
Mauro Talevi
made changes -
Field | Original Value | New Value |
---|---|---|
Status | Open [ 1 ] | Resolved [ 5 ] |
Fix Version/s | 3.6 [ 17721 ] | |
Resolution | Fixed [ 1 ] |
A patch for this issue is available at https://github.com/ruifigueira/jbehave-core/commit/2b69281edf2aae7d34e4b262c49ca88625b2b999