Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JBehave ambiguous step

Say I have:

@Given("first name is $firstName")
@Given("first name is $firstName and last name is $lastName")

The following step would be marked as ambiguous:

Given first name is John and last name is Smith

Without using quotes to surround the first parameter, how can I fix this step so it only matches the second one? Using quotes to surround both the parameters separately also has the same ambiguity issue.

Is there a limit on how long each parameter is? Are there certain characters that can't be passed in?

like image 487
user1877292 Avatar asked Dec 04 '12 23:12

user1877292


2 Answers

You can solve this by using step priorities, as documented here: http://jbehave.org/reference/stable/prioritising-steps.html

Your problem would be solved by setting a higher priority to the variant with two parameters:

@Given("first name is $firstName")
@Given(value = "first name is $firstName and last name is $lastName", priority = 1)

I tried your example and with this combination, the two steps were separated.

(Edit: my initial solution had quotes for the parameters, but it works without as well)

like image 120
dertseha Avatar answered Nov 12 '22 08:11

dertseha


I think this scenario can be write this way:

Given first name is John
And last name is Smith

And the steps:

@Given("first name is $firstName")
@And("last name is $lastName")

You can create the person object first an set the name and the last name in the "@Given" steps.
If you need add another property, like email, you just need create another step:

@And("the email is $email")
public addEmail(String email) {
    person.setEmail(email);
}

So this problem not gonna happen and you code will be more reusable.

like image 1
Andre Piantino Avatar answered Nov 12 '22 08:11

Andre Piantino