Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/manual rubocop fixes part2 #261

Merged
merged 10 commits into from
Sep 13, 2023
8 changes: 6 additions & 2 deletions lib/cucumber/core/event_bus.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def initialize(registry = Events.registry)
@event_queue = []
end

# Register for an event. The handler proc will be called back with each of the attributes
# Register for an event. The handler proc will be called back with each of the attributes
# of the event.
def on(event_id, handler_object = nil, &handler_proc)
handler = handler_proc || handler_object
Expand All @@ -29,7 +29,7 @@ def on(event_id, handler_object = nil, &handler_proc)
broadcast_queued_events_to handler, event_class
end

# Broadcast an event
# Broadcast an event
def broadcast(event)
raise ArgumentError, "Event type #{event.class} is not registered. Try one of these:\n#{event_types.values.join("\n")}" unless is_registered_type?(event.class)
handlers_for(event.class).each { |handler| handler.call(event) }
Expand All @@ -41,6 +41,10 @@ def method_missing(event_id, *args)
broadcast event_class.new(*args)
end

def respond_to_missing?(event_id, *args)
event_types.key?(event_id) || super
end

private

def broadcast_queued_events_to(handler, event_type)
Expand Down
4 changes: 2 additions & 2 deletions lib/cucumber/core/report/summary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ def initialize(event_bus)
subscribe_to(event_bus)
end

def ok?(be_strict = Test::Result::StrictConfiguration.new)
test_cases.ok?(be_strict)
def ok?(strict: Test::Result::StrictConfiguration.new)
test_cases.ok?(strict: strict)
end

private
Expand Down
41 changes: 22 additions & 19 deletions lib/cucumber/core/test/result.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ module Result
TYPES = [:failed, :flaky, :skipped, :undefined, :pending, :passed, :unknown].freeze
STRICT_AFFECTED_TYPES = [:flaky, :undefined, :pending].freeze

def self.ok?(type, be_strict = StrictConfiguration.new)
def self.ok?(type, strict: StrictConfiguration.new)
class_name = type.to_s.slice(0, 1).capitalize + type.to_s.slice(1..-1)
const_get(class_name).ok?(be_strict.strict?(type))
const_get(class_name).ok?(strict: strict.strict?(type))
end

# Defines to_sym on a result class for the given result type
Expand Down Expand Up @@ -58,7 +58,7 @@ class Passed
include Result.query_methods :passed
attr_accessor :duration

def self.ok?(_be_strict = false)
def self.ok?(*)
true
end

Expand All @@ -84,7 +84,7 @@ def to_message
)
end

def ok?(_be_strict = nil)
def ok?
self.class.ok?
end

Expand All @@ -102,7 +102,7 @@ class Failed

attr_reader :duration, :exception

def self.ok?(_be_strict = false)
def self.ok?(*)
false
end

Expand Down Expand Up @@ -138,7 +138,7 @@ def to_message
)
end

def ok?(_be_strict = nil)
def ok?(*)
self.class.ok?
end

Expand All @@ -160,8 +160,8 @@ def with_filtered_backtrace(filter)
# reporting result type for test cases that fails and the passes on
# retry, therefore only the class method self.ok? is needed.
class Flaky
def self.ok?(be_strict = false)
!be_strict
def self.ok?(strict: false)
!strict
end
end

Expand Down Expand Up @@ -196,16 +196,16 @@ def with_filtered_backtrace(filter)
filter.new(dup).exception
end

def ok?(be_strict = StrictConfiguration.new)
self.class.ok?(be_strict.strict?(to_sym))
def ok?(strict: StrictConfiguration.new)
self.class.ok?(strict: strict.strict?(to_sym))
end
end

class Undefined < Raisable
include Result.query_methods :undefined

def self.ok?(be_strict = false)
!be_strict
def self.ok?(strict: false)
!strict
end

def describe_to(visitor, *args)
Expand All @@ -229,7 +229,7 @@ def to_message
class Skipped < Raisable
include Result.query_methods :skipped

def self.ok?(_be_strict = false)
def self.ok?(*)
true
end

Expand All @@ -254,8 +254,8 @@ def to_message
class Pending < Raisable
include Result.query_methods :pending

def self.ok?(be_strict = false)
!be_strict
def self.ok?(strict: false)
!strict
end

def describe_to(visitor, *args)
Expand Down Expand Up @@ -325,8 +325,7 @@ def set?(type)
end

#
# An object that responds to the description protocol from the results
# and collects summary information.
# An object that responds to the description protocol from the results and collects summary information.
#
# e.g.
# summary = Result::Summary.new
Expand All @@ -351,10 +350,14 @@ def method_missing(name, *_args)
end
end

def ok?(be_strict = StrictConfiguration.new)
def respond_to_missing?(*)
true
end

def ok?(strict: StrictConfiguration.new)
TYPES.each do |type|
if get_total(type) > 0
return false unless Result.ok?(type, be_strict)
return false unless Result.ok?(type, strict: strict)
end
end
true
Expand Down
8 changes: 4 additions & 4 deletions spec/cucumber/core/report/summary_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,16 +166,16 @@ module Report
event_bus.send(:test_case_finished, test_case, pending_result)

expect(@summary.ok?).to eq true
be_strict = ::Cucumber::Core::Test::Result::StrictConfiguration.new([:pending])
expect(@summary.ok?(be_strict)).to eq false
strict = ::Cucumber::Core::Test::Result::StrictConfiguration.new([:pending])
expect(@summary.ok?(strict: strict)).to eq false
end

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

expect(@summary.ok?).to eq true
be_strict = ::Cucumber::Core::Test::Result::StrictConfiguration.new([:undefined])
expect(@summary.ok?(be_strict)).to eq false
strict = ::Cucumber::Core::Test::Result::StrictConfiguration.new([:undefined])
expect(@summary.ok?(strict: strict)).to eq false
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/cucumber/core/test/filters/locations_filter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ module Core
gherkin('features/test.feature') do
feature do
scenario 'x' do
step 'a step'
step 'step for scenario x'
end

scenario 'y' do
step 'a step'
step 'step for scenario y'
end
end
end
Expand Down
Loading