cucumber-core 10.1.1 → 11.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +203 -284
- data/README.md +0 -1
- data/lib/cucumber/core/test/case.rb +11 -1
- data/lib/cucumber/core/test/data_table.rb +4 -0
- data/lib/cucumber/core/test/doc_string.rb +4 -1
- data/lib/cucumber/core/test/empty_multiline_argument.rb +2 -2
- data/lib/cucumber/core/test/filters/locations_filter.rb +1 -1
- data/lib/cucumber/core/test/location.rb +15 -5
- data/lib/cucumber/core/test/step.rb +4 -0
- metadata +29 -94
- data/lib/cucumber/core/version.rb +0 -10
- data/spec/coverage.rb +0 -12
- data/spec/cucumber/core/compiler_spec.rb +0 -241
- data/spec/cucumber/core/event_bus_spec.rb +0 -163
- data/spec/cucumber/core/event_spec.rb +0 -40
- data/spec/cucumber/core/filter_spec.rb +0 -101
- data/spec/cucumber/core/gherkin/parser_spec.rb +0 -162
- data/spec/cucumber/core/gherkin/writer_spec.rb +0 -332
- data/spec/cucumber/core/report/summary_spec.rb +0 -178
- data/spec/cucumber/core/test/action_spec.rb +0 -153
- data/spec/cucumber/core/test/case_spec.rb +0 -125
- data/spec/cucumber/core/test/data_table_spec.rb +0 -79
- data/spec/cucumber/core/test/doc_string_spec.rb +0 -111
- data/spec/cucumber/core/test/duration_matcher.rb +0 -20
- data/spec/cucumber/core/test/empty_multiline_argument_spec.rb +0 -28
- data/spec/cucumber/core/test/filters/locations_filter_spec.rb +0 -271
- data/spec/cucumber/core/test/location_spec.rb +0 -129
- data/spec/cucumber/core/test/result_spec.rb +0 -504
- data/spec/cucumber/core/test/runner_spec.rb +0 -320
- data/spec/cucumber/core/test/step_spec.rb +0 -88
- data/spec/cucumber/core/test/timer_spec.rb +0 -25
- data/spec/cucumber/core_spec.rb +0 -262
- data/spec/report_api_spy.rb +0 -25
@@ -1,332 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require 'cucumber/core/gherkin/writer'
|
3
|
-
require 'unindent'
|
4
|
-
|
5
|
-
module Cucumber::Core::Gherkin
|
6
|
-
describe Writer do
|
7
|
-
include Writer
|
8
|
-
|
9
|
-
context 'specifying uri' do
|
10
|
-
it 'generates a uri by default' do
|
11
|
-
source = gherkin { feature }
|
12
|
-
expect( source.uri ).to eq 'features/test.feature'
|
13
|
-
end
|
14
|
-
|
15
|
-
it 'allows you to specify a URI' do
|
16
|
-
source = gherkin('features/path/to/my.feature') { feature }
|
17
|
-
expect( source.uri ).to eq 'features/path/to/my.feature'
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
context 'a feature' do
|
22
|
-
|
23
|
-
it 'generates the feature statement' do
|
24
|
-
source = gherkin { feature }
|
25
|
-
expect( source ).to eq "Feature:\n"
|
26
|
-
end
|
27
|
-
|
28
|
-
context 'when a name is provided' do
|
29
|
-
it 'includes the name in the feature statement' do
|
30
|
-
source = gherkin do
|
31
|
-
feature "A Feature\n"
|
32
|
-
end
|
33
|
-
expect( source ).to eq "Feature: A Feature\n"
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
context 'when a description is provided' do
|
38
|
-
it 'includes the description in the feature statement' do
|
39
|
-
source = gherkin do
|
40
|
-
feature "A Feature", description: <<-END
|
41
|
-
This is the description
|
42
|
-
which can span
|
43
|
-
multiple lines.
|
44
|
-
END
|
45
|
-
end
|
46
|
-
expected = <<-END
|
47
|
-
Feature: A Feature
|
48
|
-
This is the description
|
49
|
-
which can span
|
50
|
-
multiple lines.
|
51
|
-
END
|
52
|
-
|
53
|
-
expect( source ).to eq expected.unindent
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
context 'when a keyword is provided' do
|
58
|
-
it 'uses the supplied keyword' do
|
59
|
-
source = gherkin do
|
60
|
-
feature "A Feature", keyword: "Business Need"
|
61
|
-
end
|
62
|
-
expect( source ).to eq "Business Need: A Feature\n"
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
context 'when a language is supplied' do
|
67
|
-
it 'inserts a language statement' do
|
68
|
-
source = gherkin do
|
69
|
-
feature language: 'ru'
|
70
|
-
end
|
71
|
-
|
72
|
-
expect( source ).to eq "# language: ru\nFeature:\n"
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
context 'when a comment is supplied' do
|
77
|
-
it 'inserts a comment' do
|
78
|
-
source = gherkin do
|
79
|
-
comment 'wow'
|
80
|
-
comment 'great'
|
81
|
-
feature
|
82
|
-
end
|
83
|
-
|
84
|
-
expect( source.to_s ).to eq "# wow\n# great\nFeature:\n"
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
context 'with a scenario' do
|
89
|
-
it 'includes the scenario statement' do
|
90
|
-
source = gherkin do
|
91
|
-
feature "A Feature" do
|
92
|
-
scenario
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
expect( source.to_s ).to match(/Scenario:/)
|
97
|
-
end
|
98
|
-
|
99
|
-
context 'when a comment is provided' do
|
100
|
-
it 'includes the comment in the scenario statement' do
|
101
|
-
source = gherkin do
|
102
|
-
feature do
|
103
|
-
comment 'wow'
|
104
|
-
scenario
|
105
|
-
end
|
106
|
-
end
|
107
|
-
expect( source.to_s ).to eq <<-END.unindent
|
108
|
-
Feature:
|
109
|
-
|
110
|
-
# wow
|
111
|
-
Scenario:
|
112
|
-
END
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
context 'when a description is provided' do
|
117
|
-
it 'includes the description in the scenario statement' do
|
118
|
-
source = gherkin do
|
119
|
-
feature do
|
120
|
-
scenario description: <<-END
|
121
|
-
This is the description
|
122
|
-
which can span
|
123
|
-
multiple lines.
|
124
|
-
END
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
expect( source ).to eq <<-END.unindent
|
129
|
-
Feature:
|
130
|
-
|
131
|
-
Scenario:
|
132
|
-
This is the description
|
133
|
-
which can span
|
134
|
-
multiple lines.
|
135
|
-
END
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
context 'with a step' do
|
140
|
-
it 'includes the step statement' do
|
141
|
-
source = gherkin do
|
142
|
-
feature "A Feature" do
|
143
|
-
scenario do
|
144
|
-
step 'passing'
|
145
|
-
end
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
expect( source.to_s ).to match(/Given passing\Z/m)
|
150
|
-
end
|
151
|
-
|
152
|
-
context 'when a docstring is provided' do
|
153
|
-
it 'includes the content type when provided' do
|
154
|
-
source = gherkin do
|
155
|
-
feature do
|
156
|
-
scenario do
|
157
|
-
step 'failing' do
|
158
|
-
doc_string 'some text', 'text/plain'
|
159
|
-
end
|
160
|
-
end
|
161
|
-
end
|
162
|
-
|
163
|
-
end
|
164
|
-
|
165
|
-
expect( source ).to eq <<-END.unindent
|
166
|
-
Feature:
|
167
|
-
|
168
|
-
Scenario:
|
169
|
-
Given failing
|
170
|
-
"""text/plain
|
171
|
-
some text
|
172
|
-
"""
|
173
|
-
END
|
174
|
-
end
|
175
|
-
end
|
176
|
-
end
|
177
|
-
end
|
178
|
-
|
179
|
-
context 'with a background' do
|
180
|
-
it 'can have a description' do
|
181
|
-
source = gherkin do
|
182
|
-
feature do
|
183
|
-
background description: "One line,\nand two.."
|
184
|
-
end
|
185
|
-
end
|
186
|
-
|
187
|
-
expect( source ).to eq <<-END.unindent
|
188
|
-
Feature:
|
189
|
-
|
190
|
-
Background:
|
191
|
-
One line,
|
192
|
-
and two..
|
193
|
-
END
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|
197
|
-
context 'with a scenario outline' do
|
198
|
-
it 'can have a description' do
|
199
|
-
source = gherkin do
|
200
|
-
feature do
|
201
|
-
scenario_outline description: "Doesn't need to be multi-line."
|
202
|
-
end
|
203
|
-
end
|
204
|
-
|
205
|
-
expect( source ).to eq <<-END.unindent
|
206
|
-
Feature:
|
207
|
-
|
208
|
-
Scenario Outline:
|
209
|
-
Doesn't need to be multi-line.
|
210
|
-
END
|
211
|
-
end
|
212
|
-
|
213
|
-
context 'and examples table' do
|
214
|
-
it 'can have a description' do
|
215
|
-
source = gherkin do
|
216
|
-
feature do
|
217
|
-
scenario_outline do
|
218
|
-
examples description: "Doesn't need to be multi-line." do
|
219
|
-
|
220
|
-
end
|
221
|
-
end
|
222
|
-
end
|
223
|
-
end
|
224
|
-
|
225
|
-
expect( source ).to eq <<-END.unindent
|
226
|
-
Feature:
|
227
|
-
|
228
|
-
Scenario Outline:
|
229
|
-
|
230
|
-
Examples:
|
231
|
-
Doesn't need to be multi-line.
|
232
|
-
END
|
233
|
-
end
|
234
|
-
end
|
235
|
-
end
|
236
|
-
end
|
237
|
-
|
238
|
-
it 'generates a complex feature' do
|
239
|
-
source = gherkin do
|
240
|
-
comment 'wow'
|
241
|
-
feature 'Fully featured', language: 'en', tags: '@always' do
|
242
|
-
comment 'cool'
|
243
|
-
background do
|
244
|
-
step 'passing'
|
245
|
-
end
|
246
|
-
|
247
|
-
scenario do
|
248
|
-
step 'passing'
|
249
|
-
end
|
250
|
-
|
251
|
-
comment 'here'
|
252
|
-
scenario 'with doc string', tags: '@first @second' do
|
253
|
-
comment 'and here'
|
254
|
-
step 'passing'
|
255
|
-
step 'failing', keyword: 'When' do
|
256
|
-
doc_string <<-END
|
257
|
-
I wish I was a little bit taller.
|
258
|
-
I wish I was a baller.
|
259
|
-
END
|
260
|
-
end
|
261
|
-
end
|
262
|
-
|
263
|
-
scenario 'with a table...' do
|
264
|
-
step 'passes:' do
|
265
|
-
table do
|
266
|
-
row 'name', 'age', 'location'
|
267
|
-
row 'Janine', '43', 'Antarctica'
|
268
|
-
end
|
269
|
-
end
|
270
|
-
end
|
271
|
-
|
272
|
-
comment 'yay'
|
273
|
-
scenario_outline 'eating' do
|
274
|
-
step 'there are <start> cucumbers'
|
275
|
-
step 'I eat <eat> cucumbers', keyword: 'When'
|
276
|
-
step 'I should have <left> cucumbers', keyword: 'Then'
|
277
|
-
|
278
|
-
comment 'hmmm'
|
279
|
-
examples do
|
280
|
-
row 'start', 'eat', 'left'
|
281
|
-
row '12', '5', '7'
|
282
|
-
row '20', '5', '15'
|
283
|
-
end
|
284
|
-
end
|
285
|
-
end
|
286
|
-
end
|
287
|
-
|
288
|
-
expect( source.to_s ).to eq <<-END.unindent
|
289
|
-
# language: en
|
290
|
-
# wow
|
291
|
-
@always
|
292
|
-
Feature: Fully featured
|
293
|
-
|
294
|
-
# cool
|
295
|
-
Background:
|
296
|
-
Given passing
|
297
|
-
|
298
|
-
Scenario:
|
299
|
-
Given passing
|
300
|
-
|
301
|
-
# here
|
302
|
-
@first @second
|
303
|
-
Scenario: with doc string
|
304
|
-
# and here
|
305
|
-
Given passing
|
306
|
-
When failing
|
307
|
-
"""
|
308
|
-
I wish I was a little bit taller.
|
309
|
-
I wish I was a baller.
|
310
|
-
"""
|
311
|
-
|
312
|
-
Scenario: with a table...
|
313
|
-
Given passes:
|
314
|
-
| name | age | location |
|
315
|
-
| Janine | 43 | Antarctica |
|
316
|
-
|
317
|
-
# yay
|
318
|
-
Scenario Outline: eating
|
319
|
-
Given there are <start> cucumbers
|
320
|
-
When I eat <eat> cucumbers
|
321
|
-
Then I should have <left> cucumbers
|
322
|
-
|
323
|
-
# hmmm
|
324
|
-
Examples:
|
325
|
-
| start | eat | left |
|
326
|
-
| 12 | 5 | 7 |
|
327
|
-
| 20 | 5 | 15 |
|
328
|
-
END
|
329
|
-
|
330
|
-
end
|
331
|
-
end
|
332
|
-
end
|
@@ -1,178 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
require 'cucumber/core/event_bus'
|
3
|
-
require 'cucumber/core/events'
|
4
|
-
require 'cucumber/core/report/summary'
|
5
|
-
require 'cucumber/core/test/result'
|
6
|
-
|
7
|
-
module Cucumber::Core::Report
|
8
|
-
describe Summary do
|
9
|
-
let(:event_bus) { ::Cucumber::Core::EventBus.new(registry) }
|
10
|
-
let(:registry) { ::Cucumber::Core::Events.registry }
|
11
|
-
let(:passed_result) { ::Cucumber::Core::Test::Result::Passed.new(duration) }
|
12
|
-
let(:failed_result) { ::Cucumber::Core::Test::Result::Failed.new(duration, exception) }
|
13
|
-
let(:pending_result) { ::Cucumber::Core::Test::Result::Pending.new(duration) }
|
14
|
-
let(:skipped_result) { ::Cucumber::Core::Test::Result::Skipped.new(duration) }
|
15
|
-
let(:undefined_result) { ::Cucumber::Core::Test::Result::Undefined.new(duration) }
|
16
|
-
let(:duration) { double }
|
17
|
-
let(:exception) { double }
|
18
|
-
|
19
|
-
before(:each) { @summary = Summary.new(event_bus) }
|
20
|
-
|
21
|
-
context "test case summary" do
|
22
|
-
let(:test_case) { double }
|
23
|
-
|
24
|
-
it "counts passed test cases" do
|
25
|
-
event_bus.send(:test_case_finished, test_case, passed_result)
|
26
|
-
|
27
|
-
expect( @summary.test_cases.total(:passed) ).to eq(1)
|
28
|
-
expect( @summary.test_cases.total ).to eq(1)
|
29
|
-
end
|
30
|
-
|
31
|
-
it "counts failed test cases" do
|
32
|
-
event_bus.send(:test_case_finished, test_case, failed_result)
|
33
|
-
|
34
|
-
expect( @summary.test_cases.total(:failed) ).to eq(1)
|
35
|
-
expect( @summary.test_cases.total ).to eq(1)
|
36
|
-
end
|
37
|
-
|
38
|
-
it "counts pending test cases" do
|
39
|
-
event_bus.send(:test_case_finished, test_case, pending_result)
|
40
|
-
|
41
|
-
expect( @summary.test_cases.total(:pending) ).to eq(1)
|
42
|
-
expect( @summary.test_cases.total ).to eq(1)
|
43
|
-
end
|
44
|
-
|
45
|
-
it "counts skipped test cases" do
|
46
|
-
event_bus.send(:test_case_finished, test_case, skipped_result)
|
47
|
-
|
48
|
-
expect( @summary.test_cases.total(:skipped) ).to eq(1)
|
49
|
-
expect( @summary.test_cases.total ).to eq(1)
|
50
|
-
end
|
51
|
-
|
52
|
-
it "counts undefined test cases" do
|
53
|
-
event_bus.send(:test_case_finished, test_case, undefined_result)
|
54
|
-
|
55
|
-
expect( @summary.test_cases.total(:undefined) ).to eq(1)
|
56
|
-
expect( @summary.test_cases.total ).to eq(1)
|
57
|
-
end
|
58
|
-
|
59
|
-
it "handles flaky test cases" do
|
60
|
-
allow(test_case).to receive(:==).and_return(false, true)
|
61
|
-
event_bus.send(:test_case_finished, test_case, failed_result)
|
62
|
-
event_bus.send(:test_case_finished, test_case, passed_result)
|
63
|
-
|
64
|
-
expect( @summary.test_cases.total(:failed) ).to eq(0)
|
65
|
-
expect( @summary.test_cases.total(:flaky) ).to eq(1)
|
66
|
-
expect( @summary.test_cases.total ).to eq(1)
|
67
|
-
end
|
68
|
-
|
69
|
-
it "handless flaky with following skip test cases" do
|
70
|
-
allow(test_case).to receive(:==).and_return(false, true)
|
71
|
-
event_bus.send(:test_case_finished, test_case, failed_result)
|
72
|
-
event_bus.send(:test_case_finished, test_case, skipped_result)
|
73
|
-
|
74
|
-
expect( @summary.test_cases.total(:failed) ).to eq(0)
|
75
|
-
expect( @summary.test_cases.total(:skipped) ).to eq(0)
|
76
|
-
expect( @summary.test_cases.total(:flaky) ).to eq(1)
|
77
|
-
expect( @summary.test_cases.total ).to eq(1)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
context "test step summary" do
|
82
|
-
context "with test steps from gherkin steps" do
|
83
|
-
let(:test_step) { double }
|
84
|
-
|
85
|
-
before(:each) do
|
86
|
-
expect( test_step ).to receive(:hook?).and_return(false)
|
87
|
-
end
|
88
|
-
|
89
|
-
it "counts passed test steps" do
|
90
|
-
event_bus.send(:test_step_finished, test_step, passed_result)
|
91
|
-
|
92
|
-
expect( @summary.test_steps.total(:passed) ).to eq(1)
|
93
|
-
expect( @summary.test_steps.total ).to eq(1)
|
94
|
-
end
|
95
|
-
|
96
|
-
it "counts failed test cases" do
|
97
|
-
event_bus.send(:test_step_finished, test_step, failed_result)
|
98
|
-
|
99
|
-
expect( @summary.test_steps.total(:failed) ).to eq(1)
|
100
|
-
expect( @summary.test_steps.total ).to eq(1)
|
101
|
-
end
|
102
|
-
|
103
|
-
it "counts pending test cases" do
|
104
|
-
event_bus.send(:test_step_finished, test_step, pending_result)
|
105
|
-
|
106
|
-
expect( @summary.test_steps.total(:pending) ).to eq(1)
|
107
|
-
expect( @summary.test_steps.total ).to eq(1)
|
108
|
-
end
|
109
|
-
|
110
|
-
it "counts skipped test cases" do
|
111
|
-
event_bus.send(:test_step_finished, test_step, skipped_result)
|
112
|
-
|
113
|
-
expect( @summary.test_steps.total(:skipped) ).to eq(1)
|
114
|
-
expect( @summary.test_steps.total ).to eq(1)
|
115
|
-
end
|
116
|
-
|
117
|
-
it "counts undefined test cases" do
|
118
|
-
event_bus.send(:test_step_finished, test_step, undefined_result)
|
119
|
-
|
120
|
-
expect( @summary.test_steps.total(:undefined) ).to eq(1)
|
121
|
-
expect( @summary.test_steps.total ).to eq(1)
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
context "with test steps not from gherkin steps" do
|
126
|
-
let(:test_step) { double }
|
127
|
-
|
128
|
-
before(:each) do
|
129
|
-
expect( test_step ).to receive(:hook?).and_return(true)
|
130
|
-
end
|
131
|
-
|
132
|
-
it "ignores test steps not defined by gherkin steps" do
|
133
|
-
event_bus.send(:test_step_finished, test_step, passed_result)
|
134
|
-
|
135
|
-
expect( @summary.test_steps.total ).to eq(0)
|
136
|
-
end
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
context "ok? result" do
|
141
|
-
let(:test_case) { double }
|
142
|
-
|
143
|
-
it "passed test case is ok" do
|
144
|
-
event_bus.send(:test_case_finished, test_case, passed_result)
|
145
|
-
|
146
|
-
expect( @summary.ok? ).to eq true
|
147
|
-
end
|
148
|
-
|
149
|
-
it "skipped test case is ok" do
|
150
|
-
event_bus.send(:test_case_finished, test_case, skipped_result)
|
151
|
-
|
152
|
-
expect( @summary.ok? ).to eq true
|
153
|
-
end
|
154
|
-
|
155
|
-
it "failed test case is not ok" do
|
156
|
-
event_bus.send(:test_case_finished, test_case, failed_result)
|
157
|
-
|
158
|
-
expect( @summary.ok? ).to eq false
|
159
|
-
end
|
160
|
-
|
161
|
-
it "pending test case is ok if not strict" do
|
162
|
-
event_bus.send(:test_case_finished, test_case, pending_result)
|
163
|
-
|
164
|
-
expect( @summary.ok? ).to eq true
|
165
|
-
be_strict = ::Cucumber::Core::Test::Result::StrictConfiguration.new([:pending])
|
166
|
-
expect( @summary.ok?(be_strict) ).to eq false
|
167
|
-
end
|
168
|
-
|
169
|
-
it "undefined test case is ok if not strict" do
|
170
|
-
event_bus.send(:test_case_finished, test_case, undefined_result)
|
171
|
-
|
172
|
-
expect( @summary.ok? ).to eq true
|
173
|
-
be_strict = ::Cucumber::Core::Test::Result::StrictConfiguration.new([:undefined])
|
174
|
-
expect( @summary.ok?(be_strict) ).to eq false
|
175
|
-
end
|
176
|
-
end
|
177
|
-
end
|
178
|
-
end
|
@@ -1,153 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
require 'cucumber/core/test/action'
|
3
|
-
require 'cucumber/core/test/duration_matcher'
|
4
|
-
|
5
|
-
module Cucumber
|
6
|
-
module Core
|
7
|
-
module Test
|
8
|
-
|
9
|
-
describe Action do
|
10
|
-
|
11
|
-
context "constructed without a block" do
|
12
|
-
it "raises an error" do
|
13
|
-
expect { Action.new }.to raise_error(ArgumentError)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
context "location" do
|
18
|
-
|
19
|
-
context "with location passed to the constructor" do
|
20
|
-
let(:location) { double }
|
21
|
-
|
22
|
-
it "returns the location passed to the constructor" do
|
23
|
-
action = Action.new(location) {}
|
24
|
-
expect( action.location ).to be location
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
context "without location passed to the constructor" do
|
29
|
-
let(:block) { proc {} }
|
30
|
-
|
31
|
-
it "returns the location of the block passed to the constructor" do
|
32
|
-
action = Action.new(&block)
|
33
|
-
expect( action.location ).to eq Test::Location.new(*block.source_location)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
|
-
context "executing" do
|
40
|
-
it "executes the block passed to the constructor" do
|
41
|
-
executed = false
|
42
|
-
action = Action.new { executed = true }
|
43
|
-
action.execute
|
44
|
-
expect( executed ).to be_truthy
|
45
|
-
end
|
46
|
-
|
47
|
-
it "returns a passed result if the block doesn't fail" do
|
48
|
-
action = Action.new {}
|
49
|
-
expect( action.execute ).to be_passed
|
50
|
-
end
|
51
|
-
|
52
|
-
it "returns a failed result when the block raises an error" do
|
53
|
-
exception = StandardError.new
|
54
|
-
action = Action.new { raise exception }
|
55
|
-
result = action.execute
|
56
|
-
expect( result ).to be_failed
|
57
|
-
expect( result.exception ).to eq exception
|
58
|
-
end
|
59
|
-
|
60
|
-
it "yields the args passed to #execute to the block" do
|
61
|
-
args = [double, double]
|
62
|
-
args_spy = nil
|
63
|
-
action = Action.new { |arg1, arg2| args_spy = [arg1, arg2] }
|
64
|
-
action.execute(*args)
|
65
|
-
expect(args_spy).to eq args
|
66
|
-
end
|
67
|
-
|
68
|
-
it "returns a pending result if a Result::Pending error is raised" do
|
69
|
-
exception = Result::Pending.new("TODO")
|
70
|
-
action = Action.new { raise exception }
|
71
|
-
result = action.execute
|
72
|
-
expect( result ).to be_pending
|
73
|
-
expect( result.message ).to eq "TODO"
|
74
|
-
end
|
75
|
-
|
76
|
-
it "returns a skipped result if a Result::Skipped error is raised" do
|
77
|
-
exception = Result::Skipped.new("Not working right now")
|
78
|
-
action = Action.new { raise exception }
|
79
|
-
result = action.execute
|
80
|
-
expect( result ).to be_skipped
|
81
|
-
expect( result.message ).to eq "Not working right now"
|
82
|
-
end
|
83
|
-
|
84
|
-
it "returns an undefined result if a Result::Undefined error is raised" do
|
85
|
-
exception = Result::Undefined.new("new step")
|
86
|
-
action = Action.new { raise exception }
|
87
|
-
result = action.execute
|
88
|
-
expect( result ).to be_undefined
|
89
|
-
expect( result.message ).to eq "new step"
|
90
|
-
end
|
91
|
-
|
92
|
-
context "recording the duration" do
|
93
|
-
before do
|
94
|
-
allow( Timer::MonotonicTime ).to receive(:time_in_nanoseconds).and_return(525702744080000, 525702744080001)
|
95
|
-
end
|
96
|
-
|
97
|
-
it "records the nanoseconds duration of the execution on the result" do
|
98
|
-
action = Action.new { }
|
99
|
-
duration = action.execute.duration
|
100
|
-
expect( duration ).to be_duration 1
|
101
|
-
end
|
102
|
-
|
103
|
-
it "records the duration of a failed execution" do
|
104
|
-
action = Action.new { raise StandardError }
|
105
|
-
duration = action.execute.duration
|
106
|
-
expect( duration ).to be_duration 1
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
end
|
111
|
-
|
112
|
-
context "skipping" do
|
113
|
-
it "does not execute the block" do
|
114
|
-
executed = false
|
115
|
-
action = Action.new { executed = true }
|
116
|
-
action.skip
|
117
|
-
expect( executed ).to be_falsey
|
118
|
-
end
|
119
|
-
|
120
|
-
it "returns a skipped result" do
|
121
|
-
action = Action.new {}
|
122
|
-
expect( action.skip ).to be_skipped
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
describe UndefinedAction do
|
128
|
-
let(:location) { double }
|
129
|
-
let(:action) { UndefinedAction.new(location) }
|
130
|
-
let(:test_step) { double }
|
131
|
-
|
132
|
-
context "location" do
|
133
|
-
it "returns the location passed to the constructor" do
|
134
|
-
expect( action.location ).to be location
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
context "executing" do
|
139
|
-
it "returns an undefined result" do
|
140
|
-
expect( action.execute ).to be_undefined
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
context "skipping" do
|
145
|
-
it "returns an undefined result" do
|
146
|
-
expect( action.skip ).to be_undefined
|
147
|
-
end
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
end
|
152
|
-
end
|
153
|
-
end
|