1

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.

4

1 回答 1

1

我们遇到了同样的问题,但我们的解决方法是使用不同的措辞来区分步骤。据我了解,这不是您的选择。在这种情况下,我建议研究步骤优先级 - 您可以将更高的优先级设置为更长的步骤,因此会先尝试(请参阅 JBehave 文档:http: //jbehave.org/reference/stable/prioritising-steps.html) .

于 2013-08-07T14:48:23.620 回答