[ 
https://jira.codehaus.org/browse/JBEHAVE-646?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=294953#comment-294953
 ] 

Arjan van Bentem commented on JBEHAVE-646:
------------------------------------------

If the following is true:

bq. Hence, you cannot use it in conjunction with the normal parameter matching, 
which uses natural ordering.

...then isn't the documentation at 
http://jbehave.org/reference/stable/parameter-injection.html wrong? It states:

bq. One reason to use named parameters is that then we can have method 
parameter appearing in any order:

{code}
@Given("a stock of symbol $symbol and a threshold of $threshold")
public void aStock(@Named("threshold") double aThreshold, @Named("symbol") 
String aSymbol) {
    // ...
}
{code}

I'm seeing the same issue when using slightly complicated regexs, such as a 
regex in which the parameters are not surrounded with whitespace.

For example, no issues, even though not all parameters are surrounded by 
whitespace:

{code}
// Ordered parameters, with whitespace
@Given("I have $a and $b")
public void givenAAndB(String myA, String myB) {
    LOG.info("given A={}, B={}", myA, myB);
    assertThat(myA).isEqualTo("1st");
    assertThat(myB).isEqualTo("2nd");
}

// Named parameters, in natural order, WITHOUT whitespace after $a
@When("doing $a, and $b")
public void whenAAndB(@Named("a") String myA, @Named("b") String myB) {
    LOG.info("when A={}, B={}", myA, myB);
    assertThat(myA).isEqualTo("this");
    assertThat(myB).isEqualTo("that");
}

// Named parameters, reversed order, with whitespace
@Then("we have $a or $b")
public void thenAOrdB(@Named("b") String myB, @Named("a") String myA) {
    LOG.info("then A={}, B={}", myA, myB);
    assertThat(myA).isEqualTo("success");
    assertThat(myB).isEqualTo("failure");
}
{code}

...but, troublesome when named parameters are not in the natural order, and not 
all parameters are fully surrounded with whitespace:

{code}
// Named parameters, reversed order, WITHOUT whitespace after $a
@Then("we have $a, $b")
// Same with comma and quotes: @Then("we have '$a', '$b'")
// Same without comma, with quotes: @Then("we have '$a' '$b'")
// No problem for: @Then("we have $a for you, $b")
public void thenACommaB(@Named("b") String myB, @Named("a") String myA) {
    // Will fail; parameters have been assigned in their natural order
    assertThat(myA).isEqualTo("a problem");
    assertThat(myB).isEqualTo("Houston");
}{code}

...with

{code}
Given I have 1st and 2nd
When doing this, and that
Then we have success or failure
And we have a problem, Houston
{code}

...I get:

{code}
Failed to run story login.story
org.junit.ComparisonFailure: expected:<'[a problem]'> but was:<'[Houston]'>
{code}

So it seems that parameters always need to be surrounded by whitespace?

(It's not so much an issue that a test would fail with PENDING, but silently 
falling back to the natural order doesn't seem to nice to me.)
                
> @Named not respecting parameter order
> -------------------------------------
>
>                 Key: JBEHAVE-646
>                 URL: https://jira.codehaus.org/browse/JBEHAVE-646
>             Project: JBehave
>          Issue Type: Bug
>            Reporter: Diego Rivera
>
> @Named doesn't seem to do its job, and parameter ordering in the method 
> declaration seems to confuse the assignment code.  For instance:
> "Given a $var1 with $var2 and $var3"
> void testVars(@Named("var3") String var3, @Named("var1") String var1, 
> @Named("var2") String var2)
> When executing testVars, it assigns var3=$var3, var1=$var1, but var2=$var3
> Clearly, the correct assignment is var2=$var2

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://jira.codehaus.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply via email to