Details
Description
I have a story that looks like this:
Meta:
@themes Book
Scenario:
As a member I can return all my borrowed books at once.
Given an empty library
And a user <user> has borrowed books <isbns>
And a user <user2> has borrowed books <isbns2>
When user <user> returns all his books
Then books <isbns> are not borrowed anymore by user <user>
And books <isbns2> are still borrowed by user <user2>
Examples:
| user | isbns | user2 | isbns2 |
| user1@dings.com | 0321293533 | | |
| user1@dings.com | 0321293533 | user2@dings.com | 1234567962 |
| user1@dings.com | 0321293533 | user2@dings.com | 0321293533 |
| user1@dings.com | 0321293533 1234567962 | | |
| user1@dings.com | 0321293533 1234567962 | user2@dings.com | 1234567962 |
| user1@dings.com | 0321293533 1234567962 | user2@dings.com | 0321293533 1234567962 |
As you can see, I would like to reuse a step two times, with different parameter sets (user/isbns and user2/isbns2). JBehave forces me to wrote two different step definitions (two annotated methods), because the @Named actually pulls the value straight out of the examples table, regardless, of what parameters match the step.
So I am forced to do this. Very ugly, IMHO.
@Given("a user <user> has borrowed books <isbns>") public void createListOfBorrowedBooks(@Named("user") String user, @Named("isbns") String isbns) throws SQLException{ } @Given("a user <user2> has borrowed books <isbns2>") public void createListOfBorrowedBooks2(@Named("user2") String user, @Named("isbns2") String isbns) throws SQLException{ createListOfBorrowedBooks(user, isbns); }
I regarded the steps as something similar to a method or keyword, but now I realize that there are subtle differences.
As weird as Robot Frameworks syntax and grammar might be sometimes, it is coping much better with these circumstances.
Activity
Mauro Talevi
made changes -
Field | Original Value | New Value |
---|---|---|
Fix Version/s | 3.7.3 [ 18885 ] | |
Component/s | Core [ 11086 ] |
Mauro Talevi
made changes -
Status | Open [ 1 ] | Resolved [ 5 ] |
Resolution | Not A Bug [ 6 ] |
Mauro Talevi
made changes -
Fix Version/s | 3.7.4 [ 18964 ] | |
Fix Version/s | 3.7.3 [ 18885 ] |
Mauro Talevi
made changes -
Fix Version/s | 3.8 [ 19104 ] |
After some trial and error we found that using:
new MostUsefulConfiguration().useParameterControls(new ParameterControls("<", ">", true));
and implement steps as:
@Given("a user $user has borrowed books $isbns")
public void createListOfBorrowedBooks(String user, String isbns) throws SQLException{
}
gives a much more natural behaviour on how parameters are passed to step implementations.