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,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,162 +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(:event_bus) { double }
|
12
|
-
let(:gherkin_query) { double }
|
13
|
-
let(:parser) { Parser.new(receiver, event_bus, gherkin_query) }
|
14
|
-
let(:visitor) { double }
|
15
|
-
|
16
|
-
before do
|
17
|
-
allow( event_bus ).to receive(:gherkin_source_parsed)
|
18
|
-
allow( event_bus).to receive(:envelope)
|
19
|
-
allow( gherkin_query ).to receive(:update)
|
20
|
-
end
|
21
|
-
|
22
|
-
def parse
|
23
|
-
parser.document(source)
|
24
|
-
end
|
25
|
-
|
26
|
-
context "for invalid gherkin" do
|
27
|
-
let(:source) { Gherkin::Document.new(path, "\nnot gherkin\n\nFeature: \n") }
|
28
|
-
let(:path) { 'path_to/the.feature' }
|
29
|
-
|
30
|
-
it "raises an error" do
|
31
|
-
expect { parse }.to raise_error(ParseError) do |error|
|
32
|
-
expect( error.message ).to match(/not gherkin/)
|
33
|
-
expect( error.message ).to match(/#{path}/)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
context "for valid gherkin" do
|
39
|
-
let(:source) { Gherkin::Document.new(path, 'Feature:') }
|
40
|
-
let(:path) { 'path_to/the.feature' }
|
41
|
-
|
42
|
-
it "issues a gherkin_source_parsed event" do
|
43
|
-
expect( event_bus ).to receive(:gherkin_source_parsed)
|
44
|
-
parse
|
45
|
-
end
|
46
|
-
|
47
|
-
it "emits an 'envelope' event for every message produced by Gherkin" do
|
48
|
-
# Only one message emited, there's no pickles generated
|
49
|
-
expect( event_bus ).to receive(:envelope).once
|
50
|
-
parse
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
context "for empty files" do
|
55
|
-
let(:source) { Gherkin::Document.new(path, '') }
|
56
|
-
let(:path) { 'path_to/the.feature' }
|
57
|
-
|
58
|
-
it "passes on no pickles" do
|
59
|
-
expect( receiver ).not_to receive(:pickle)
|
60
|
-
parse
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
include Writer
|
65
|
-
def self.source(&block)
|
66
|
-
let(:source) { gherkin(&block) }
|
67
|
-
end
|
68
|
-
|
69
|
-
RSpec::Matchers.define :pickle_with_language do |language|
|
70
|
-
match { |actual| actual.language == language }
|
71
|
-
end
|
72
|
-
|
73
|
-
context "when the Gherkin has a language header" do
|
74
|
-
source do
|
75
|
-
feature(language: 'ja', keyword: '機能') do
|
76
|
-
scenario(keyword: 'シナリオ')
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
it "the pickles have the correct language" do
|
81
|
-
expect( receiver ).to receive(:pickle).with(pickle_with_language('ja'))
|
82
|
-
parse
|
83
|
-
end
|
84
|
-
end
|
85
|
-
|
86
|
-
context "when the Gherkin produces one pickle" do
|
87
|
-
source do
|
88
|
-
feature do
|
89
|
-
scenario do
|
90
|
-
step 'text'
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
it "passes on the pickle" do
|
96
|
-
expect( receiver ).to receive(:pickle)
|
97
|
-
parse
|
98
|
-
end
|
99
|
-
|
100
|
-
it "emits an 'envelope' event containing the pickle" do
|
101
|
-
allow( receiver ).to receive(:pickle)
|
102
|
-
# Once for the gherkin document, once with the pickle
|
103
|
-
expect( event_bus ).to receive(:envelope).twice
|
104
|
-
parse
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
context "when scenario is inside a rule" do
|
109
|
-
source do
|
110
|
-
feature do
|
111
|
-
rule do
|
112
|
-
scenario name: "My scenario"
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
it "passes on the pickle" do
|
118
|
-
expect( receiver ).to receive(:pickle)
|
119
|
-
parse
|
120
|
-
end
|
121
|
-
end
|
122
|
-
|
123
|
-
context "when example is inside a rule" do
|
124
|
-
source do
|
125
|
-
feature do
|
126
|
-
rule do
|
127
|
-
example name: "My example"
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
it "passes on the pickle" do
|
133
|
-
expect( receiver ).to receive(:pickle)
|
134
|
-
parse
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
context "when there are multiple rules and scenarios or examples" do
|
139
|
-
source do
|
140
|
-
feature do
|
141
|
-
rule description: "First rule" do
|
142
|
-
scenario name: "Do not talk about the fight club" do
|
143
|
-
step 'text'
|
144
|
-
end
|
145
|
-
end
|
146
|
-
rule description: "Second rule" do
|
147
|
-
example name: "Do not talk about the fight club" do
|
148
|
-
step 'text'
|
149
|
-
end
|
150
|
-
end
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
it "passes on the pickles" do
|
155
|
-
expect( receiver ).to receive(:pickle).twice
|
156
|
-
parse
|
157
|
-
end
|
158
|
-
end
|
159
|
-
end
|
160
|
-
end
|
161
|
-
end
|
162
|
-
end
|