cucumber-core 3.0.0 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/lib/cucumber/core/version.rb +1 -1
  3. metadata +19 -85
  4. data/.coveralls.yml +0 -1
  5. data/.github/ISSUE_TEMPLATE.md +0 -48
  6. data/.github/PULL_REQUEST_TEMPLATE.md +0 -39
  7. data/.rspec +0 -1
  8. data/.ruby-gemset +0 -1
  9. data/.travis.yml +0 -30
  10. data/.yardopts +0 -6
  11. data/Gemfile +0 -2
  12. data/Rakefile +0 -28
  13. data/cucumber-core.gemspec +0 -36
  14. data/spec/capture_warnings.rb +0 -74
  15. data/spec/coverage.rb +0 -11
  16. data/spec/cucumber/core/ast/background_spec.rb +0 -11
  17. data/spec/cucumber/core/ast/data_table_spec.rb +0 -81
  18. data/spec/cucumber/core/ast/doc_string_spec.rb +0 -114
  19. data/spec/cucumber/core/ast/empty_multiline_argument_spec.rb +0 -28
  20. data/spec/cucumber/core/ast/examples_table_spec.rb +0 -113
  21. data/spec/cucumber/core/ast/location_spec.rb +0 -199
  22. data/spec/cucumber/core/ast/outline_step_spec.rb +0 -93
  23. data/spec/cucumber/core/ast/step_spec.rb +0 -174
  24. data/spec/cucumber/core/compiler_spec.rb +0 -267
  25. data/spec/cucumber/core/event_bus_spec.rb +0 -163
  26. data/spec/cucumber/core/event_spec.rb +0 -40
  27. data/spec/cucumber/core/filter_spec.rb +0 -101
  28. data/spec/cucumber/core/gherkin/parser_spec.rb +0 -261
  29. data/spec/cucumber/core/gherkin/writer_spec.rb +0 -333
  30. data/spec/cucumber/core/report/summary_spec.rb +0 -175
  31. data/spec/cucumber/core/test/action_spec.rb +0 -154
  32. data/spec/cucumber/core/test/case_spec.rb +0 -316
  33. data/spec/cucumber/core/test/duration_matcher.rb +0 -20
  34. data/spec/cucumber/core/test/filters/locations_filter_spec.rb +0 -405
  35. data/spec/cucumber/core/test/result_spec.rb +0 -474
  36. data/spec/cucumber/core/test/runner_spec.rb +0 -310
  37. data/spec/cucumber/core/test/step_spec.rb +0 -98
  38. data/spec/cucumber/core/test/timer_spec.rb +0 -25
  39. data/spec/cucumber/core_spec.rb +0 -262
  40. data/spec/readme_spec.rb +0 -37
  41. data/spec/report_api_spy.rb +0 -25
@@ -1,163 +0,0 @@
1
- require "cucumber/core/event_bus"
2
-
3
- module Cucumber
4
- module Core
5
- module Events
6
-
7
- class TestEvent < Core::Event.new(:some_attribute)
8
- end
9
-
10
- AnotherTestEvent = Core::Event.new
11
-
12
- UnregisteredEvent = Core::Event.new
13
- end
14
-
15
- describe EventBus do
16
- let(:event_bus) { EventBus.new(registry) }
17
- let(:registry) { { test_event: Events::TestEvent, another_test_event: Events::AnotherTestEvent } }
18
-
19
- context "broadcasting events" do
20
-
21
- it "can broadcast by calling a method named after the event ID" do
22
- called = false
23
- event_bus.on(:test_event) {called = true }
24
- event_bus.test_event
25
- expect(called).to be true
26
- end
27
-
28
- it "can broadcast by calling the `broadcast` method with an instance of the event type" do
29
- called = false
30
- event_bus.on(:test_event) {called = true }
31
- event_bus.broadcast(Events::TestEvent.new(:some_attribute))
32
- expect(called).to be true
33
- end
34
-
35
- it "calls a subscriber for an event, passing details of the event" do
36
- received_payload = nil
37
- event_bus.on :test_event do |event|
38
- received_payload = event
39
- end
40
-
41
- event_bus.test_event :some_attribute
42
-
43
- expect(received_payload.some_attribute).to eq(:some_attribute)
44
- end
45
-
46
- it "does not call subscribers for other events" do
47
- handler_called = false
48
- event_bus.on :test_event do
49
- handler_called = true
50
- end
51
-
52
- event_bus.another_test_event
53
-
54
- expect(handler_called).to eq(false)
55
- end
56
-
57
- it "broadcasts to multiple subscribers" do
58
- received_events = []
59
- event_bus.on :test_event do
60
- received_events << :event
61
- end
62
- event_bus.on :test_event do
63
- received_events << :event
64
- end
65
-
66
- event_bus.test_event(:some_attribute)
67
-
68
- expect(received_events.length).to eq 2
69
- end
70
-
71
- it "raises an error when given an event to broadcast that it doesn't recognise" do
72
- expect { event_bus.some_unknown_event }.to raise_error(NameError)
73
- end
74
-
75
- context "#broadcast method" do
76
- it "must be passed an instance of a registered event type" do
77
- expect {
78
- event_bus.broadcast Events::UnregisteredEvent
79
- }.to raise_error(ArgumentError)
80
- end
81
- end
82
-
83
- end
84
-
85
- context "subscribing to events" do
86
- it "allows subscription by symbol (Event ID)" do
87
- received_payload = nil
88
- event_bus.on(:test_event) do |event|
89
- received_payload = event
90
- end
91
-
92
- event_bus.test_event :some_attribute
93
-
94
- expect(received_payload.some_attribute).to eq(:some_attribute)
95
- end
96
-
97
- it "raises an error if you use an unknown Event ID" do
98
- expect {
99
- event_bus.on(:some_unknown_event) { :whatever }
100
- }.to raise_error(ArgumentError)
101
- end
102
-
103
- it "allows handlers that are objects with a `call` method" do
104
- class MyHandler
105
- attr_reader :received_payload
106
-
107
- def call(event)
108
- @received_payload = event
109
- end
110
- end
111
-
112
- handler = MyHandler.new
113
- event_bus.on(:test_event, handler)
114
-
115
- event_bus.test_event :some_attribute
116
-
117
- expect(handler.received_payload.some_attribute).to eq :some_attribute
118
- end
119
-
120
- it "allows handlers that are procs" do
121
- class MyProccyHandler
122
- attr_reader :received_payload
123
-
124
- def initialize(event_bus)
125
- event_bus.on :test_event, &method(:on_test_event)
126
- end
127
-
128
- def on_test_event(event)
129
- @received_payload = event
130
- end
131
- end
132
-
133
- handler = MyProccyHandler.new(event_bus)
134
-
135
- event_bus.test_event :some_attribute
136
- expect(handler.received_payload.some_attribute).to eq :some_attribute
137
- end
138
-
139
- it "sends events that were broadcast before you subscribed" do
140
- event_bus.test_event :some_attribute
141
- event_bus.another_test_event
142
-
143
- received_payload = nil
144
- event_bus.on(:test_event) do |event|
145
- received_payload = event
146
- end
147
-
148
- expect(received_payload.some_attribute).to eq(:some_attribute)
149
- end
150
-
151
- end
152
-
153
- it "will let you inspect the registry" do
154
- expect(event_bus.event_types[:test_event]).to eq Events::TestEvent
155
- end
156
-
157
- it "won't let you modify the registry" do
158
- expect { event_bus.event_types[:foo] = :bar }.to raise_error(RuntimeError)
159
- end
160
-
161
- end
162
- end
163
- end
@@ -1,40 +0,0 @@
1
- require 'cucumber/core/event'
2
-
3
- module Cucumber
4
- module Core
5
- describe Event do
6
-
7
- describe ".new" do
8
- it "generates new types of events" do
9
- my_event_type = Event.new
10
- my_event = my_event_type.new
11
- expect(my_event).to be_kind_of(Core::Event)
12
- end
13
-
14
- it "generates events with attributes" do
15
- my_event_type = Event.new(:foo, :bar)
16
- my_event = my_event_type.new(1,2)
17
- expect(my_event.attributes).to eq [1, 2]
18
- expect(my_event.foo).to eq 1
19
- expect(my_event.bar).to eq 2
20
- end
21
- end
22
-
23
- describe "a generated event" do
24
- class MyEventType < Event.new(:foo, :bar)
25
- end
26
-
27
- it "can be converted to a hash" do
28
- my_event = MyEventType.new(1,2)
29
- expect(my_event.to_h).to eq foo: 1, bar: 2
30
- end
31
-
32
- it "has an event_id" do
33
- expect(MyEventType.event_id).to eq :my_event_type
34
- expect(MyEventType.new(1,2).event_id).to eq :my_event_type
35
- end
36
- end
37
- end
38
-
39
- end
40
- end
@@ -1,101 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'cucumber/core/gherkin/writer'
3
- require 'cucumber/core'
4
- require 'cucumber/core/filter'
5
-
6
- module Cucumber::Core
7
- describe Filter do
8
- include Cucumber::Core::Gherkin::Writer
9
- include Cucumber::Core
10
-
11
- describe ".new" do
12
- let(:receiver) { double.as_null_object }
13
-
14
- let(:doc) {
15
- gherkin do
16
- feature do
17
- scenario 'x' do
18
- step 'a step'
19
- end
20
-
21
- scenario 'y' do
22
- step 'a step'
23
- end
24
- end
25
- end
26
- }
27
-
28
- it "creates a filter class that can pass-through by default" do
29
- my_filter_class = Filter.new
30
- my_filter = my_filter_class.new
31
- expect(receiver).to receive(:test_case) { |test_case|
32
- expect(test_case.test_steps.length).to eq 1
33
- expect(test_case.test_steps.first.text).to eq 'a step'
34
- }.exactly(2).times
35
- compile [doc], receiver, [my_filter]
36
- end
37
-
38
- context "customizing by subclassing" do
39
-
40
- # Each filter imlicitly gets a :receiver attribute
41
- # that you need to call with the new test case
42
- # once you've received yours and modified it.
43
- class BasicBlankingFilter < Filter.new
44
- def test_case(test_case)
45
- test_case.with_steps([]).describe_to(receiver)
46
- end
47
- end
48
-
49
- # You can pass the names of attributes when building a
50
- # filter, allowing you to have custom attributes.
51
- class NamedBlankingFilter < Filter.new(:name_pattern)
52
- def test_case(test_case)
53
- if test_case.name =~ name_pattern
54
- test_case.with_steps([]).describe_to(receiver)
55
- else
56
- test_case.describe_to(receiver) # or just call `super`
57
- end
58
- self
59
- end
60
- end
61
-
62
- it "can override methods from the base class" do
63
- expect(receiver).to receive(:test_case) { |test_case|
64
- expect(test_case.test_steps.length).to eq 0
65
- }.exactly(2).times
66
- run BasicBlankingFilter.new
67
- end
68
-
69
- it "can take arguments" do
70
- expect(receiver).to receive(:test_case) { |test_case|
71
- expect(test_case.test_steps.length).to eq 0
72
- }.once.ordered
73
- expect(receiver).to receive(:test_case) { |test_case|
74
- expect(test_case.test_steps.length).to eq 1
75
- }.once.ordered
76
- run NamedBlankingFilter.new(/x/)
77
- end
78
-
79
- end
80
-
81
- context "customizing by using a block" do
82
- BlockBlankingFilter = Filter.new do
83
- def test_case(test_case)
84
- test_case.with_steps([]).describe_to(receiver)
85
- end
86
- end
87
-
88
- it "allows methods to be overridden" do
89
- expect(receiver).to receive(:test_case) { |test_case|
90
- expect(test_case.test_steps.length).to eq 0
91
- }.exactly(2).times
92
- run BlockBlankingFilter.new
93
- end
94
- end
95
-
96
- def run(filter)
97
- compile [doc], receiver, [filter]
98
- end
99
- end
100
- end
101
- end
@@ -1,261 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- # frozen_string_literal: true
3
- require 'cucumber/core/gherkin/parser'
4
- require 'cucumber/core/gherkin/writer'
5
-
6
- module Cucumber
7
- module Core
8
- module Gherkin
9
- describe Parser do
10
- let(:receiver) { double }
11
- let(:parser) { Parser.new(receiver) }
12
- let(:visitor) { double }
13
-
14
- def parse
15
- parser.document(source)
16
- end
17
-
18
- context "for invalid gherkin" do
19
- let(:source) { Gherkin::Document.new(path, "\nnot gherkin\n\nFeature: \n") }
20
- let(:path) { 'path_to/the.feature' }
21
-
22
- it "raises an error" do
23
- expect { parse }.to raise_error(ParseError) do |error|
24
- expect( error.message ).to match(/not gherkin/)
25
- expect( error.message ).to match(/#{path}/)
26
- end
27
- end
28
- end
29
-
30
- RSpec::Matchers.define :a_null_feature do
31
- match do |actual|
32
- allow( visitor ).to receive(:feature).and_throw
33
-
34
- actual.describe_to( visitor )
35
- end
36
- end
37
-
38
- context "for empty files" do
39
- let(:source) { Gherkin::Document.new(path, '') }
40
- let(:path) { 'path_to/the.feature' }
41
-
42
- it "creates a NullFeature" do
43
- expect( receiver ).to receive(:feature).with(a_null_feature)
44
- parse
45
- end
46
- end
47
-
48
- include Writer
49
- def self.source(&block)
50
- let(:source) { gherkin(&block) }
51
- end
52
-
53
- def feature
54
- result = nil
55
- allow( receiver ).to receive(:feature) { |feature| result = feature }
56
- parse
57
- result
58
- end
59
-
60
- context "when the Gherkin has a language header" do
61
- source do
62
- feature(language: 'ja', keyword: '機能')
63
- end
64
-
65
- it "sets the language from the Gherkin" do
66
- expect( feature.language.iso_code ).to eq 'ja'
67
- end
68
- end
69
-
70
- context "a Scenario with a DocString" do
71
- source do
72
- feature do
73
- scenario do
74
- step do
75
- doc_string("content")
76
- end
77
- end
78
- end
79
- end
80
-
81
- it "parses doc strings without error" do
82
- allow( visitor ).to receive(:feature).and_yield(visitor)
83
- allow( visitor ).to receive(:scenario).and_yield(visitor)
84
- allow( visitor ).to receive(:step).and_yield(visitor)
85
-
86
- location = double
87
- expected = Ast::DocString.new("content", "", location)
88
- expect( visitor ).to receive(:doc_string).with(expected)
89
- feature.describe_to(visitor)
90
- end
91
-
92
- end
93
-
94
- context "a Scenario with a DataTable" do
95
- source do
96
- feature do
97
- scenario do
98
- step do
99
- table do
100
- row "name", "surname"
101
- row "rob", "westgeest"
102
- end
103
- end
104
- end
105
- end
106
- end
107
-
108
- it "parses the DataTable" do
109
- visitor = double
110
- allow( visitor ).to receive(:feature).and_yield(visitor)
111
- allow( visitor ).to receive(:scenario).and_yield(visitor)
112
- allow( visitor ).to receive(:step).and_yield(visitor)
113
-
114
- expected = Ast::DataTable.new([['name', 'surname'], ['rob', 'westgeest']], Ast::Location.new('foo.feature', 23))
115
- expect( visitor ).to receive(:data_table).with(expected)
116
- feature.describe_to(visitor)
117
- end
118
- end
119
-
120
- context "a feature file with a comments on different levels" do
121
- source do
122
- comment 'feature comment'
123
- feature do
124
- comment 'scenario comment'
125
- scenario do
126
- comment 'step comment'
127
- step
128
- end
129
- comment 'scenario outline comment'
130
- scenario_outline do
131
- comment 'outline step comment'
132
- step
133
- comment 'examples comment'
134
- examples do
135
- row
136
- row
137
- end
138
- end
139
- end
140
- end
141
-
142
- it "the comments are distibuted to down the ast tree from the feature" do
143
- visitor = double
144
- expect( visitor ).to receive(:feature) do |feature|
145
- expect( feature.comments.join ).to eq "# feature comment"
146
- visitor
147
- end.and_yield(visitor)
148
- expect( visitor ).to receive(:scenario) do |scenario|
149
- expect( scenario.comments.join ).to eq " # scenario comment"
150
- end.and_yield(visitor)
151
- expect( visitor ).to receive(:step) do |step|
152
- expect( step.comments.join ).to eq " # step comment"
153
- end.and_yield(visitor)
154
- expect( visitor ).to receive(:scenario_outline) do |scenario_outline|
155
- expect( scenario_outline.comments.join ).to eq " # scenario outline comment"
156
- end.and_yield(visitor)
157
- expect( visitor ).to receive(:outline_step) do |outline_step|
158
- expect( outline_step.comments.join ).to eq " # outline step comment"
159
- end.and_yield(visitor)
160
- expect( visitor ).to receive(:examples_table) do |examples_table|
161
- expect( examples_table.comments.join ).to eq " # examples comment"
162
- end
163
- feature.describe_to(visitor)
164
- end
165
- end
166
-
167
- context "a Scenario Outline" do
168
- source do
169
- feature do
170
- scenario_outline 'outline name' do
171
- step 'passing <arg>'
172
-
173
- examples do
174
- row 'arg'
175
- row '1'
176
- row '2'
177
- end
178
-
179
- examples do
180
- row 'arg'
181
- row 'a'
182
- end
183
- end
184
- end
185
- end
186
-
187
- it "creates a scenario outline node" do
188
- allow( visitor ).to receive(:feature).and_yield(visitor)
189
- expect( visitor ).to receive(:scenario_outline) do |outline|
190
- expect( outline.name ).to eq 'outline name'
191
- end
192
- feature.describe_to(visitor)
193
- end
194
-
195
- it "creates a step node for each step of the scenario outline" do
196
- allow( visitor ).to receive(:feature).and_yield(visitor)
197
- allow( visitor ).to receive(:scenario_outline).and_yield(visitor)
198
- allow( visitor ).to receive(:examples_table)
199
- expect( visitor ).to receive(:outline_step) do |step|
200
- expect( step.text ).to eq 'passing <arg>'
201
- end
202
- feature.describe_to(visitor)
203
- end
204
-
205
- it "creates an examples table node for each examples table" do
206
- allow( visitor ).to receive(:feature).and_yield(visitor)
207
- allow( visitor ).to receive(:scenario_outline).and_yield(visitor)
208
- allow( visitor ).to receive(:outline_step)
209
- expect( visitor ).to receive(:examples_table).exactly(2).times.and_yield(visitor)
210
- expect( visitor ).to receive(:examples_table_row) do |row|
211
- expect( row.number ).to eq 1
212
- expect( row.values ).to eq ['1']
213
- end.once.ordered
214
- expect( visitor ).to receive(:examples_table_row) do |row|
215
- expect( row.number ).to eq 2
216
- expect( row.values ).to eq ['2']
217
- end.once.ordered
218
- expect( visitor ).to receive(:examples_table_row) do |row|
219
- expect( row.number ).to eq 1
220
- expect( row.values ).to eq ['a']
221
- end.once.ordered
222
- feature.describe_to(visitor)
223
- end
224
-
225
- end
226
-
227
- context "a Scenario Outline with an empty examples table" do
228
- source do
229
- feature do
230
- scenario_outline 'outline name' do
231
- step 'passing <arg>'
232
-
233
- examples do
234
- end
235
- end
236
- end
237
- end
238
-
239
- it "creates an examples table node but no example table rows" do
240
- allow( visitor ).to receive(:feature).and_yield(visitor)
241
- allow( visitor ).to receive(:scenario_outline).and_yield(visitor)
242
- allow( visitor ).to receive(:outline_step)
243
- expect( visitor ).to receive(:examples_table).and_yield(visitor)
244
- expect( visitor ).to receive(:examples_table_row).exactly(0).times
245
- feature.describe_to(visitor)
246
- end
247
-
248
- end
249
-
250
- context "a Scenario Outline with no Examples" do
251
- source do
252
- feature(language: 'not-a-language')
253
- end
254
- it "throws an error" do
255
- expect { feature.describe_to(double.as_null_object) }.to raise_error(ParseError)
256
- end
257
- end
258
- end
259
- end
260
- end
261
- end