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