| 1 |
Feature: Execute Steps within a Step Function (Nested Steps) |
| 2 |
|
| 3 |
As a tester |
| 4 |
I want to reuse existing steps and call several ones within another step |
| 5 |
So that I can comply with the the DRY principle. |
| 6 |
|
| 7 |
Scenario: Execute a number of simple steps (GOOD CASE) |
| 8 |
Given a new working directory |
| 9 |
And a file named "features/steps/steps.py" with: |
| 10 |
""" |
| 11 |
from behave import given, when, then |
| 12 |
|
| 13 |
@given(u'I go to the supermarket') |
| 14 |
def step_given_I_go_to_the_supermarket(context): |
| 15 |
context.shopping_cart = {} |
| 16 |
|
| 17 |
@when(u'I buy {amount:n} {item:w}') |
| 18 |
def step_when_I_buy(context, amount, item): |
| 19 |
assert amount >= 0 |
| 20 |
if not item in context.shopping_cart: |
| 21 |
context.shopping_cart[item] = 0 |
| 22 |
context.shopping_cart[item] += amount |
| 23 |
|
| 24 |
# -- HERE: Is the interesting functionality. |
| 25 |
@when(u'I buy the usual things') |
| 26 |
def step_when_I_buy_the_usual_things(context): |
| 27 |
context.execute_steps(u''' |
| 28 |
When I buy 2 apples |
| 29 |
And I buy 3 bananas |
| 30 |
''') |
| 31 |
|
| 32 |
@then(u'I have {amount:n} {item:w}') |
| 33 |
def step_then_I_have(context, amount, item): |
| 34 |
actual = context.shopping_cart.get(item, 0) |
| 35 |
assert amount == actual |
| 36 |
""" |
| 37 |
And a file named "features/use_nested_steps.feature" with: |
| 38 |
""" |
| 39 |
Feature: |
| 40 |
Scenario: |
| 41 |
Given I go to the supermarket |
| 42 |
When I buy the usual things |
| 43 |
Then I have 2 apples |
| 44 |
And I have 3 bananas |
| 45 |
""" |
| 46 |
When I run "behave -f plain features/use_nested_steps.feature" |
| 47 |
Then it should pass with: |
| 48 |
""" |
| 49 |
1 feature passed, 0 failed, 0 skipped |
| 50 |
1 scenario passed, 0 failed, 0 skipped |
| 51 |
4 steps passed, 0 failed, 0 skipped, 0 undefined |
| 52 |
""" |
| 53 |
|
| 54 |
@not_implemented |
| 55 |
Scenario: A Nested Step Fails with Assert |
| 56 |
|
| 57 |
@not_implemented |
| 58 |
Scenario: A Nested Step Fails with Exception |
| 59 |
|