| 1 |
@issue |
| 2 |
@change_request |
| 3 |
Feature: Issue #112: Improvement to AmbiguousStep error |
| 4 |
|
| 5 |
. AmbiguousStep could be more useful if it also showed the existing string |
| 6 |
. with which the new one is clashing. This is particularly useful |
| 7 |
. if using step parameters. |
| 8 |
|
| 9 |
|
| 10 |
Background: |
| 11 |
Given a new working directory |
| 12 |
And a file named "features/syndrome112.feature" with: |
| 13 |
""" |
| 14 |
Feature: |
| 15 |
Scenario: |
| 16 |
Given I buy 10 oranges |
| 17 |
""" |
| 18 |
|
| 19 |
Scenario: Good step ordering -- From specific to generic regular expression |
| 20 |
Given a file named "features/steps/good_steps.py" with: |
| 21 |
""" |
| 22 |
from behave import given, when, then |
| 23 |
|
| 24 |
# -- ORDERING-IMPORTANT: From more specific steps to less specific. |
| 25 |
@given(u'I buy {number:n} {items:w}') |
| 26 |
def step_given_I_buy2(context, number, items): |
| 27 |
pass |
| 28 |
|
| 29 |
# -- OTHERWISE: Generic step matches all other patterns. |
| 30 |
@given(u'I buy {amount} {product}') |
| 31 |
def step_given_I_buy(context, amount, product): |
| 32 |
pass |
| 33 |
""" |
| 34 |
When I run "behave -c features/syndrome112.feature" |
| 35 |
Then it should pass with: |
| 36 |
""" |
| 37 |
1 feature passed, 0 failed, 0 skipped |
| 38 |
1 scenario passed, 0 failed, 0 skipped |
| 39 |
1 step passed, 0 failed, 0 skipped, 0 undefined |
| 40 |
""" |
| 41 |
|
| 42 |
|
| 43 |
Scenario: Bad step ordering causes AmbiguousStep |
| 44 |
Given a file named "features/steps/bad_steps.py" with: |
| 45 |
""" |
| 46 |
from behave import given, when, then |
| 47 |
|
| 48 |
# -- ORDERING-VIOLATED: Generic step comes first. |
| 49 |
@given(u'I buy {amount} {product}') |
| 50 |
def step_given_I_buy(context, amount, product): |
| 51 |
pass |
| 52 |
|
| 53 |
# -- AMBIGUOUS-STEP: Will occur here. |
| 54 |
@given(u'I buy {number:n} {items:w}') |
| 55 |
def step_given_I_buy2(context, number, items): |
| 56 |
pass |
| 57 |
""" |
| 58 |
When I run "behave -c features/syndrome112.feature" |
| 59 |
Then it should fail |
| 60 |
And the command output should contain: |
| 61 |
""" |
| 62 |
AmbiguousStep: @given('I buy {number:n} {items:w}') has already been defined in |
| 63 |
existing step @given('I buy {amount} {product}') at features/steps/bad_steps.py:4 |
| 64 |
""" |