cucumber-core 1.0.0.beta.4 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/CONTRIBUTING.md +14 -0
- data/HISTORY.md +14 -1
- data/README.md +34 -33
- data/lib/cucumber/core.rb +3 -5
- data/lib/cucumber/core/ast/background.rb +13 -2
- data/lib/cucumber/core/ast/comment.rb +8 -2
- data/lib/cucumber/core/ast/examples_table.rb +14 -5
- data/lib/cucumber/core/ast/feature.rb +15 -6
- data/lib/cucumber/core/ast/scenario.rb +17 -4
- data/lib/cucumber/core/ast/scenario_outline.rb +20 -8
- data/lib/cucumber/core/ast/tag.rb +5 -3
- data/lib/cucumber/core/compiler.rb +39 -7
- data/lib/cucumber/core/filter.rb +83 -0
- data/lib/cucumber/core/gherkin/ast_builder.rb +7 -2
- data/lib/cucumber/core/gherkin/document.rb +5 -2
- data/lib/cucumber/core/gherkin/parser.rb +6 -1
- data/lib/cucumber/core/test/action.rb +8 -8
- data/lib/cucumber/core/test/around_hook.rb +19 -0
- data/lib/cucumber/core/test/case.rb +6 -4
- data/lib/cucumber/core/test/filters/locations_filter.rb +3 -6
- data/lib/cucumber/core/test/filters/name_filter.rb +3 -7
- data/lib/cucumber/core/test/filters/tag_filter.rb +4 -2
- data/lib/cucumber/core/test/result.rb +5 -7
- data/lib/cucumber/core/test/runner.rb +39 -40
- data/lib/cucumber/core/test/step.rb +7 -10
- data/lib/cucumber/core/version.rb +1 -1
- data/spec/capture_warnings.rb +5 -0
- data/spec/cucumber/core/filter_spec.rb +100 -0
- data/spec/cucumber/core/gherkin/parser_spec.rb +0 -1
- data/spec/cucumber/core/test/action_spec.rb +29 -31
- data/spec/cucumber/core/test/runner_spec.rb +5 -5
- data/spec/cucumber/core/test/step_spec.rb +18 -9
- data/spec/cucumber/core_spec.rb +40 -172
- metadata +11 -16
- data/lib/cucumber/core/test/hooks.rb +0 -93
- data/lib/cucumber/core/test/mapper.rb +0 -150
- data/lib/cucumber/initializer.rb +0 -18
- data/spec/cucumber/core/test/hooks_spec.rb +0 -30
- data/spec/cucumber/core/test/mapper_spec.rb +0 -203
- data/spec/cucumber/initializer_spec.rb +0 -49
data/spec/capture_warnings.rb
CHANGED
@@ -16,6 +16,11 @@ module CaptureWarnings
|
|
16
16
|
print_warnings('other', other_warnings) if ENV['VIEW_OTHER_WARNINGS']
|
17
17
|
end
|
18
18
|
|
19
|
+
# Until they fix https://bugs.ruby-lang.org/issues/10661
|
20
|
+
if RUBY_VERSION == "2.2.0"
|
21
|
+
project_warnings = project_warnings.reject { |w| w =~ /warning: possible reference to past scope/ }
|
22
|
+
end
|
23
|
+
|
19
24
|
if project_warnings.any?
|
20
25
|
puts "#{ project_warnings.count } cucumber-core warnings detected"
|
21
26
|
print_warnings('cucumber-core', project_warnings)
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'cucumber/core/gherkin/writer'
|
2
|
+
require 'cucumber/core'
|
3
|
+
require 'cucumber/core/filter'
|
4
|
+
|
5
|
+
module Cucumber::Core
|
6
|
+
describe Filter do
|
7
|
+
include Cucumber::Core::Gherkin::Writer
|
8
|
+
include Cucumber::Core
|
9
|
+
|
10
|
+
describe ".new" do
|
11
|
+
let(:receiver) { double.as_null_object }
|
12
|
+
|
13
|
+
let(:doc) {
|
14
|
+
gherkin do
|
15
|
+
feature do
|
16
|
+
scenario 'x' do
|
17
|
+
step 'a step'
|
18
|
+
end
|
19
|
+
|
20
|
+
scenario 'y' do
|
21
|
+
step 'a step'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
}
|
26
|
+
|
27
|
+
it "creates a filter class that can pass-through by default" do
|
28
|
+
my_filter_class = Filter.new
|
29
|
+
my_filter = my_filter_class.new
|
30
|
+
expect(receiver).to receive(:test_case) { |test_case|
|
31
|
+
expect(test_case.test_steps.length).to eq 1
|
32
|
+
expect(test_case.test_steps.first.name).to eq 'a step'
|
33
|
+
}.exactly(2).times
|
34
|
+
compile [doc], receiver, [my_filter]
|
35
|
+
end
|
36
|
+
|
37
|
+
context "customizing by subclassing" do
|
38
|
+
|
39
|
+
# Each filter imlicitly gets a :receiver attribute
|
40
|
+
# that you need to call with the new test case
|
41
|
+
# once you've received yours and modified it.
|
42
|
+
class BasicBlankingFilter < Filter.new
|
43
|
+
def test_case(test_case)
|
44
|
+
test_case.with_steps([]).describe_to(receiver)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
# You can pass the names of attributes when building a
|
49
|
+
# filter, allowing you to have custom attributes.
|
50
|
+
class NamedBlankingFilter < Filter.new(:name_pattern)
|
51
|
+
def test_case(test_case)
|
52
|
+
if test_case.name =~ name_pattern
|
53
|
+
test_case.with_steps([]).describe_to(receiver)
|
54
|
+
else
|
55
|
+
test_case.describe_to(receiver) # or just call `super`
|
56
|
+
end
|
57
|
+
self
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
it "can override methods from the base class" do
|
62
|
+
expect(receiver).to receive(:test_case) { |test_case|
|
63
|
+
expect(test_case.test_steps.length).to eq 0
|
64
|
+
}.exactly(2).times
|
65
|
+
run BasicBlankingFilter.new
|
66
|
+
end
|
67
|
+
|
68
|
+
it "can take arguments" do
|
69
|
+
expect(receiver).to receive(:test_case) { |test_case|
|
70
|
+
expect(test_case.test_steps.length).to eq 0
|
71
|
+
}.once.ordered
|
72
|
+
expect(receiver).to receive(:test_case) { |test_case|
|
73
|
+
expect(test_case.test_steps.length).to eq 1
|
74
|
+
}.once.ordered
|
75
|
+
run NamedBlankingFilter.new(/x/)
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
|
80
|
+
context "customizing by using a block" do
|
81
|
+
BlockBlankingFilter = Filter.new do
|
82
|
+
def test_case(test_case)
|
83
|
+
test_case.with_steps([]).describe_to(receiver)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
it "allows methods to be overridden" do
|
88
|
+
expect(receiver).to receive(:test_case) { |test_case|
|
89
|
+
expect(test_case.test_steps.length).to eq 0
|
90
|
+
}.exactly(2).times
|
91
|
+
run BlockBlankingFilter.new
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def run(filter)
|
96
|
+
compile [doc], receiver, [filter]
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -6,7 +6,6 @@ module Cucumber
|
|
6
6
|
module Test
|
7
7
|
|
8
8
|
describe Action do
|
9
|
-
let(:last_result) { double('last_result') }
|
10
9
|
|
11
10
|
context "constructed without a block" do
|
12
11
|
it "raises an error" do
|
@@ -17,51 +16,52 @@ module Cucumber
|
|
17
16
|
context "executing" do
|
18
17
|
it "executes the block passed to the constructor" do
|
19
18
|
executed = false
|
20
|
-
|
21
|
-
|
19
|
+
action = Action.new { executed = true }
|
20
|
+
action.execute
|
22
21
|
expect( executed ).to be_truthy
|
23
22
|
end
|
24
23
|
|
25
24
|
it "returns a passed result if the block doesn't fail" do
|
26
|
-
|
27
|
-
expect(
|
25
|
+
action = Action.new {}
|
26
|
+
expect( action.execute ).to be_passed
|
28
27
|
end
|
29
28
|
|
30
29
|
it "returns a failed result when the block raises an error" do
|
31
30
|
exception = StandardError.new
|
32
|
-
|
33
|
-
result =
|
31
|
+
action = Action.new { raise exception }
|
32
|
+
result = action.execute
|
34
33
|
expect( result ).to be_failed
|
35
34
|
expect( result.exception ).to eq exception
|
36
35
|
end
|
37
36
|
|
38
|
-
it "yields the
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
37
|
+
it "yields the args passed to #execute to the block" do
|
38
|
+
args = [double, double]
|
39
|
+
args_spy = nil
|
40
|
+
action = Action.new { |arg1, arg2| args_spy = [arg1, arg2] }
|
41
|
+
action.execute(*args)
|
42
|
+
expect(args_spy).to eq args
|
43
43
|
end
|
44
44
|
|
45
45
|
it "returns a pending result if a Result::Pending error is raised" do
|
46
46
|
exception = Result::Pending.new("TODO")
|
47
|
-
|
48
|
-
result =
|
47
|
+
action = Action.new { raise exception }
|
48
|
+
result = action.execute
|
49
49
|
expect( result ).to be_pending
|
50
50
|
expect( result.message ).to eq "TODO"
|
51
51
|
end
|
52
52
|
|
53
53
|
it "returns a skipped result if a Result::Skipped error is raised" do
|
54
54
|
exception = Result::Skipped.new("Not working right now")
|
55
|
-
|
56
|
-
result =
|
55
|
+
action = Action.new { raise exception }
|
56
|
+
result = action.execute
|
57
57
|
expect( result ).to be_skipped
|
58
58
|
expect( result.message ).to eq "Not working right now"
|
59
59
|
end
|
60
60
|
|
61
61
|
it "returns an undefined result if a Result::Undefined error is raised" do
|
62
62
|
exception = Result::Undefined.new("new step")
|
63
|
-
|
64
|
-
result =
|
63
|
+
action = Action.new { raise exception }
|
64
|
+
result = action.execute
|
65
65
|
expect( result ).to be_undefined
|
66
66
|
expect( result.message ).to eq "new step"
|
67
67
|
end
|
@@ -75,14 +75,14 @@ module Cucumber
|
|
75
75
|
end
|
76
76
|
|
77
77
|
it "records the nanoseconds duration of the execution on the result" do
|
78
|
-
|
79
|
-
duration =
|
78
|
+
action = Action.new { }
|
79
|
+
duration = action.execute.duration
|
80
80
|
expect( duration ).to be_duration 1
|
81
81
|
end
|
82
82
|
|
83
83
|
it "records the duration of a failed execution" do
|
84
|
-
|
85
|
-
duration =
|
84
|
+
action = Action.new { raise StandardError }
|
85
|
+
duration = action.execute.duration
|
86
86
|
expect( duration ).to be_duration 1
|
87
87
|
end
|
88
88
|
end
|
@@ -92,35 +92,33 @@ module Cucumber
|
|
92
92
|
context "skipping" do
|
93
93
|
it "does not execute the block" do
|
94
94
|
executed = false
|
95
|
-
|
96
|
-
|
95
|
+
action = Action.new { executed = true }
|
96
|
+
action.skip
|
97
97
|
expect( executed ).to be_falsey
|
98
98
|
end
|
99
99
|
|
100
100
|
it "returns a skipped result" do
|
101
|
-
|
102
|
-
expect(
|
101
|
+
action = Action.new {}
|
102
|
+
expect( action.skip ).to be_skipped
|
103
103
|
end
|
104
104
|
end
|
105
105
|
end
|
106
106
|
|
107
107
|
describe UndefinedAction do
|
108
|
-
let(:
|
108
|
+
let(:action) { UndefinedAction.new }
|
109
109
|
let(:test_step) { double }
|
110
|
-
let(:last_result) { double('last_result') }
|
111
110
|
|
112
111
|
context "executing" do
|
113
112
|
it "returns an undefined result" do
|
114
|
-
expect(
|
113
|
+
expect( action.execute ).to be_undefined
|
115
114
|
end
|
116
115
|
end
|
117
116
|
|
118
117
|
context "skipping" do
|
119
118
|
it "returns an undefined result" do
|
120
|
-
expect(
|
119
|
+
expect( action.skip ).to be_undefined
|
121
120
|
end
|
122
121
|
end
|
123
|
-
|
124
122
|
end
|
125
123
|
|
126
124
|
end
|
@@ -10,10 +10,10 @@ module Cucumber::Core::Test
|
|
10
10
|
let(:source) { double }
|
11
11
|
let(:runner) { Runner.new(report) }
|
12
12
|
let(:report) { double.as_null_object }
|
13
|
-
let(:passing) { Step.new([double]).
|
14
|
-
let(:failing) { Step.new([double]).
|
15
|
-
let(:pending) { Step.new([double]).
|
16
|
-
let(:skipping) { Step.new([double]).
|
13
|
+
let(:passing) { Step.new([double]).with_action {} }
|
14
|
+
let(:failing) { Step.new([double]).with_action { raise exception } }
|
15
|
+
let(:pending) { Step.new([double]).with_action { raise Result::Pending.new("TODO") } }
|
16
|
+
let(:skipping) { Step.new([double]).with_action { raise Result::Skipped.new } }
|
17
17
|
let(:undefined) { Step.new([double]) }
|
18
18
|
let(:exception) { StandardError.new('test error') }
|
19
19
|
|
@@ -203,7 +203,7 @@ module Cucumber::Core::Test
|
|
203
203
|
result_spy = last_result
|
204
204
|
end
|
205
205
|
after_hook = Step.new([double], hook_mapping)
|
206
|
-
failing_step = Step.new([double]).
|
206
|
+
failing_step = Step.new([double]).with_action { fail }
|
207
207
|
test_case = Case.new([failing_step, after_hook], source)
|
208
208
|
test_case.describe_to runner
|
209
209
|
expect(result_spy).to be_failed
|
@@ -2,7 +2,6 @@ require 'cucumber/core/test/step'
|
|
2
2
|
|
3
3
|
module Cucumber::Core::Test
|
4
4
|
describe Step do
|
5
|
-
let(:last_result) { double('last_result') }
|
6
5
|
|
7
6
|
describe "describing itself" do
|
8
7
|
it "describes itself to a visitor" do
|
@@ -28,28 +27,38 @@ module Cucumber::Core::Test
|
|
28
27
|
describe "executing" do
|
29
28
|
let(:ast_step) { double }
|
30
29
|
|
31
|
-
|
30
|
+
it "passes arbitrary arguments to the action's block" do
|
31
|
+
args_spy = nil
|
32
|
+
expected_args = [double, double]
|
33
|
+
test_step = Step.new([ast_step]).with_action do |*actual_args|
|
34
|
+
args_spy = actual_args
|
35
|
+
end
|
36
|
+
test_step.execute(*expected_args)
|
37
|
+
expect(args_spy).to eq expected_args
|
38
|
+
end
|
39
|
+
|
40
|
+
context "when a passing action exists" do
|
32
41
|
it "returns a passing result" do
|
33
|
-
test_step = Step.new([ast_step]).
|
34
|
-
expect( test_step.execute
|
42
|
+
test_step = Step.new([ast_step]).with_action {}
|
43
|
+
expect( test_step.execute ).to be_passed
|
35
44
|
end
|
36
45
|
end
|
37
46
|
|
38
|
-
context "when a failing
|
47
|
+
context "when a failing action exists" do
|
39
48
|
let(:exception) { StandardError.new('oops') }
|
40
49
|
|
41
50
|
it "returns a failing result" do
|
42
|
-
test_step = Step.new([ast_step]).
|
43
|
-
result = test_step.execute
|
51
|
+
test_step = Step.new([ast_step]).with_action { raise exception }
|
52
|
+
result = test_step.execute
|
44
53
|
expect( result ).to be_failed
|
45
54
|
expect( result.exception ).to eq exception
|
46
55
|
end
|
47
56
|
end
|
48
57
|
|
49
|
-
context "with no
|
58
|
+
context "with no action" do
|
50
59
|
it "returns an Undefined result" do
|
51
60
|
test_step = Step.new([ast_step])
|
52
|
-
result = test_step.execute
|
61
|
+
result = test_step.execute
|
53
62
|
expect( result ).to be_undefined
|
54
63
|
end
|
55
64
|
end
|
data/spec/cucumber/core_spec.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
require 'report_api_spy'
|
2
2
|
require 'cucumber/core'
|
3
|
+
require 'cucumber/core/filter'
|
3
4
|
require 'cucumber/core/gherkin/writer'
|
4
5
|
require 'cucumber/core/platform'
|
5
6
|
require 'cucumber/core/report/summary'
|
7
|
+
require 'cucumber/core/test/around_hook'
|
6
8
|
|
7
9
|
module Cucumber
|
8
10
|
describe Core do
|
@@ -71,7 +73,7 @@ module Cucumber
|
|
71
73
|
end
|
72
74
|
end
|
73
75
|
|
74
|
-
compile [gherkin], visitor, [
|
76
|
+
compile [gherkin], visitor, [Cucumber::Core::Test::TagFilter.new(['@a', '@b'])]
|
75
77
|
end
|
76
78
|
|
77
79
|
describe 'with tag filters that have limits' do
|
@@ -114,7 +116,7 @@ module Cucumber
|
|
114
116
|
|
115
117
|
context 'on scenarios' do
|
116
118
|
let(:tag_filters) {
|
117
|
-
[
|
119
|
+
[ Cucumber::Core::Test::TagFilter.new(['@one:1']) ]
|
118
120
|
}
|
119
121
|
|
120
122
|
it 'raises a tag excess error with the location of the test cases' do
|
@@ -128,7 +130,7 @@ module Cucumber
|
|
128
130
|
|
129
131
|
context 'on scenario outlines' do
|
130
132
|
let(:tag_filters) {
|
131
|
-
[
|
133
|
+
[ Cucumber::Core::Test::TagFilter.new(['@three:1']) ]
|
132
134
|
}
|
133
135
|
|
134
136
|
it 'raises a tag excess error with the location of the test cases' do
|
@@ -142,7 +144,7 @@ module Cucumber
|
|
142
144
|
|
143
145
|
context 'on a feature with scenarios' do
|
144
146
|
let(:tag_filters) {
|
145
|
-
[
|
147
|
+
[ Cucumber::Core::Test::TagFilter.new(['@feature:2']) ]
|
146
148
|
}
|
147
149
|
|
148
150
|
it 'raises a tag excess error with the location of the test cases' do
|
@@ -158,7 +160,7 @@ module Cucumber
|
|
158
160
|
|
159
161
|
context 'with negated tags' do
|
160
162
|
let(:tag_filters) {
|
161
|
-
[
|
163
|
+
[ Cucumber::Core::Test::TagFilter.new(['~@one:1']) ]
|
162
164
|
}
|
163
165
|
|
164
166
|
it 'raises a tag excess error with the location of the test cases' do
|
@@ -172,7 +174,7 @@ module Cucumber
|
|
172
174
|
|
173
175
|
context 'whith multiple tag limits' do
|
174
176
|
let(:tag_filters) {
|
175
|
-
[
|
177
|
+
[ Cucumber::Core::Test::TagFilter.new(['@one:1, @three:1', '~@feature:3']) ]
|
176
178
|
}
|
177
179
|
|
178
180
|
it 'raises a tag excess error with the location of the test cases' do
|
@@ -198,17 +200,20 @@ module Cucumber
|
|
198
200
|
|
199
201
|
describe "executing a test suite" do
|
200
202
|
context "without hooks" do
|
201
|
-
class
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
203
|
+
class WithSteps < Core::Filter.new
|
204
|
+
def test_case(test_case)
|
205
|
+
test_steps = test_case.test_steps.map do |step|
|
206
|
+
case step.name
|
207
|
+
when /fail/
|
208
|
+
step.with_action { raise Failure }
|
209
|
+
when /pass/
|
210
|
+
step.with_action {}
|
211
|
+
else
|
212
|
+
step
|
213
|
+
end
|
214
|
+
end
|
207
215
|
|
208
|
-
|
209
|
-
mapper.map { raise Failure } if step.name =~ /fail/
|
210
|
-
mapper.map {} if step.name =~ /pass/
|
211
|
-
self
|
216
|
+
test_case.with_steps(test_steps).describe_to(receiver)
|
212
217
|
end
|
213
218
|
end
|
214
219
|
|
@@ -228,9 +233,8 @@ module Cucumber
|
|
228
233
|
end
|
229
234
|
end
|
230
235
|
report = Core::Report::Summary.new
|
231
|
-
mappings = StepTestMappings.new
|
232
236
|
|
233
|
-
execute [gherkin],
|
237
|
+
execute [gherkin], report, [WithSteps.new]
|
234
238
|
|
235
239
|
expect( report.test_cases.total ).to eq 2
|
236
240
|
expect( report.test_cases.total_passed ).to eq 1
|
@@ -243,149 +247,22 @@ module Cucumber
|
|
243
247
|
end
|
244
248
|
end
|
245
249
|
|
246
|
-
context "with hooks" do
|
247
|
-
class HookTestMappings
|
248
|
-
Failure = Class.new(StandardError)
|
249
|
-
attr_reader :logger
|
250
|
-
|
251
|
-
def initialize
|
252
|
-
@logger = []
|
253
|
-
end
|
254
|
-
|
255
|
-
def test_case(test_case, mapper)
|
256
|
-
mapper.before { @logger << ['--'] }
|
257
|
-
failing_before = proc do
|
258
|
-
@logger << [:failing_before, test_case.name]
|
259
|
-
raise Failure
|
260
|
-
end
|
261
|
-
passing_after = proc do
|
262
|
-
@logger << [:passing_after, test_case.name]
|
263
|
-
end
|
264
|
-
passing_before = proc do
|
265
|
-
@logger << [:passing_before, test_case.name]
|
266
|
-
end
|
267
|
-
failing_after = proc do
|
268
|
-
@logger << [:failing_after, test_case.name]
|
269
|
-
raise Failure
|
270
|
-
end
|
271
|
-
|
272
|
-
case test_case.name
|
273
|
-
|
274
|
-
when /fail before/
|
275
|
-
mapper.before( &failing_before )
|
276
|
-
mapper.after( &passing_after )
|
277
|
-
|
278
|
-
when /fail after/
|
279
|
-
mapper.before( &passing_before )
|
280
|
-
mapper.after( &failing_after )
|
281
|
-
|
282
|
-
else
|
283
|
-
mapper.before( &passing_before )
|
284
|
-
mapper.after( &passing_after )
|
285
|
-
|
286
|
-
end
|
287
|
-
|
288
|
-
self
|
289
|
-
end
|
290
|
-
|
291
|
-
def test_step(test_step, mapper)
|
292
|
-
mapper.map { @logger << [:step, test_step.name] } # all steps pass
|
293
|
-
if test_step.name == 'fail after'
|
294
|
-
mapper.after do
|
295
|
-
@logger << :failing_after_step
|
296
|
-
raise Failure
|
297
|
-
end
|
298
|
-
end
|
299
|
-
self
|
300
|
-
end
|
301
|
-
end
|
302
|
-
|
303
|
-
it "executes the steps and hooks in the right order" do
|
304
|
-
gherkin = gherkin do
|
305
|
-
feature do
|
306
|
-
scenario 'fail before' do
|
307
|
-
step 'passing'
|
308
|
-
end
|
309
|
-
|
310
|
-
scenario 'fail after' do
|
311
|
-
step 'passing'
|
312
|
-
end
|
313
|
-
|
314
|
-
scenario 'fail step' do
|
315
|
-
step 'fail after'
|
316
|
-
end
|
317
|
-
|
318
|
-
scenario 'passing' do
|
319
|
-
step 'passing'
|
320
|
-
end
|
321
|
-
end
|
322
|
-
end
|
323
|
-
report = Core::Report::Summary.new
|
324
|
-
mappings = HookTestMappings.new
|
325
|
-
|
326
|
-
execute [gherkin], mappings, report
|
327
|
-
|
328
|
-
expect( report.test_steps.total ).to eq(17)
|
329
|
-
expect( report.test_steps.total_failed ).to eq(3)
|
330
|
-
expect( report.test_cases.total ).to eq(4)
|
331
|
-
expect( report.test_cases.total_passed ).to eq(1)
|
332
|
-
expect( report.test_cases.total_failed ).to eq(3)
|
333
|
-
expect( mappings.logger ).to eq [
|
334
|
-
["--"],
|
335
|
-
[:failing_before, "Scenario: fail before"],
|
336
|
-
[:passing_after, "Scenario: fail before"],
|
337
|
-
["--"],
|
338
|
-
[:passing_before, "Scenario: fail after"],
|
339
|
-
[:step, "passing"],
|
340
|
-
[:failing_after, "Scenario: fail after"],
|
341
|
-
["--"],
|
342
|
-
[:passing_before, "Scenario: fail step"],
|
343
|
-
[:step, "fail after"],
|
344
|
-
:failing_after_step,
|
345
|
-
[:passing_after, "Scenario: fail step"],
|
346
|
-
["--"],
|
347
|
-
[:passing_before, "Scenario: passing"],
|
348
|
-
[:step, "passing"],
|
349
|
-
[:passing_after, "Scenario: passing"]
|
350
|
-
]
|
351
|
-
end
|
352
|
-
end
|
353
|
-
|
354
250
|
context "with around hooks" do
|
355
|
-
class
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
logger = @logger
|
364
|
-
mapper.around do |run_scenario|
|
251
|
+
class WithAroundHooks < Core::Filter.new(:logger)
|
252
|
+
def test_case(test_case)
|
253
|
+
base_step = Core::Test::Step.new(test_case.source)
|
254
|
+
test_steps = [
|
255
|
+
base_step.with_action { logger << :step },
|
256
|
+
]
|
257
|
+
|
258
|
+
around_hook = Core::Test::AroundHook.new do |run_scenario|
|
365
259
|
logger << :before_all
|
366
260
|
run_scenario.call
|
367
261
|
logger << :middle
|
368
262
|
run_scenario.call
|
369
263
|
logger << :after_all
|
370
264
|
end
|
371
|
-
|
372
|
-
logger << :before
|
373
|
-
end
|
374
|
-
mapper.after do
|
375
|
-
logger << :after
|
376
|
-
end
|
377
|
-
self
|
378
|
-
end
|
379
|
-
|
380
|
-
def test_step(step, mapper)
|
381
|
-
logger = @logger
|
382
|
-
mapper.map do
|
383
|
-
logger << :during
|
384
|
-
end
|
385
|
-
mapper.after do
|
386
|
-
logger << :after_step
|
387
|
-
end
|
388
|
-
self
|
265
|
+
test_case.with_steps(test_steps).with_around_hooks([around_hook]).describe_to(receiver)
|
389
266
|
end
|
390
267
|
end
|
391
268
|
|
@@ -398,24 +275,18 @@ module Cucumber
|
|
398
275
|
end
|
399
276
|
end
|
400
277
|
report = Core::Report::Summary.new
|
401
|
-
|
278
|
+
logger = []
|
402
279
|
|
403
|
-
execute [gherkin],
|
280
|
+
execute [gherkin], report, [WithAroundHooks.new(logger)]
|
404
281
|
|
405
282
|
expect( report.test_cases.total ).to eq 1
|
406
283
|
expect( report.test_cases.total_passed ).to eq 1
|
407
284
|
expect( report.test_cases.total_failed ).to eq 0
|
408
|
-
expect(
|
285
|
+
expect( logger ).to eq [
|
409
286
|
:before_all,
|
410
|
-
:
|
411
|
-
:during,
|
412
|
-
:after_step,
|
413
|
-
:after,
|
287
|
+
:step,
|
414
288
|
:middle,
|
415
|
-
:
|
416
|
-
:during,
|
417
|
-
:after_step,
|
418
|
-
:after,
|
289
|
+
:step,
|
419
290
|
:after_all
|
420
291
|
]
|
421
292
|
end
|
@@ -439,9 +310,8 @@ module Cucumber
|
|
439
310
|
end
|
440
311
|
end
|
441
312
|
report = Core::Report::Summary.new
|
442
|
-
mappings = HookTestMappings.new
|
443
313
|
|
444
|
-
execute [gherkin],
|
314
|
+
execute [gherkin], report, [ Cucumber::Core::Test::TagFilter.new(['@a']) ]
|
445
315
|
|
446
316
|
expect( report.test_cases.total ).to eq 2
|
447
317
|
end
|
@@ -458,9 +328,8 @@ module Cucumber
|
|
458
328
|
end
|
459
329
|
end
|
460
330
|
report = Core::Report::Summary.new
|
461
|
-
mappings = HookTestMappings.new
|
462
331
|
|
463
|
-
execute [gherkin],
|
332
|
+
execute [gherkin], report, [ Cucumber::Core::Test::NameFilter.new([/scenario/]) ]
|
464
333
|
|
465
334
|
expect( report.test_cases.total ).to eq 1
|
466
335
|
end
|
@@ -483,11 +352,10 @@ module Cucumber
|
|
483
352
|
end
|
484
353
|
|
485
354
|
report = Core::Report::Summary.new
|
486
|
-
mappings = HookTestMappings.new
|
487
355
|
some_feature = Cucumber::Core::Ast::Location.new("some.feature")
|
488
|
-
filters = [
|
356
|
+
filters = [ Cucumber::Core::Test::LocationsFilter.new([some_feature]) ]
|
489
357
|
|
490
|
-
execute documents,
|
358
|
+
execute documents, report, filters
|
491
359
|
|
492
360
|
expect( report.test_cases.total ).to eq 1
|
493
361
|
end
|