Skip to content

Commit 16e4ed8

Browse files
committed
Do not create test cases for scenarios with no steps.
To be consistent with the (Pickle) compiler in the Gherkin library, test cases should not be created for scenarios with no steps.
1 parent 1aa0140 commit 16e4ed8

File tree

4 files changed

+19
-11
lines changed

4 files changed

+19
-11
lines changed

lib/cucumber/core/compiler.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def on_step(source)
4545
end
4646

4747
def on_test_case(source)
48-
Test::Case.new(test_steps, source).describe_to(receiver)
48+
Test::Case.new(test_steps, source).describe_to(receiver) if test_steps.count > 0
4949
@test_steps = nil
5050
self
5151
end

spec/cucumber/core/compiler_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,23 @@ def self.stubs(*names)
157157
end
158158
end
159159

160+
context 'empty scenarios' do
161+
it 'does not create test cases for them' do
162+
gherkin_documents = [
163+
gherkin do
164+
feature do
165+
scenario do
166+
end
167+
end
168+
end
169+
]
170+
compile(gherkin_documents) do |visitor|
171+
expect( visitor ).to receive(:test_case).never
172+
expect( visitor ).to receive(:done).once.ordered
173+
end
174+
end
175+
end
176+
160177
describe Compiler::FeatureCompiler do
161178
let(:receiver) { double('receiver') }
162179
let(:compiler) { Compiler::FeatureCompiler.new(receiver) }

spec/cucumber/core/test/case_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ module Test
277277
gherkin = Gherkin::Document.new('features/treasure.feature', %{# language: en-pirate
278278
Ahoy matey!: Treasure map
279279
Heave to: Find the treasure
280-
Gangway!: a map
280+
Gangway! a map
281281
})
282282
receiver = double.as_null_object
283283
expect( receiver ).to receive(:test_case) do |test_case|

spec/cucumber/core/test/filters/locations_filter_spec.rb

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,6 @@ module Cucumber::Core
9696
Given a table
9797
| a | b |
9898
| 1 | 2 |
99-
100-
Scenario: empty
10199
END
102100
end
103101

@@ -112,13 +110,6 @@ def test_case_named(name)
112110
expect(receiver.test_case_locations).to eq [test_case_named('two').location]
113111
end
114112

115-
it 'matches the precise location of an empty scenario' do
116-
location = test_case_named('empty').location
117-
filter = Test::LocationsFilter.new([location])
118-
compile [doc], receiver, [filter]
119-
expect(receiver.test_case_locations).to eq [test_case_named('empty').location]
120-
end
121-
122113
it 'matches multiple locations' do
123114
good_location = Ast::Location.new(file, 8)
124115
bad_location = Ast::Location.new(file, 5)

0 commit comments

Comments
 (0)