Skip to content

Commit ddd9633

Browse files
committed
Merge #143 'Handle selective strict settings'
Also update History.md.
2 parents 1aa0140 + 51eee9c commit ddd9633

File tree

5 files changed

+153
-25
lines changed

5 files changed

+153
-25
lines changed

HISTORY.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
## [In Git](https://github.com/cucumber/cucumber-ruby-core/compare/3.0.0.pre.2...master)
22

33
### New Features
4+
* Handle selective strict settings. ([#143](https://github.com/cucumber/cucumber-ruby-core/pull/143) @brasmusson)
5+
46
### Bugfixes
7+
58
### Removed Features
9+
610
### Refactoring
711
* Use past tense in event names (`xStarting` -> `xStarted`) (see [cucumber/cucumber-ruby#1166](https://github.com/cucumber/cucumber-ruby/issues/1166) @brasmusson).
812

lib/cucumber/core/report/summary.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def initialize(event_bus)
1212
subscribe_to(event_bus)
1313
end
1414

15-
def ok?(be_strict = false)
15+
def ok?(be_strict = Test::Result::StrictConfiguration.new)
1616
test_cases.ok?(be_strict)
1717
end
1818

lib/cucumber/core/test/result.rb

Lines changed: 58 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ module Core
66
module Test
77
module Result
88
TYPES = [:failed, :flaky, :skipped, :undefined, :pending, :passed, :unknown].freeze
9+
STRICT_AFFECTED_TYPES = [:flaky, :undefined, :pending].freeze
910

10-
def self.ok?(type, be_strict = false)
11+
def self.ok?(type, be_strict = StrictConfiguration.new)
1112
private
1213
class_name = type.to_s.slice(0, 1).capitalize + type.to_s.slice(1..-1)
13-
const_get(class_name).ok?(be_strict)
14+
const_get(class_name).ok?(be_strict.strict?(type))
1415
end
1516

1617
# Defines to_sym on a result class for the given result type
@@ -67,8 +68,8 @@ def to_s
6768
"✓"
6869
end
6970

70-
def ok?(be_strict = false)
71-
self.class.ok?(be_strict)
71+
def ok?(be_strict = nil)
72+
self.class.ok?
7273
end
7374

7475
def with_appended_backtrace(step)
@@ -106,8 +107,8 @@ def to_s
106107
"✗"
107108
end
108109

109-
def ok?(be_strict = false)
110-
self.class.ok?(be_strict)
110+
def ok?(be_strict = nil)
111+
self.class.ok?
111112
end
112113

113114
def with_duration(new_duration)
@@ -164,8 +165,8 @@ def with_filtered_backtrace(filter)
164165
filter.new(dup).exception
165166
end
166167

167-
def ok?(be_strict = false)
168-
self.class.ok?(be_strict)
168+
def ok?(be_strict = StrictConfiguration.new)
169+
self.class.ok?(be_strict.strict?(to_sym))
169170
end
170171
end
171172

@@ -223,6 +224,54 @@ def to_s
223224
end
224225
end
225226

227+
# Handles the strict settings for the result types that are
228+
# affected by the strict options (that is the STRICT_AFFECTED_TYPES).
229+
class StrictConfiguration
230+
attr_accessor :settings
231+
private :settings
232+
233+
def initialize(strict_types = [])
234+
@settings = Hash[STRICT_AFFECTED_TYPES.map { |t| [t, :default] }]
235+
strict_types.each do |type|
236+
set_strict(true, type)
237+
end
238+
end
239+
240+
def strict?(type = nil)
241+
if type.nil?
242+
settings.each do |_key, value|
243+
return true if value == true
244+
end
245+
false
246+
else
247+
return false unless settings.key?(type)
248+
return false unless set?(type)
249+
settings[type]
250+
end
251+
end
252+
253+
def set_strict(setting, type = nil)
254+
if type.nil?
255+
STRICT_AFFECTED_TYPES.each do |t|
256+
set_strict(setting, t)
257+
end
258+
else
259+
settings[type] = setting
260+
end
261+
end
262+
263+
def merge!(other)
264+
settings.keys.each do |type|
265+
set_strict(other.strict?(type), type) if other.set?(type)
266+
end
267+
self
268+
end
269+
270+
def set?(type)
271+
settings[type] != :default
272+
end
273+
end
274+
226275
#
227276
# An object that responds to the description protocol from the results
228277
# and collects summary information.
@@ -250,7 +299,7 @@ def method_missing(name, *args)
250299
end
251300
end
252301

253-
def ok?(be_strict = false)
302+
def ok?(be_strict = StrictConfiguration.new)
254303
TYPES.each do |type|
255304
if get_total(type) > 0
256305
return false unless Result.ok?(type, be_strict)

spec/cucumber/core/report/summary_spec.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,14 +159,16 @@ module Cucumber::Core::Report
159159
event_bus.send(:test_case_finished, test_case, pending_result)
160160

161161
expect( @summary.ok? ).to eq true
162-
expect( @summary.ok?(true) ).to eq false
162+
be_strict = ::Cucumber::Core::Test::Result::StrictConfiguration.new([:pending])
163+
expect( @summary.ok?(be_strict) ).to eq false
163164
end
164165

165166
it "undefined test case is ok if not strict" do
166167
event_bus.send(:test_case_finished, test_case, undefined_result)
167168

168169
expect( @summary.ok? ).to eq true
169-
expect( @summary.ok?(true) ).to eq false
170+
be_strict = ::Cucumber::Core::Test::Result::StrictConfiguration.new([:undefined])
171+
expect( @summary.ok?(be_strict) ).to eq false
170172
end
171173
end
172174
end

spec/cucumber/core/test/result_spec.rb

Lines changed: 86 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ module Cucumber::Core::Test
4949
specify { expect( result ).not_to be_flaky }
5050

5151
specify { expect( result ).to be_ok }
52-
specify { expect( result.ok?(false) ).to be_truthy }
53-
specify { expect( result.ok?(true) ).to be_truthy }
52+
specify { expect( result.ok? ).to be_truthy }
5453
end
5554

5655
describe Result::Failed do
@@ -109,8 +108,7 @@ module Cucumber::Core::Test
109108
specify { expect( result ).not_to be_flaky }
110109

111110
specify { expect( result ).to_not be_ok }
112-
specify { expect( result.ok?(false) ).to be_falsey }
113-
specify { expect( result.ok?(true) ).to be_falsey }
111+
specify { expect( result.ok? ).to be_falsey }
114112
end
115113

116114
describe Result::Unknown do
@@ -202,8 +200,9 @@ module Cucumber::Core::Test
202200
specify { expect( result ).not_to be_flaky }
203201

204202
specify { expect( result ).to be_ok }
205-
specify { expect( result.ok?(false) ).to be_truthy }
206-
specify { expect( result.ok?(true) ).to be_falsey }
203+
specify { expect( result.ok? ).to be_truthy }
204+
be_strict = Result::StrictConfiguration.new([:undefined])
205+
specify { expect( result.ok?(be_strict) ).to be_falsey }
207206
end
208207

209208
describe Result::Skipped do
@@ -225,8 +224,7 @@ module Cucumber::Core::Test
225224
specify { expect( result ).not_to be_flaky }
226225

227226
specify { expect( result ).to be_ok }
228-
specify { expect( result.ok?(false) ).to be_truthy }
229-
specify { expect( result.ok?(true) ).to be_truthy }
227+
specify { expect( result.ok? ).to be_truthy }
230228
end
231229

232230
describe Result::Pending do
@@ -249,15 +247,87 @@ module Cucumber::Core::Test
249247
specify { expect( result ).to be_pending }
250248

251249
specify { expect( result ).to be_ok }
252-
specify { expect( result.ok?(false) ).to be_truthy }
253-
specify { expect( result.ok?(true) ).to be_falsey }
250+
specify { expect( result.ok? ).to be_truthy }
251+
be_strict = Result::StrictConfiguration.new([:pending])
252+
specify { expect( result.ok?(be_strict) ).to be_falsey }
254253
end
255254

256255
describe Result::Flaky do
257256
specify { expect( Result::Flaky.ok?(false) ).to be_truthy }
258257
specify { expect( Result::Flaky.ok?(true) ).to be_falsey }
259258
end
260259

260+
describe Result::StrictConfiguration do
261+
subject(:strict_configuration) { Result::StrictConfiguration.new}
262+
263+
describe '#set_strict' do
264+
context 'no type argument' do
265+
it 'sets all result types to the setting argument' do
266+
strict_configuration.set_strict(true)
267+
expect( strict_configuration.strict?(:undefined) ).to be_truthy
268+
expect( strict_configuration.strict?(:pending) ).to be_truthy
269+
expect( strict_configuration.strict?(:flaky) ).to be_truthy
270+
271+
strict_configuration.set_strict(false)
272+
expect( strict_configuration.strict?(:undefined) ).to be_falsey
273+
expect( strict_configuration.strict?(:pending) ).to be_falsey
274+
expect( strict_configuration.strict?(:flaky) ).to be_falsey
275+
end
276+
end
277+
context 'with type argument' do
278+
it 'sets the specified result type to the setting argument' do
279+
strict_configuration.set_strict(true, :undefined)
280+
expect( strict_configuration.strict?(:undefined) ).to be_truthy
281+
expect( strict_configuration.set?(:pending) ).to be_falsey
282+
expect( strict_configuration.set?(:flaky) ).to be_falsey
283+
284+
strict_configuration.set_strict(false, :undefined)
285+
expect( strict_configuration.strict?(:undefined) ).to be_falsey
286+
expect( strict_configuration.set?(:pending) ).to be_falsey
287+
expect( strict_configuration.set?(:flaky) ).to be_falsey
288+
end
289+
end
290+
end
291+
292+
describe '#strict?' do
293+
context 'no type argument' do
294+
it 'returns true if any result type is set to strict' do
295+
strict_configuration.set_strict(false, :pending)
296+
expect( strict_configuration.strict? ).to be_falsey
297+
298+
strict_configuration.set_strict(true, :flaky)
299+
expect( strict_configuration.strict? ).to be_truthy
300+
end
301+
end
302+
context 'with type argument' do
303+
it 'returns true if the specified result type is set to strict' do
304+
strict_configuration.set_strict(false, :pending)
305+
strict_configuration.set_strict(true, :flaky)
306+
307+
expect( strict_configuration.strict?(:undefined) ).to be_falsey
308+
expect( strict_configuration.strict?(:pending) ).to be_falsey
309+
expect( strict_configuration.strict?(:flaky) ).to be_truthy
310+
end
311+
end
312+
end
313+
314+
describe '#merge!' do
315+
let(:merged_configuration) { Result::StrictConfiguration.new }
316+
it 'sets the not default values from the argument accordingly' do
317+
strict_configuration.set_strict(false, :undefined)
318+
strict_configuration.set_strict(false, :pending)
319+
strict_configuration.set_strict(true, :flaky)
320+
merged_configuration.set_strict(true, :pending)
321+
merged_configuration.set_strict(false, :flaky)
322+
strict_configuration.merge!(merged_configuration)
323+
324+
expect( strict_configuration.strict?(:undefined) ).to be_falsey
325+
expect( strict_configuration.strict?(:pending) ).to be_truthy
326+
expect( strict_configuration.strict?(:flaky) ).to be_falsey
327+
end
328+
end
329+
end
330+
261331
describe Result::Summary do
262332
let(:summary) { Result::Summary.new }
263333
let(:failed) { Result::Failed.new(Result::Duration.new(10), exception) }
@@ -360,19 +430,22 @@ def describe_to(visitor, *args)
360430
it "pending result is ok if not strict" do
361431
pending.describe_to summary
362432
expect( summary.ok? ).to be true
363-
expect( summary.ok?(true) ).to be false
433+
be_strict = Result::StrictConfiguration.new([:pending])
434+
expect( summary.ok?(be_strict) ).to be false
364435
end
365436

366437
it "undefined result is ok if not strict" do
367438
undefined.describe_to summary
368439
expect( summary.ok? ).to be true
369-
expect( summary.ok?(true) ).to be false
440+
be_strict = Result::StrictConfiguration.new([:undefined])
441+
expect( summary.ok?(be_strict) ).to be false
370442
end
371443

372444
it "flaky result is ok if not strict" do
373445
summary.flaky
374446
expect( summary.ok? ).to be true
375-
expect( summary.ok?(true) ).to be false
447+
be_strict = Result::StrictConfiguration.new([:flaky])
448+
expect( summary.ok?(be_strict) ).to be false
376449
end
377450
end
378451
end

0 commit comments

Comments
 (0)