| 1 |
Feature: Execute nested steps that use a table |
| 2 |
|
| 3 |
Scenario: |
| 4 |
Given a new working directory |
| 5 |
And a file named "features/steps/steps.py" with: |
| 6 |
""" |
| 7 |
from behave import given, when, then, step |
| 8 |
import six |
| 9 |
@given('the following nested steps') |
| 10 |
def step_given_following_nested_steps(context): |
| 11 |
assert context.text, "ENSURE: multi-line text is provided." |
| 12 |
context.nested_steps = six.text_type(context.text) |
| 13 |
|
| 14 |
@step('I execute the nested steps {comment}') |
| 15 |
def step_execute_nested_steps_with_table(context, comment): |
| 16 |
assert context.nested_steps, "ENSURE: nested steps are provided." |
| 17 |
context.execute_steps(context.nested_steps) |
| 18 |
|
| 19 |
@then('the step "{expected_step}" was called') |
| 20 |
def then_step_was_called(context, expected_step): |
| 21 |
assert context.steps_called, "ENSURE: steps_called is provided." |
| 22 |
assert expected_step in context.steps_called |
| 23 |
|
| 24 |
@then('the table should be equal to') |
| 25 |
def then_table_should_be_equal_to(context): |
| 26 |
assert context.table, "ENSURE: table is provided." |
| 27 |
expected_table = context.table |
| 28 |
actual_table = context.the_table |
| 29 |
assert actual_table == expected_table |
| 30 |
|
| 31 |
# -- SPECIAL-STEP: |
| 32 |
@step('I setup an address book with') |
| 33 |
def step_setup_address_book_with_friends(context): |
| 34 |
assert context.table, "ENSURE: table is provided." |
| 35 |
if not hasattr(context, "steps_called"): |
| 36 |
context.steps_called = [] |
| 37 |
context.steps_called.append("I setup an address book with") |
| 38 |
context.the_table = context.table |
| 39 |
""" |
| 40 |
And a file named "features/execute_nested_steps_with_table.feature" with: |
| 41 |
''' |
| 42 |
Feature: |
| 43 |
Scenario: |
| 44 |
Given the following nested steps: |
| 45 |
""" |
| 46 |
When I setup an address book with: |
| 47 |
| Name | Telephone Number | |
| 48 |
| Alice | 555 1111 | |
| 49 |
| Bob | 555 2222 | |
| 50 |
""" |
| 51 |
When I execute the nested steps with a table |
| 52 |
Then the step "I setup an address book with" was called |
| 53 |
And the table should be equal to: |
| 54 |
| Name | Telephone Number | |
| 55 |
| Alice | 555 1111 | |
| 56 |
| Bob | 555 2222 | |
| 57 |
''' |
| 58 |
When I run "behave -f plain features/execute_nested_steps_with_table.feature" |
| 59 |
Then it should pass with: |
| 60 |
""" |
| 61 |
1 feature passed, 0 failed, 0 skipped |
| 62 |
1 scenario passed, 0 failed, 0 skipped |
| 63 |
4 steps passed, 0 failed, 0 skipped, 0 undefined |
| 64 |
""" |
| 65 |
|