Composed steps don't behave like steps in a story when using parameters

Description

Problem Statement:
When I use a composite step that calls another step which takes parameters, the correct step is rejected because it doesn't match the patternString.

Steps to Recreate:
1. Create a step and method that take a parameter, (ex. @When("I click the $button button")public void clickButton(String button){...}
2. Create a Composite step that references step 1. (ex. @When("I login")
@Composite(steps={"I click the login button"})

Actual Results:
The second step will give you a pending method, that matches step 1. but they don't match because of the paramter.

Suggested Change:
Found this while debugging in the StepCandidate.class on line 179:
if (StringUtils.startsWith(composedStep, candidate.getStartingWord())
&& StringUtils.endsWith(composedStep, candidate.getPatternAsString()) ) {
return candidate;
}

Could be changed to:

if (StringUtils.startsWith(composedStep, candidate.getStartingWord())
&& (StringUtils.endsWith(composedStep, candidate.getPatternAsString()) || candidate.matches(composedStep))) {
return candidate;
}

JUnit Test:

@Test
public void shouldMatchCompositStepsWhenStepParamterIsProvided(){
CompositeStepParamterMatching steps = new CompositeStepParamterMatching();
List<StepCandidate> candidates = steps.listCandidates();
StepCandidate candidate = candidates.get(0);
assertThat(candidate.isComposite(), is(true));
Map<String, String> noNamedParameters = new HashMap<String, String>();
List<Step> composedSteps = new ArrayList<Step>();
candidate.addComposedSteps(composedSteps, "When I login", noNamedParameters, candidates);
assertThat(composedSteps.size(), equalTo(2));
for (Step step : composedSteps) {
step.perform(null);
}
assertThat(steps.button, equalTo("Login"));
}

static class CompositeStepParamterMatching extends Steps {
private String button;

@When("I login")
@Composite(steps={"I click the Login button"})
public void whenILogin(){}

@When("I click the <button> button")
public void whenIClickTheButton(@Named("button") String button){
this.button = button;
}

}

Assignee

Unassigned

Reporter

David Tanner

Labels

None

Time tracking

1h

Components

Fix versions

Affects versions

Priority

Major
Configure