Debian Codegraph @

issue.features/issue0081.feature

raw
1 @issue
2 Feature: Issue #81: Allow defining steps in a separate library
3
4 . The current design forces steps.py to be in a particular folder.
5 . This does not allow to reuse a common library of BDD steps across
6 . multiple software projects in a company.
7 . It would be great if one could define a separate lib with common steps
8 . (e.g. steps4mycompany.py)
9
10
11 Background: Test Setup
12 Given a new working directory
13 And an empty file named "step_library42/__init__.py"
14 And a file named "step_library42/alice_steps.py" with:
15 """
16 # -- ALICE-STEPS: Anonymous step names.
17 from behave import given, when, then
18
19 @given(u'I use the step library "{library}"')
20 def step(context, library):
21 pass
22
23 @when(u'I use steps from this step library')
24 def step(context):
25 pass
26
27 @then(u'these steps are executed')
28 def step(context):
29 pass
30 """
31 And a file named "features/use_step_library.feature" with:
32 """
33 Feature:
34 Scenario:
35 Given I use the step library "alice"
36 When I use steps from this step library
37 Then these steps are executed
38 """
39
40 Scenario: Proof of Concept
41 Given a file named "features/steps/use_step_libs.py" with:
42 """
43 from step_library42.alice_steps import *
44 """
45 When I run "behave --no-timings -f plain features/use_step_library.feature"
46 Then it should pass with:
47 """
48 1 scenario passed, 0 failed, 0 skipped
49 3 steps passed, 0 failed, 0 skipped, 0 undefined
50 """
51 And the command output should contain:
52 """
53 Feature:
54 Scenario:
55 Given I use the step library "alice" ... passed
56 When I use steps from this step library ... passed
57 Then these steps are executed ... passed
58 """
59
60 Scenario: With --format=pretty
61 Given a file named "features/steps/use_step_libs.py" with:
62 """
63 from step_library42.alice_steps import *
64 """
65 When I run "behave -c -f pretty features/use_step_library.feature"
66 Then it should pass with:
67 """
68 1 scenario passed, 0 failed, 0 skipped
69 3 steps passed, 0 failed, 0 skipped, 0 undefined
70 """
71 And the command output should contain:
72 """
73 Feature: # features/use_step_library.feature:1
74 Scenario: # features/use_step_library.feature:2
75 Given I use the step library "alice" # step_library42/alice_steps.py:4
76 When I use steps from this step library # step_library42/alice_steps.py:8
77 Then these steps are executed # step_library42/alice_steps.py:12
78 """
79
80 Scenario: Selective step import from step library
81 Given a file named "step_library42/bob_steps.py" with:
82 """
83 # -- BOB-STEPS: Explicit step function names (otherwise same as alice).
84 from behave import given, when, then
85
86 @given(u'I use the step library "{library}"')
87 def given_I_use_the_step_library(context, library):
88 pass
89
90 @when(u'I use steps from this step library')
91 def when_I_use_steps_from_this_step_library(context):
92 pass
93
94 @then(u'these steps are executed')
95 def then_these_steps_are_executed(context):
96 pass
97 """
98 And a file named "features/steps/use_step_libs.py" with:
99 """
100 from step_library42.bob_steps import given_I_use_the_step_library
101 from step_library42.bob_steps import when_I_use_steps_from_this_step_library
102 from step_library42.bob_steps import then_these_steps_are_executed
103 """
104 When I run "behave -c -f pretty features/use_step_library.feature"
105 Then it should pass with:
106 """
107 1 scenario passed, 0 failed, 0 skipped
108 3 steps passed, 0 failed, 0 skipped, 0 undefined
109 """
110 And the command output should contain:
111 """
112 Feature: # features/use_step_library.feature:1
113 Scenario: # features/use_step_library.feature:2
114 Given I use the step library "alice" # step_library42/bob_steps.py:4
115 When I use steps from this step library # step_library42/bob_steps.py:8
116 Then these steps are executed # step_library42/bob_steps.py:12
117 """
118
119 Scenario: Import step library in "environment.py"
120 Given a file named "features/environment.py" with:
121 """
122 from step_library42.alice_steps import *
123 """
124 And an empty file named "features/steps/__init__.py"
125 When I run "behave -c -f pretty features/use_step_library.feature"
126 Then it should pass with:
127 """
128 1 scenario passed, 0 failed, 0 skipped
129 3 steps passed, 0 failed, 0 skipped, 0 undefined
130 """
131 And the command output should contain:
132 """
133 Feature: # features/use_step_library.feature:1
134 Scenario: # features/use_step_library.feature:2
135 Given I use the step library "alice" # step_library42/alice_steps.py:4
136 When I use steps from this step library # step_library42/alice_steps.py:8
137 Then these steps are executed # step_library42/alice_steps.py:12
138 """