Question

I have two similarly worded steps, but still different enough (I would hope):

@When("I send $method '$url'")
public void sendMethodURL(
    @Named("method") final String method,
    @Named("url") final String url)
{
    // stuff
}

@When("I send $method '$url' with JSON '$body'")
public void sendMethodURLBody(
    @Named("method") final String method,
    @Named("url") final String url,
    @Named("body") final String inputJSON)
{
    // stuff
}

However, in my story, I have:

When I send POST '/blah/foo/bar' with JSON '["some", "json"]'

Yet it's calling sendMethodURL where method is "POST '/blah/foo/bar' with JSON" and url is "[\"some\", \"json\"]". Clearly, I'd rather it call sendMethodURLBody instead.

What am I doing wrong here? How can I get JBehave to differentiate between the two steps?

Edit: I realize it's the RegexStepMatcher matching the first @When it finds that matches (which is sendMethodURL)... but how can I keep the grammar as it is, but differentiate the two so it no longer matches both steps? The order of the methods seems to work, but there must be a less fragile way.

Was it helpful?

Solution

We had same problem, but our workaround is to use different wording to distinguish steps from each other. As far as I understand this is not an option for you. In this case I would recomment to look into steps prioritization - you can set higher priority to longer step, so it would be tried first (see JBehave documentation: http://jbehave.org/reference/stable/prioritising-steps.html).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top