Debian Codegraph @

issue.features/issue0191.feature

raw
1 @issue
2 Feature: Issue #191 Using context.execute_steps() may change context.table/.text
3
4 . PROBLEM DESCRIPTION:
5 . When you execute nested steps via "context.execute_steps()" in a
6 . step implementation, the following context attributes of the current step
7 . may be modified and may be longer valid:
8 . * context.text (multi-line text)
9 . * context.table
10
11
12 @setup
13 Scenario: Feature Setup
14 Given a new working directory
15 And a file named "features/steps/common_steps.py" with:
16 """
17 from behave import given, step
18
19 @step('{word:w} step passes')
20 def step_passes(context, word):
21 pass
22
23 @given('I define the following nested steps')
24 def step_define_nested_steps(context):
25 assert context.text is not None, "REQUIRE: text"
26 context.nested_steps = context.text
27 """
28 And a file named "features/steps/table_steps.py" with:
29 """
30 from behave import when, then, step
31
32 @step('I use another table with')
33 def step_use_another_table_with(context):
34 assert context.table, "REQUIRE: table"
35 context.nested_table = context.table
36
37 @when('I execute the nested steps and use the table')
38 def step_execute_nested_steps_and_use_table(context):
39 assert context.table, "REQUIRE: table"
40 assert context.nested_steps, "REQUIRE: context.nested_steps"
41 context.my_table1 = context.table
42 context.execute_steps(context.nested_steps)
43 context.my_table2 = context.table
44
45 @then('the original table is restored after the nested steps are executed')
46 def step_table_is_restored(context):
47 assert context.my_table1 is not None
48 assert context.my_table2 is not None
49 assert context.my_table1 is context.my_table2
50 """
51 And a file named "features/steps/text_steps.py" with:
52 """
53 from behave import when, then, step
54
55 @step('I use another step with text "{text}"')
56 def step_use_another_text_with(context, text):
57 assert context.text is None
58 context.text = text # -- MODIFY: context.text (emulation)
59
60 @step('I use another text with')
61 def step_use_another_text_with(context):
62 assert context.text is not None, "REQUIRE: text"
63 context.nested_text = context.text
64
65 @when('I execute the nested steps and use the text')
66 def step_execute_nested_steps_and_use_text(context):
67 assert context.text is not None, "REQUIRE: text"
68 assert context.nested_steps, "REQUIRE: context.nested_steps"
69 context.my_text1 = context.text
70 context.execute_steps(context.nested_steps)
71 context.my_text2 = context.text
72
73 @then('the original text is restored after the nested steps are executed')
74 def step_text_is_restored(context):
75 assert context.my_text1 is not None
76 assert context.my_text2 is not None
77 assert context.my_text1 is context.my_text2
78 """
79
80 @nested_steps.with_table
81 Scenario: After executing simple nested steps the original table is restored
82 Given a file named "features/example.nested_simple_steps_and_table.feature" with:
83 """
84 Feature:
85 Scenario:
86 Given I define the following nested steps:
87 '''
88 Given a step passes
89 When another step passes
90 '''
91 When I execute the nested steps and use the table:
92 | Name | Age |
93 | Alice | 21 |
94 | Bob | 32 |
95 Then the original table is restored after the nested steps are executed
96 """
97 When I run "behave -f plain -T features/example.nested_simple_steps_and_table.feature"
98 Then it should pass with:
99 """
100 1 scenario passed, 0 failed, 0 skipped
101 3 steps passed, 0 failed, 0 skipped, 0 undefined
102 """
103
104 @nested_steps.with_table
105 Scenario: After executing nested steps with a table the original table is restored
106 Given a file named "features/example.nested_steps_and_table.feature" with:
107 """
108 Feature:
109 Scenario:
110 Given I define the following nested steps:
111 '''
112 Given I use another table with:
113 | Person | Registered |
114 | Anton | true |
115 | Barby | false |
116 '''
117 When I execute the nested steps and use the table:
118 | Name | Age |
119 | Charly | 41 |
120 | Doro | 52 |
121 Then the original table is restored after the nested steps are executed
122 """
123 When I run "behave -f plain -T features/example.nested_steps_and_table.feature"
124 Then it should pass with:
125 """
126 1 scenario passed, 0 failed, 0 skipped
127 3 steps passed, 0 failed, 0 skipped, 0 undefined
128 """
129
130
131 @nested_steps.with_text
132 Scenario: After executing simple nested steps the original text is restored
133 Given a file named "features/example.nested_simple_steps_and_text.feature" with:
134 """
135 Feature:
136 Scenario:
137 Given I define the following nested steps:
138 '''
139 Given a step passes
140 When another step passes
141 '''
142 When I execute the nested steps and use the text:
143 '''
144 Lorem ipsum
145 Ipsum lorem
146 '''
147 Then the original text is restored after the nested steps are executed
148 """
149 When I run "behave -f plain -T features/example.nested_simple_steps_and_text.feature"
150 Then it should pass with:
151 """
152 1 scenario passed, 0 failed, 0 skipped
153 3 steps passed, 0 failed, 0 skipped, 0 undefined
154 """
155
156 @nested_steps.with_text
157 Scenario: After executing nested steps with a text the original text is restored
158 Given a file named "features/example.nested_steps_and_text.feature" with:
159 """
160 Feature:
161 Scenario:
162 Given I define the following nested steps:
163 '''
164 Given I use another step with text "Hello Alice"
165 '''
166 When I execute the nested steps and use the text:
167 '''
168 Lorem ipsum
169 Ipsum lorem
170 '''
171 Then the original text is restored after the nested steps are executed
172 """
173 When I run "behave -f plain -T features/example.nested_steps_and_text.feature"
174 Then it should pass with:
175 """
176 1 scenario passed, 0 failed, 0 skipped
177 3 steps passed, 0 failed, 0 skipped, 0 undefined
178 """