Skip to content
This repository has been archived by the owner on May 21, 2019. It is now read-only.

Step definitions with optional regex matching groups doesn't work. #103

Open
borisbrodski opened this issue Apr 7, 2011 · 5 comments
Open

Comments

@borisbrodski
Copy link

Consider following step definition:
@then("^I( don't)? see the Text "([^"]*)"$")
public void seeOrDoesntSeeText(String dont, String text) {
if (dont != null) {
assertFalse(seeText(text));
} else {
assertTrue(seeText(text));
}
}

This step definition should work with both

  • I see the Text "abc"
    and
  • I doesn't see the Text "abc"

In Cuke4duke this produces IndexOutOfBounds exception in StepArgument class.
The problem is, that the matcher.start(1) returns -1, if "don't" not there. This causes wrong call to the StepArgument-constructor in the line

  • arguments.add(new StepArgument(matcher.group(i), matcher.start(i), stepName));
    in the JdkPatternArgumentMatcher class.
@JanAhrens
Copy link

Maybe it's just a typo, but in your example, you write "doesn't" and your regex contains "don't" ...

@borisbrodski
Copy link
Author

Yes, it's a type. Sorry for that.

@borisbrodski
Copy link
Author

I would like to point out, that the problem still exists. The typo is only in the posted example.

@bcluca
Copy link

bcluca commented Aug 23, 2011

Hi, I see you have the same issue here.

Have a look at #124 and the corresponding commit for a quick patch.
You can either check it out and build from source or wait for the pull request to be accepted.

Hope it helps.

@borisbrodski
Copy link
Author

Cool! Thank you very much.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants