| 1 |
@sequential |
| 2 |
Feature: Steps Doc Formatter |
| 3 |
|
| 4 |
As a test writer |
| 5 |
I want to get a quick overview how to use a step definition |
| 6 |
By reading the step definition documentation (doc-stings). |
| 7 |
|
| 8 |
. SOLUTION: Use StepsDocFormatter in dry-run mode, like: |
| 9 |
. |
| 10 |
. behave --dry-run -f steps.doc features/ |
| 11 |
|
| 12 |
|
| 13 |
@setup |
| 14 |
Scenario: Feature Setup |
| 15 |
Given a new working directory |
| 16 |
And a file named "features/steps/passing_steps.py" with: |
| 17 |
""" |
| 18 |
from behave import step |
| 19 |
|
| 20 |
@step('a step passes') |
| 21 |
def step_passes(context): |
| 22 |
'''This step always passes.''' |
| 23 |
pass |
| 24 |
|
| 25 |
@step('a step fails') |
| 26 |
def step_fails(context): |
| 27 |
'''This step is expected to fail.''' |
| 28 |
assert False, "XFAIL-STEP" |
| 29 |
""" |
| 30 |
And a file named "features/steps/alice_steps.py" with: |
| 31 |
""" |
| 32 |
from behave import given, when, then |
| 33 |
|
| 34 |
@given('{person} lives in {city}') |
| 35 |
def step_given_person_lives_in_city(context, person, city): |
| 36 |
''' |
| 37 |
Setup the data where a person lives and store in the database. |
| 38 |
|
| 39 |
:param person: Person's name (as string). |
| 40 |
:param city: City where the person lives (as string). |
| 41 |
''' |
| 42 |
database = getattr(context, "database", None) |
| 43 |
if not database: |
| 44 |
context.database = {} |
| 45 |
context.database[person] = { "city": city } |
| 46 |
|
| 47 |
@when('I visit {person}') |
| 48 |
def step_when_visit_person(context, person): |
| 49 |
# -- NO DOC-STRING. |
| 50 |
pass |
| 51 |
|
| 52 |
@then('I meet {person} in {city}') |
| 53 |
def step_then_meet_person_in_city(context, person, city): |
| 54 |
''' |
| 55 |
Checks if I can meet the person in the expected city. |
| 56 |
|
| 57 |
:param person: Person's name as key (as string). |
| 58 |
:param city: Expected city (as string). |
| 59 |
''' |
| 60 |
person_data = context.database.get(person, None) |
| 61 |
assert person_data is not None, "Person %s not found" % person |
| 62 |
assert person_data["city"] == city |
| 63 |
""" |
| 64 |
And an empty file named "features/none.feature" |
| 65 |
|
| 66 |
|
| 67 |
@usecase.primary |
| 68 |
Scenario: Show documentation of available step definitions in dry-run mode |
| 69 |
When I run "behave --dry-run -f steps.doc features/" |
| 70 |
Then it should pass with: |
| 71 |
""" |
| 72 |
@given('{person} lives in {city}') |
| 73 |
Function: step_given_person_lives_in_city() |
| 74 |
Location: features/steps/alice_steps.py:3 |
| 75 |
Setup the data where a person lives and store in the database. |
| 76 |
|
| 77 |
:param person: Person's name (as string). |
| 78 |
:param city: City where the person lives (as string). |
| 79 |
|
| 80 |
@when('I visit {person}') |
| 81 |
Function: step_when_visit_person() |
| 82 |
Location: features/steps/alice_steps.py:16 |
| 83 |
|
| 84 |
@then('I meet {person} in {city}') |
| 85 |
Function: step_then_meet_person_in_city() |
| 86 |
Location: features/steps/alice_steps.py:21 |
| 87 |
Checks if I can meet the person in the expected city. |
| 88 |
|
| 89 |
:param person: Person's name as key (as string). |
| 90 |
:param city: Expected city (as string). |
| 91 |
|
| 92 |
@step('a step passes') |
| 93 |
Function: step_passes() |
| 94 |
Location: features/steps/passing_steps.py:3 |
| 95 |
This step always passes. |
| 96 |
|
| 97 |
@step('a step fails') |
| 98 |
Function: step_fails() |
| 99 |
Location: features/steps/passing_steps.py:8 |
| 100 |
This step is expected to fail. |
| 101 |
""" |
| 102 |
But note that "the step definitions are ordered by file location" |
| 103 |
And note that "@when('I visit {person}') has no doc-string" |
| 104 |
|
| 105 |
|
| 106 |
@usecase.secondary |
| 107 |
Scenario: Show documentation of available step definitions in normal mode |
| 108 |
When I run "behave -f steps.doc features/" |
| 109 |
Then it should pass with: |
| 110 |
""" |
| 111 |
@given('{person} lives in {city}') |
| 112 |
Function: step_given_person_lives_in_city() |
| 113 |
Location: features/steps/alice_steps.py:3 |
| 114 |
Setup the data where a person lives and store in the database. |
| 115 |
|
| 116 |
:param person: Person's name (as string). |
| 117 |
:param city: City where the person lives (as string). |
| 118 |
|
| 119 |
@when('I visit {person}') |
| 120 |
Function: step_when_visit_person() |
| 121 |
Location: features/steps/alice_steps.py:16 |
| 122 |
|
| 123 |
@then('I meet {person} in {city}') |
| 124 |
Function: step_then_meet_person_in_city() |
| 125 |
Location: features/steps/alice_steps.py:21 |
| 126 |
Checks if I can meet the person in the expected city. |
| 127 |
|
| 128 |
:param person: Person's name as key (as string). |
| 129 |
:param city: Expected city (as string). |
| 130 |
|
| 131 |
@step('a step passes') |
| 132 |
Function: step_passes() |
| 133 |
Location: features/steps/passing_steps.py:3 |
| 134 |
This step always passes. |
| 135 |
|
| 136 |
@step('a step fails') |
| 137 |
Function: step_fails() |
| 138 |
Location: features/steps/passing_steps.py:8 |
| 139 |
This step is expected to fail. |
| 140 |
""" |