| 1 |
@sequential |
| 2 |
Feature: Steps Catalog 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 |
However I am not interested in technical details such as |
| 8 |
source location and step function names. |
| 9 |
Also, I would prefer to view the step as they appear in a feature file. |
| 10 |
|
| 11 |
. SOLUTION: Use StepsDocFormatter in dry-run mode, like: |
| 12 |
. |
| 13 |
. behave --dry-run -f steps.catalog features/ |
| 14 |
|
| 15 |
|
| 16 |
@setup |
| 17 |
Scenario: Feature Setup |
| 18 |
Given a new working directory |
| 19 |
And a file named "features/steps/passing_steps.py" with: |
| 20 |
""" |
| 21 |
from behave import step |
| 22 |
|
| 23 |
@step('a step passes') |
| 24 |
def step_passes(context): |
| 25 |
'''This step always passes.''' |
| 26 |
pass |
| 27 |
|
| 28 |
@step('a step fails') |
| 29 |
def step_fails(context): |
| 30 |
'''This step is expected to fail.''' |
| 31 |
assert False, "XFAIL-STEP" |
| 32 |
""" |
| 33 |
And a file named "features/steps/alice_steps.py" with: |
| 34 |
""" |
| 35 |
from behave import given, when, then |
| 36 |
|
| 37 |
@given('{person} lives in {city}') |
| 38 |
def step_given_person_lives_in_city(context, person, city): |
| 39 |
''' |
| 40 |
Setup the data where a person lives and store in the database. |
| 41 |
|
| 42 |
:param person: Person's name (as string). |
| 43 |
:param city: City where the person lives (as string). |
| 44 |
''' |
| 45 |
database = getattr(context, "database", None) |
| 46 |
if not database: |
| 47 |
context.database = {} |
| 48 |
context.database[person] = { "city": city } |
| 49 |
|
| 50 |
@when('I visit {person}') |
| 51 |
def step_when_visit_person(context, person): |
| 52 |
# -- NO DOC-STRING. |
| 53 |
pass |
| 54 |
|
| 55 |
@then('I meet {person} in {city}') |
| 56 |
def step_then_meet_person_in_city(context, person, city): |
| 57 |
''' |
| 58 |
Checks if I can meet the person in the expected city. |
| 59 |
|
| 60 |
:param person: Person's name as key (as string). |
| 61 |
:param city: Expected city (as string). |
| 62 |
''' |
| 63 |
person_data = context.database.get(person, None) |
| 64 |
assert person_data is not None, "Person %s not found" % person |
| 65 |
assert person_data["city"] == city |
| 66 |
""" |
| 67 |
And an empty file named "features/none.feature" |
| 68 |
|
| 69 |
|
| 70 |
@usecase.primary |
| 71 |
Scenario: Show documentation of available step definitions in dry-run mode |
| 72 |
When I run "behave --steps-catalog features/" |
| 73 |
Then it should pass with: |
| 74 |
""" |
| 75 |
Given {person} lives in {city} |
| 76 |
Setup the data where a person lives and store in the database. |
| 77 |
|
| 78 |
:param person: Person's name (as string). |
| 79 |
:param city: City where the person lives (as string). |
| 80 |
|
| 81 |
When I visit {person} |
| 82 |
|
| 83 |
Then I meet {person} in {city} |
| 84 |
Checks if I can meet the person in the expected city. |
| 85 |
|
| 86 |
:param person: Person's name as key (as string). |
| 87 |
:param city: Expected city (as string). |
| 88 |
|
| 89 |
Given a step passes |
| 90 |
When a step passes |
| 91 |
Then a step passes |
| 92 |
This step always passes. |
| 93 |
|
| 94 |
Given a step fails |
| 95 |
When a step fails |
| 96 |
Then a step fails |
| 97 |
This step is expected to fail. |
| 98 |
""" |
| 99 |
But note that "the step definitions are ordered by step type" |
| 100 |
And note that "'When I visit {person}' has no doc-string" |