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
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cucumber-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aslak Hellesøy
|
@@ -12,7 +12,7 @@ authors:
|
|
12
12
|
autorequire:
|
13
13
|
bindir: bin
|
14
14
|
cert_chain: []
|
15
|
-
date:
|
15
|
+
date: 2015-01-23 00:00:00.000000000 Z
|
16
16
|
dependencies:
|
17
17
|
- !ruby/object:Gem::Dependency
|
18
18
|
name: gherkin
|
@@ -123,6 +123,7 @@ files:
|
|
123
123
|
- ".ruby-gemset"
|
124
124
|
- ".travis.yml"
|
125
125
|
- ".yardopts"
|
126
|
+
- CONTRIBUTING.md
|
126
127
|
- Gemfile
|
127
128
|
- HISTORY.md
|
128
129
|
- LICENSE
|
@@ -148,6 +149,7 @@ files:
|
|
148
149
|
- lib/cucumber/core/ast/step.rb
|
149
150
|
- lib/cucumber/core/ast/tag.rb
|
150
151
|
- lib/cucumber/core/compiler.rb
|
152
|
+
- lib/cucumber/core/filter.rb
|
151
153
|
- lib/cucumber/core/gherkin/ast_builder.rb
|
152
154
|
- lib/cucumber/core/gherkin/document.rb
|
153
155
|
- lib/cucumber/core/gherkin/parser.rb
|
@@ -156,19 +158,17 @@ files:
|
|
156
158
|
- lib/cucumber/core/platform.rb
|
157
159
|
- lib/cucumber/core/report/summary.rb
|
158
160
|
- lib/cucumber/core/test/action.rb
|
161
|
+
- lib/cucumber/core/test/around_hook.rb
|
159
162
|
- lib/cucumber/core/test/case.rb
|
160
163
|
- lib/cucumber/core/test/filters.rb
|
161
164
|
- lib/cucumber/core/test/filters/locations_filter.rb
|
162
165
|
- lib/cucumber/core/test/filters/name_filter.rb
|
163
166
|
- lib/cucumber/core/test/filters/tag_filter.rb
|
164
|
-
- lib/cucumber/core/test/hooks.rb
|
165
|
-
- lib/cucumber/core/test/mapper.rb
|
166
167
|
- lib/cucumber/core/test/result.rb
|
167
168
|
- lib/cucumber/core/test/runner.rb
|
168
169
|
- lib/cucumber/core/test/step.rb
|
169
170
|
- lib/cucumber/core/test/timer.rb
|
170
171
|
- lib/cucumber/core/version.rb
|
171
|
-
- lib/cucumber/initializer.rb
|
172
172
|
- spec/capture_warnings.rb
|
173
173
|
- spec/coverage.rb
|
174
174
|
- spec/cucumber/core/ast/data_table_spec.rb
|
@@ -178,19 +178,17 @@ files:
|
|
178
178
|
- spec/cucumber/core/ast/outline_step_spec.rb
|
179
179
|
- spec/cucumber/core/ast/step_spec.rb
|
180
180
|
- spec/cucumber/core/compiler_spec.rb
|
181
|
+
- spec/cucumber/core/filter_spec.rb
|
181
182
|
- spec/cucumber/core/gherkin/parser_spec.rb
|
182
183
|
- spec/cucumber/core/gherkin/writer_spec.rb
|
183
184
|
- spec/cucumber/core/test/action_spec.rb
|
184
185
|
- spec/cucumber/core/test/case_spec.rb
|
185
186
|
- spec/cucumber/core/test/duration_matcher.rb
|
186
|
-
- spec/cucumber/core/test/hooks_spec.rb
|
187
|
-
- spec/cucumber/core/test/mapper_spec.rb
|
188
187
|
- spec/cucumber/core/test/result_spec.rb
|
189
188
|
- spec/cucumber/core/test/runner_spec.rb
|
190
189
|
- spec/cucumber/core/test/step_spec.rb
|
191
190
|
- spec/cucumber/core/test/timer_spec.rb
|
192
191
|
- spec/cucumber/core_spec.rb
|
193
|
-
- spec/cucumber/initializer_spec.rb
|
194
192
|
- spec/readme_spec.rb
|
195
193
|
- spec/report_api_spy.rb
|
196
194
|
homepage: http://cukes.info
|
@@ -209,15 +207,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
209
207
|
version: 1.9.3
|
210
208
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
211
209
|
requirements:
|
212
|
-
- - "
|
210
|
+
- - ">="
|
213
211
|
- !ruby/object:Gem::Version
|
214
|
-
version:
|
212
|
+
version: '0'
|
215
213
|
requirements: []
|
216
214
|
rubyforge_project:
|
217
|
-
rubygems_version: 2.
|
215
|
+
rubygems_version: 2.2.2
|
218
216
|
signing_key:
|
219
217
|
specification_version: 4
|
220
|
-
summary: cucumber-core-1.0.0
|
218
|
+
summary: cucumber-core-1.0.0
|
221
219
|
test_files:
|
222
220
|
- spec/capture_warnings.rb
|
223
221
|
- spec/coverage.rb
|
@@ -228,19 +226,16 @@ test_files:
|
|
228
226
|
- spec/cucumber/core/ast/outline_step_spec.rb
|
229
227
|
- spec/cucumber/core/ast/step_spec.rb
|
230
228
|
- spec/cucumber/core/compiler_spec.rb
|
229
|
+
- spec/cucumber/core/filter_spec.rb
|
231
230
|
- spec/cucumber/core/gherkin/parser_spec.rb
|
232
231
|
- spec/cucumber/core/gherkin/writer_spec.rb
|
233
232
|
- spec/cucumber/core/test/action_spec.rb
|
234
233
|
- spec/cucumber/core/test/case_spec.rb
|
235
234
|
- spec/cucumber/core/test/duration_matcher.rb
|
236
|
-
- spec/cucumber/core/test/hooks_spec.rb
|
237
|
-
- spec/cucumber/core/test/mapper_spec.rb
|
238
235
|
- spec/cucumber/core/test/result_spec.rb
|
239
236
|
- spec/cucumber/core/test/runner_spec.rb
|
240
237
|
- spec/cucumber/core/test/step_spec.rb
|
241
238
|
- spec/cucumber/core/test/timer_spec.rb
|
242
239
|
- spec/cucumber/core_spec.rb
|
243
|
-
- spec/cucumber/initializer_spec.rb
|
244
240
|
- spec/readme_spec.rb
|
245
241
|
- spec/report_api_spy.rb
|
246
|
-
has_rdoc:
|
@@ -1,93 +0,0 @@
|
|
1
|
-
require 'cucumber/initializer'
|
2
|
-
|
3
|
-
module Cucumber
|
4
|
-
module Core
|
5
|
-
module Test
|
6
|
-
module Hooks
|
7
|
-
|
8
|
-
class BeforeHook
|
9
|
-
include Cucumber.initializer(:location)
|
10
|
-
public :location
|
11
|
-
|
12
|
-
def name
|
13
|
-
"Before hook"
|
14
|
-
end
|
15
|
-
|
16
|
-
def match_locations?(queried_locations)
|
17
|
-
queried_locations.any? { |other_location| other_location.match?(location) }
|
18
|
-
end
|
19
|
-
|
20
|
-
def describe_to(visitor, *args)
|
21
|
-
visitor.before_hook(self, *args)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
class AfterHook
|
26
|
-
include Cucumber.initializer(:location)
|
27
|
-
public :location
|
28
|
-
|
29
|
-
def name
|
30
|
-
"After hook"
|
31
|
-
end
|
32
|
-
|
33
|
-
def match_locations?(queried_locations)
|
34
|
-
queried_locations.any? { |other_location| other_location.match?(location) }
|
35
|
-
end
|
36
|
-
|
37
|
-
def describe_to(visitor, *args)
|
38
|
-
visitor.after_hook(self, *args)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
class AroundHook
|
43
|
-
def initialize(&block)
|
44
|
-
@block = block
|
45
|
-
end
|
46
|
-
|
47
|
-
def describe_to(visitor, *args, &continue)
|
48
|
-
visitor.around_hook(self, *args, &continue)
|
49
|
-
end
|
50
|
-
|
51
|
-
def call(continue)
|
52
|
-
@block.call(continue)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
class BeforeStepHook
|
57
|
-
include Cucumber.initializer(:location)
|
58
|
-
public :location
|
59
|
-
|
60
|
-
def name
|
61
|
-
"BeforeStep hook"
|
62
|
-
end
|
63
|
-
|
64
|
-
def match_locations?(queried_locations)
|
65
|
-
queried_locations.any? { |other_location| other_location.match?(location) }
|
66
|
-
end
|
67
|
-
|
68
|
-
def describe_to(visitor, *args)
|
69
|
-
visitor.before_step_hook(self, *args)
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
class AfterStepHook
|
74
|
-
include Cucumber.initializer(:location)
|
75
|
-
public :location
|
76
|
-
|
77
|
-
def name
|
78
|
-
"AfterStep hook"
|
79
|
-
end
|
80
|
-
|
81
|
-
def match_locations?(queried_locations)
|
82
|
-
queried_locations.any? { |other_location| other_location.match?(location) }
|
83
|
-
end
|
84
|
-
|
85
|
-
def describe_to(visitor, *args)
|
86
|
-
visitor.after_step_hook(self, *args)
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
end
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
@@ -1,150 +0,0 @@
|
|
1
|
-
require 'cucumber/initializer'
|
2
|
-
require 'cucumber/core/test/hooks'
|
3
|
-
|
4
|
-
module Cucumber
|
5
|
-
module Core
|
6
|
-
module Test
|
7
|
-
class Mapper
|
8
|
-
include Cucumber.initializer(:mapping_definition, :receiver)
|
9
|
-
|
10
|
-
def test_case(test_case, &descend)
|
11
|
-
hook_factory = HookFactory.new(test_case.source)
|
12
|
-
mapper = CaseMapper.new(mapping_definition)
|
13
|
-
test_case.describe_to mapping_definition, CaseMapper::DSL.new(mapper, hook_factory)
|
14
|
-
descend.call(mapper)
|
15
|
-
test_case.
|
16
|
-
with_steps(mapper.before_hooks + mapper.test_steps + mapper.after_hooks).
|
17
|
-
with_around_hooks(mapper.around_hooks).
|
18
|
-
describe_to(receiver)
|
19
|
-
self
|
20
|
-
end
|
21
|
-
|
22
|
-
def done
|
23
|
-
receiver.done
|
24
|
-
self
|
25
|
-
end
|
26
|
-
|
27
|
-
private
|
28
|
-
|
29
|
-
class CaseMapper
|
30
|
-
include Cucumber.initializer(:mapping_definition)
|
31
|
-
|
32
|
-
def test_step(test_step)
|
33
|
-
hook_factory = HookFactory.new(test_step.source)
|
34
|
-
mapper = StepMapper.new(test_step)
|
35
|
-
test_step.describe_to mapping_definition, StepMapper::DSL.new(mapper, hook_factory)
|
36
|
-
test_steps.push(*(mapper.before_step_hooks + [mapper.test_step] + mapper.after_step_hooks))
|
37
|
-
self
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_steps
|
41
|
-
@test_steps ||= []
|
42
|
-
end
|
43
|
-
|
44
|
-
def around_hooks
|
45
|
-
@around_hooks ||= []
|
46
|
-
end
|
47
|
-
|
48
|
-
def before_hooks
|
49
|
-
@before_hooks ||= []
|
50
|
-
end
|
51
|
-
|
52
|
-
def after_hooks
|
53
|
-
@after_hooks ||= []
|
54
|
-
end
|
55
|
-
|
56
|
-
# Passed to users in the mappings to add hooks to a scenario
|
57
|
-
class DSL
|
58
|
-
include Cucumber.initializer(:mapper, :hook_factory)
|
59
|
-
|
60
|
-
# Run this block of code before the scenario
|
61
|
-
def before(&block)
|
62
|
-
mapper.before_hooks << hook_factory.before(block)
|
63
|
-
self
|
64
|
-
end
|
65
|
-
|
66
|
-
# Run this block of code after the scenario
|
67
|
-
def after(&block)
|
68
|
-
mapper.after_hooks.unshift(hook_factory.after(block))
|
69
|
-
self
|
70
|
-
end
|
71
|
-
|
72
|
-
# Run this block of code around the scenario, with a yield in the block executing the scenario
|
73
|
-
def around(&block)
|
74
|
-
mapper.around_hooks << Hooks::AroundHook.new(&block)
|
75
|
-
self
|
76
|
-
end
|
77
|
-
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
class StepMapper
|
82
|
-
include Cucumber.initializer(:test_step)
|
83
|
-
|
84
|
-
attr_accessor :test_step
|
85
|
-
|
86
|
-
def before_step_hooks
|
87
|
-
@before_step_hooks ||= []
|
88
|
-
end
|
89
|
-
|
90
|
-
def after_step_hooks
|
91
|
-
@after_step_hooks ||= []
|
92
|
-
end
|
93
|
-
|
94
|
-
# Passed to users in the mappings to define and add hooks to a step
|
95
|
-
class DSL
|
96
|
-
include Cucumber.initializer(:mapper, :hook_factory)
|
97
|
-
|
98
|
-
def before(&block)
|
99
|
-
mapper.before_step_hooks << hook_factory.before_step(block)
|
100
|
-
end
|
101
|
-
|
102
|
-
# Define the step with a block of code to be executed
|
103
|
-
def map(&block)
|
104
|
-
mapper.test_step = mapper.test_step.with_mapping(&block)
|
105
|
-
self
|
106
|
-
end
|
107
|
-
|
108
|
-
# Define a block of code to be run after the step
|
109
|
-
def after(&block)
|
110
|
-
mapper.after_step_hooks << hook_factory.after_step(block)
|
111
|
-
self
|
112
|
-
end
|
113
|
-
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
class HookFactory
|
118
|
-
include Cucumber.initializer(:source)
|
119
|
-
|
120
|
-
def after(block)
|
121
|
-
build_hook_step(block, Hooks::AfterHook, Test::UnskippableAction)
|
122
|
-
end
|
123
|
-
|
124
|
-
def before(block)
|
125
|
-
build_hook_step(block, Hooks::BeforeHook, Test::UnskippableAction)
|
126
|
-
end
|
127
|
-
|
128
|
-
def before_step(block)
|
129
|
-
build_hook_step(block, Hooks::BeforeStepHook, Test::UnskippableAction)
|
130
|
-
end
|
131
|
-
|
132
|
-
def after_step(block)
|
133
|
-
build_hook_step(block, Hooks::AfterStepHook, Test::Action)
|
134
|
-
end
|
135
|
-
|
136
|
-
private
|
137
|
-
|
138
|
-
def build_hook_step(block, hook_type, mapping_type)
|
139
|
-
mapping = mapping_type.new(&block)
|
140
|
-
hook = hook_type.new(mapping.location)
|
141
|
-
Step.new(source + [hook], mapping)
|
142
|
-
end
|
143
|
-
|
144
|
-
end
|
145
|
-
|
146
|
-
|
147
|
-
end
|
148
|
-
end
|
149
|
-
end
|
150
|
-
end
|
data/lib/cucumber/initializer.rb
DELETED
@@ -1,18 +0,0 @@
|
|
1
|
-
module Cucumber
|
2
|
-
def self.initializer(*attributes)
|
3
|
-
Module.new do
|
4
|
-
attr_reader(*attributes)
|
5
|
-
private(*attributes)
|
6
|
-
|
7
|
-
define_method(:initialize) do |*arguments|
|
8
|
-
if attributes.size != arguments.size
|
9
|
-
raise ArgumentError, "wrong number of arguments (#{arguments.size} for #{attributes.size})"
|
10
|
-
end
|
11
|
-
|
12
|
-
attributes.zip(arguments) do |attribute, argument|
|
13
|
-
instance_variable_set("@#{attribute}", argument)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'cucumber/core/test/hooks'
|
2
|
-
module Cucumber::Core::Test::Hooks
|
3
|
-
shared_examples_for 'a source node' do
|
4
|
-
it "responds to name" do
|
5
|
-
expect( subject.name ).to be_a(String)
|
6
|
-
end
|
7
|
-
|
8
|
-
it "responds to location" do
|
9
|
-
expect( subject.location ).to eq(location)
|
10
|
-
end
|
11
|
-
|
12
|
-
it "responds to match_locations?" do
|
13
|
-
expect( subject.match_locations? [location] ).to be_truthy
|
14
|
-
expect( subject.match_locations? [] ).to be_falsey
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
require 'cucumber/core/ast/location'
|
19
|
-
describe BeforeHook do
|
20
|
-
subject { BeforeHook.new(location) }
|
21
|
-
let(:location) { Cucumber::Core::Ast::Location.new('hooks.rb', 1) }
|
22
|
-
it_behaves_like 'a source node'
|
23
|
-
end
|
24
|
-
|
25
|
-
describe AfterHook do
|
26
|
-
subject { AfterHook.new(location) }
|
27
|
-
let(:location) { Cucumber::Core::Ast::Location.new('hooks.rb', 1) }
|
28
|
-
it_behaves_like 'a source node'
|
29
|
-
end
|
30
|
-
end
|
@@ -1,203 +0,0 @@
|
|
1
|
-
require 'cucumber/core/test/mapper'
|
2
|
-
require 'cucumber/core/test/case'
|
3
|
-
require 'cucumber/core/test/step'
|
4
|
-
require 'cucumber/core/ast'
|
5
|
-
|
6
|
-
module Cucumber
|
7
|
-
module Core
|
8
|
-
module Test
|
9
|
-
describe Mapper do
|
10
|
-
|
11
|
-
ExampleMappings = Struct.new(:app) do
|
12
|
-
def test_case(test_case, mapper)
|
13
|
-
end
|
14
|
-
|
15
|
-
def test_step(test_step, mapper)
|
16
|
-
mapper.map { app.do_something } if test_step.name == 'mapped'
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
let(:mapper) { Mapper.new(mappings, receiver) }
|
21
|
-
let(:receiver) { double('receiver') }
|
22
|
-
before { allow(receiver).to receive(:test_case).and_yield(receiver) }
|
23
|
-
let(:mappings) { ExampleMappings.new(app) }
|
24
|
-
let(:app) { double('app') }
|
25
|
-
let(:last_result) { double('last_result') }
|
26
|
-
|
27
|
-
context "an unmapped step" do
|
28
|
-
let(:test_step) { Test::Step.new([double(name: 'unmapped')]) }
|
29
|
-
let(:test_case) { Test::Case.new([test_step], double) }
|
30
|
-
|
31
|
-
it "maps to a step that executes to an undefined result" do
|
32
|
-
expect( receiver ).to receive(:test_step) do |test_step|
|
33
|
-
expect( test_step.name ).to eq 'unmapped'
|
34
|
-
expect( test_step.execute(last_result) ).to be_undefined
|
35
|
-
end.once.ordered
|
36
|
-
test_case.describe_to mapper
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
context "a mapped step" do
|
41
|
-
let(:test_step) { Test::Step.new([double(name: 'mapped')]) }
|
42
|
-
let(:test_case) { Test::Case.new([test_step], double) }
|
43
|
-
|
44
|
-
it "maps to a step that executes the block" do
|
45
|
-
expect( receiver ).to receive(:test_step) do |test_step|
|
46
|
-
expect( test_step.name ).to eq 'mapped'
|
47
|
-
expect( app ).to receive(:do_something)
|
48
|
-
test_step.execute(last_result)
|
49
|
-
end.once.ordered
|
50
|
-
test_case.describe_to mapper
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
context "a combination" do
|
55
|
-
let(:mapped) { Test::Step.new([double(name: 'passing')]) }
|
56
|
-
let(:unmapped) { Test::Step.new([double(name: 'unmapped')]) }
|
57
|
-
let(:test_case) { Test::Case.new([mapped, unmapped], double) }
|
58
|
-
|
59
|
-
it "maps each of the test steps" do
|
60
|
-
expect( receiver ).to receive(:test_step) do |test_step|
|
61
|
-
expect( test_step.name ).to eq 'passing'
|
62
|
-
end.once.ordered
|
63
|
-
expect( receiver ).to receive(:test_step) do |test_step|
|
64
|
-
expect( test_step.name ).to eq 'unmapped'
|
65
|
-
end.once.ordered
|
66
|
-
test_case.describe_to mapper
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
context "mapping hooks" do
|
71
|
-
let(:test_case) { Case.new([test_step], source) }
|
72
|
-
let(:test_step) { Step.new([Ast::Step.new(:node, :language, :location, :keyword, :name, :multiline_arg)]) }
|
73
|
-
let(:source) { [feature, scenario] }
|
74
|
-
let(:feature) { double('feature') }
|
75
|
-
let(:scenario) { double('scenario', location: 'test') }
|
76
|
-
|
77
|
-
it "prepends before hooks to the test case" do
|
78
|
-
allow( mappings ).to receive(:test_case) do |test_case, mapper|
|
79
|
-
mapper.before {}
|
80
|
-
end
|
81
|
-
expect( receiver ).to receive(:test_case) do |test_case|
|
82
|
-
expect( test_case.step_count ).to eq 2
|
83
|
-
end
|
84
|
-
test_case.describe_to mapper
|
85
|
-
end
|
86
|
-
|
87
|
-
it "appends after hooks to the test case" do
|
88
|
-
allow( mappings ).to receive(:test_case) do |test_case, mapper|
|
89
|
-
mapper.after {}
|
90
|
-
end
|
91
|
-
expect( receiver ).to receive(:test_case) do |test_case|
|
92
|
-
expect( test_case.step_count ).to eq 2
|
93
|
-
end
|
94
|
-
test_case.describe_to mapper
|
95
|
-
end
|
96
|
-
|
97
|
-
it "adds hooks in the right order" do
|
98
|
-
log = double
|
99
|
-
allow(mappings).to receive(:test_case) do |test_case, mapper|
|
100
|
-
mapper.before { log.before_hook_1 }
|
101
|
-
mapper.before { log.before_hook_2 }
|
102
|
-
mapper.after { log.after_hook_1 }
|
103
|
-
mapper.after { log.after_hook_2 }
|
104
|
-
end
|
105
|
-
mapped_step = test_step.with_mapping { log.step_1 }
|
106
|
-
test_case = Case.new([mapped_step], source)
|
107
|
-
|
108
|
-
expect( log ).to receive(:before_hook_1).ordered
|
109
|
-
expect( log ).to receive(:before_hook_2).ordered
|
110
|
-
expect( log ).to receive(:step_1).ordered
|
111
|
-
expect( log ).to receive(:after_hook_2).ordered
|
112
|
-
expect( log ).to receive(:after_hook_1).ordered
|
113
|
-
|
114
|
-
allow(receiver).to receive(:test_case).and_yield(receiver)
|
115
|
-
allow(receiver).to receive(:test_step) do |test_step|
|
116
|
-
test_step.execute(last_result)
|
117
|
-
end
|
118
|
-
|
119
|
-
test_case.describe_to mapper
|
120
|
-
end
|
121
|
-
|
122
|
-
it "sets the source to include the before hook, scenario and feature" do
|
123
|
-
test_case = Case.new([], source)
|
124
|
-
allow(mappings).to receive(:test_case) do |test_case_to_be_mapped, mapper|
|
125
|
-
mapper.before {}
|
126
|
-
end
|
127
|
-
allow(receiver).to receive(:test_case).and_yield(receiver)
|
128
|
-
allow(receiver).to receive(:test_step) do |test_step|
|
129
|
-
args = double('args')
|
130
|
-
visitor = double('visitor')
|
131
|
-
expect( feature ).to receive(:describe_to)
|
132
|
-
expect( scenario ).to receive(:describe_to)
|
133
|
-
expect( visitor ).to receive(:before_hook) do |hook, hook_args|
|
134
|
-
expect( args ).to eq(hook_args)
|
135
|
-
expect( hook.location.to_s ).to eq("#{__FILE__}:125")
|
136
|
-
end
|
137
|
-
test_step.describe_source_to(visitor, args)
|
138
|
-
end
|
139
|
-
test_case.describe_to mapper
|
140
|
-
end
|
141
|
-
|
142
|
-
it "sets the source to include the after hook" do
|
143
|
-
test_case = Case.new([], source)
|
144
|
-
allow(mappings).to receive(:test_case) do |test_case_to_be_mapped, mapper|
|
145
|
-
mapper.after {}
|
146
|
-
end
|
147
|
-
allow(receiver).to receive(:test_case).and_yield(receiver)
|
148
|
-
allow(receiver).to receive(:test_step) do |test_step|
|
149
|
-
args = double('args')
|
150
|
-
visitor = double('visitor')
|
151
|
-
expect( feature ).to receive(:describe_to)
|
152
|
-
expect( scenario ).to receive(:describe_to)
|
153
|
-
expect( visitor ).to receive(:after_hook) do |hook, hook_args|
|
154
|
-
expect( args ).to eq(hook_args)
|
155
|
-
expect( hook.location.to_s ).to eq("#{__FILE__}:145")
|
156
|
-
end
|
157
|
-
test_step.describe_source_to(visitor, args)
|
158
|
-
end
|
159
|
-
test_case.describe_to mapper
|
160
|
-
end
|
161
|
-
|
162
|
-
it "appends after_step hooks to the test step" do
|
163
|
-
allow(mappings).to receive(:test_step) do |test_step, mapper|
|
164
|
-
mapper.after {}
|
165
|
-
end
|
166
|
-
args = double('args')
|
167
|
-
visitor = double('visitor')
|
168
|
-
allow(receiver).to receive(:test_case).and_yield(receiver)
|
169
|
-
allow(receiver).to receive(:test_step) do |test_step|
|
170
|
-
test_step.describe_source_to(visitor, args)
|
171
|
-
end
|
172
|
-
expect( visitor ).to receive(:step).ordered
|
173
|
-
expect( visitor ).to receive(:after_step_hook) do |hook, hook_args|
|
174
|
-
expect( args ).to eq(hook_args)
|
175
|
-
expect( hook.location.to_s ).to eq("#{__FILE__}:164")
|
176
|
-
end.once.ordered
|
177
|
-
expect( visitor ).to receive(:step).ordered
|
178
|
-
test_case.describe_to mapper
|
179
|
-
end
|
180
|
-
|
181
|
-
it "prepends before_step hooks to the test step" do
|
182
|
-
allow(mappings).to receive(:test_step) do |test_step, mapper|
|
183
|
-
mapper.before {}
|
184
|
-
end
|
185
|
-
args = double('args')
|
186
|
-
visitor = double('visitor')
|
187
|
-
allow(receiver).to receive(:test_case) do |test_case|
|
188
|
-
test_case.test_steps.first.describe_source_to(visitor, args)
|
189
|
-
end
|
190
|
-
expect( visitor ).to receive(:before_step_hook) do |hook, hook_args|
|
191
|
-
expect( args ).to eq(hook_args)
|
192
|
-
expect( hook.location.to_s ).to eq("#{__FILE__}:183")
|
193
|
-
end.once.ordered
|
194
|
-
expect( visitor ).to receive(:step).ordered
|
195
|
-
test_case.describe_to mapper
|
196
|
-
end
|
197
|
-
|
198
|
-
end
|
199
|
-
end
|
200
|
-
|
201
|
-
end
|
202
|
-
end
|
203
|
-
end
|