cucumber-gherkin 28.0.0 → 30.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,208 +0,0 @@
1
- require 'rspec'
2
- require 'gherkin'
3
- require 'gherkin/query'
4
-
5
- describe Gherkin::Query do
6
- let(:subject) { Gherkin::Query.new }
7
-
8
- def filter_messages_by_attribute(messages, attribute)
9
- messages.map do |message|
10
- return unless message.respond_to?(attribute)
11
- message.send(attribute)
12
- end.compact
13
- end
14
-
15
- def find_message_by_attribute(messages, attribute)
16
- filter_messages_by_attribute(messages, attribute).first
17
- end
18
-
19
- let(:gherkin_document) { find_message_by_attribute(messages, :gherkin_document) }
20
-
21
- let(:messages) do
22
- Gherkin.from_source(
23
- "some/path",
24
- feature_content,
25
- {
26
- include_gherkin_document: true
27
- }
28
- ).to_a
29
- end
30
-
31
- let(:feature_content) do
32
- """
33
- @feature-tag
34
- Feature: my feature
35
-
36
- Background:
37
- Given a passed background step
38
-
39
- @scenario-tag
40
- Scenario: my scenario
41
- Given a passed step
42
-
43
- Scenario Outline: with examples
44
- Given a <Status> step
45
-
46
- @examples-tag
47
- Examples:
48
- | Status |
49
- | passed |
50
- | failed |
51
-
52
- @rule-tag
53
- Rule: this is a rule
54
- Background:
55
- Given the passed step in the rule background
56
-
57
- @ruled-scenario-tag
58
- Scenario: a ruled scenario
59
- Given a step in the ruled scenario
60
- """
61
- end
62
-
63
- describe '#update' do
64
- context 'when the feature file is empty' do
65
- let(:feature_content) { '' }
66
-
67
- it 'does not fail' do
68
- expect do
69
- messages.each { |message| subject.update(message) }
70
- end.not_to raise_exception
71
- end
72
- end
73
- end
74
-
75
- describe '#scenario_parent_locations' do
76
- before do
77
- messages.each { |message| subject.update(message) }
78
- end
79
-
80
- let(:background) { find_message_by_attribute(gherkin_document.feature.children, :background) }
81
- let(:scenarios) { filter_messages_by_attribute(gherkin_document.feature.children, :scenario) }
82
-
83
- context 'without rule' do
84
- let(:scenario) { scenarios.first }
85
-
86
- it 'provides the feature and background locations of a given scenario node id' do
87
- expect(subject.scenario_parent_locations(scenario.id)).to eq([
88
- gherkin_document.feature.location,
89
- background.location,
90
- ])
91
- end
92
- end
93
-
94
- context 'with rule' do
95
- let(:rule) { find_message_by_attribute(gherkin_document.feature.children, :rule) }
96
- let(:rule_background) { find_message_by_attribute(rule.children, :background) }
97
- let(:scenario) { find_message_by_attribute(rule.children, :scenario) }
98
-
99
- it 'provides the feature, background, rule, and rule background locations of a given scenario node id' do
100
- expect(subject.scenario_parent_locations(scenario.id)).to eq([
101
- gherkin_document.feature.location,
102
- background.location,
103
- rule.location,
104
- rule_background.location,
105
- ])
106
- end
107
- end
108
-
109
- context 'in a scenario outline' do
110
- let(:scenario) { scenarios.last }
111
-
112
- it 'provides the feature and background locations of a given scenario outline node id' do
113
- expect(subject.scenario_parent_locations(scenario.id)).to eq([
114
- gherkin_document.feature.location,
115
- background.location,
116
- ])
117
- end
118
- end
119
-
120
- it 'raises an exception if called with an invalid id' do
121
- expect { subject.scenario_parent_locations("BAD") }.to raise_error(Gherkin::AstNodeNotLocatedException)
122
- end
123
- end
124
-
125
- describe '#location' do
126
- before do
127
- messages.each { |message| subject.update(message) }
128
- end
129
-
130
- let(:background) { find_message_by_attribute(gherkin_document.feature.children, :background) }
131
- let(:rule) { find_message_by_attribute(gherkin_document.feature.children, :rule) }
132
- let(:scenarios) { filter_messages_by_attribute(gherkin_document.feature.children, :scenario) }
133
- let(:scenario) { scenarios.first }
134
-
135
- it 'raises an exception when the AST node ID is unknown' do
136
- expect { subject.location("this-id-may-not-exist-for-real") }.to raise_exception(Gherkin::AstNodeNotLocatedException)
137
- end
138
-
139
- it 'provides the location of a scenario' do
140
- expect(subject.location(scenario.id)).to eq(scenario.location)
141
- end
142
-
143
- it 'provides the location of an examples table row' do
144
- node = scenarios.last.examples.first.table_body.first
145
- expect(subject.location(node.id)).to eq(node.location)
146
- end
147
-
148
- context 'when querying steps' do
149
- let(:background_step) { background.steps.first }
150
- let(:scenario_step) { scenario.steps.first }
151
-
152
- it 'provides the location of a background step' do
153
- expect(subject.location(background_step.id)).to eq(background_step.location)
154
- end
155
-
156
- it 'provides the location of a scenario step' do
157
- expect(subject.location(scenario_step.id)).to eq(scenario_step.location)
158
- end
159
- end
160
-
161
- context 'when querying tags' do
162
- let(:feature_tag) { gherkin_document.feature.tags.first }
163
- let(:rule_tag) { rule.tags.first }
164
- let(:scenario_tag) { scenario.tags.first }
165
- let(:examples_tag) { scenarios.last.examples.first.tags.first }
166
-
167
- it 'provides the location of a feature tags' do
168
- expect(subject.location(feature_tag.id)).to eq(feature_tag.location)
169
- end
170
-
171
- it 'provides the location of a scenario tags' do
172
- expect(subject.location(scenario_tag.id)).to eq(scenario_tag.location)
173
- end
174
-
175
- it 'provides the location of scenario examples tags' do
176
- expect(subject.location(examples_tag.id)).to eq(examples_tag.location)
177
- end
178
-
179
- it 'provides the location of a rule tag' do
180
- expect(subject.location(rule_tag.id)).to eq(rule_tag.location)
181
- end
182
- end
183
-
184
- context 'when children are scoped in a Rule' do
185
- let(:rule_background) { find_message_by_attribute(rule.children, :background) }
186
- let(:rule_background_step) { rule_background.steps.first }
187
- let(:rule_scenario) { find_message_by_attribute(rule.children, :scenario) }
188
- let(:rule_scenario_step) { rule_scenario.steps.first }
189
- let(:rule_scenario_tag) { rule_scenario.tags.first }
190
-
191
- it 'provides the location of a background step' do
192
- expect(subject.location(rule_background_step.id)).to eq(rule_background_step.location)
193
- end
194
-
195
- it 'provides the location of a scenario' do
196
- expect(subject.location(rule_scenario.id)).to eq(rule_scenario.location)
197
- end
198
-
199
- it 'provides the location of a scenario tag' do
200
- expect(subject.location(rule_scenario_tag.id)).to eq(rule_scenario_tag.location)
201
- end
202
-
203
- it 'provides the location of a scenario step' do
204
- expect(subject.location(rule_scenario_step.id)).to eq(rule_scenario_step.location)
205
- end
206
- end
207
- end
208
- end
@@ -1,67 +0,0 @@
1
- require 'rspec'
2
- require 'gherkin/stream/parser_message_stream'
3
-
4
- module Gherkin
5
- module Stream
6
- describe ParserMessageStream do
7
- let(:feature_content) {
8
- "Feature: my feature\n" \
9
- " Scenario: a scenario\n" \
10
- " Given some context"
11
- }
12
-
13
- let(:source_feature) {
14
- Cucumber::Messages::Source.new(
15
- uri: '//whatever/uri',
16
- data: feature_content,
17
- media_type: 'text/x.cucumber.gherkin+plain'
18
- )
19
- }
20
-
21
- let(:options) {
22
- {
23
- include_gherkin_document: true,
24
- }
25
- }
26
-
27
- let(:gherkin_document) {
28
- ParserMessageStream.new([], [source_feature], options).messages.first.gherkin_document
29
- }
30
-
31
- let(:scenario_id) { gherkin_document.feature.children.first.scenario.id }
32
-
33
- context '#messages' do
34
- it "raises an exception on second iteration" do
35
- messages = ParserMessageStream.new([], [source_feature], options).messages
36
-
37
- expect { messages.map(&:to_s) }.not_to raise_exception
38
- expect { messages.map(&:to_s) }.to raise_exception(Gherkin::DoubleIterationException)
39
- end
40
- end
41
-
42
- context 'options.id_generator' do
43
- context 'when not set' do
44
- it 'generates random UUIDs' do
45
- expect(scenario_id).to match(/[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}/)
46
- end
47
- end
48
-
49
-
50
- context 'when set' do
51
- let(:id_generator) { double }
52
- let(:options) {
53
- {
54
- include_gherkin_document: true,
55
- id_generator: id_generator
56
- }
57
- }
58
-
59
- it 'uses the generator instance to produce the IDs' do
60
- allow(id_generator).to receive(:new_id).and_return('some-random-id')
61
- expect(scenario_id).to eq('some-random-id')
62
- end
63
- end
64
- end
65
- end
66
- end
67
- end