diff --git a/lib/cucumber/core/event_bus.rb b/lib/cucumber/core/event_bus.rb index 6390410a..449e196a 100644 --- a/lib/cucumber/core/event_bus.rb +++ b/lib/cucumber/core/event_bus.rb @@ -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 @@ -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) } @@ -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) diff --git a/lib/cucumber/core/report/summary.rb b/lib/cucumber/core/report/summary.rb index d312127f..a4929de0 100644 --- a/lib/cucumber/core/report/summary.rb +++ b/lib/cucumber/core/report/summary.rb @@ -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 diff --git a/lib/cucumber/core/test/result.rb b/lib/cucumber/core/test/result.rb index 7beb1cd3..50782ec9 100644 --- a/lib/cucumber/core/test/result.rb +++ b/lib/cucumber/core/test/result.rb @@ -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 @@ -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 @@ -84,7 +84,7 @@ def to_message ) end - def ok?(_be_strict = nil) + def ok? self.class.ok? end @@ -102,7 +102,7 @@ class Failed attr_reader :duration, :exception - def self.ok?(_be_strict = false) + def self.ok?(*) false end @@ -138,7 +138,7 @@ def to_message ) end - def ok?(_be_strict = nil) + def ok?(*) self.class.ok? end @@ -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 @@ -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) @@ -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 @@ -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) @@ -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 @@ -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 diff --git a/spec/cucumber/core/report/summary_spec.rb b/spec/cucumber/core/report/summary_spec.rb index c19024db..c749cf7b 100644 --- a/spec/cucumber/core/report/summary_spec.rb +++ b/spec/cucumber/core/report/summary_spec.rb @@ -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 diff --git a/spec/cucumber/core/test/filters/locations_filter_spec.rb b/spec/cucumber/core/test/filters/locations_filter_spec.rb index 471044ea..96b0ddbf 100644 --- a/spec/cucumber/core/test/filters/locations_filter_spec.rb +++ b/spec/cucumber/core/test/filters/locations_filter_spec.rb @@ -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 diff --git a/spec/cucumber/core/test/result_spec.rb b/spec/cucumber/core/test/result_spec.rb index de622430..a51d9b73 100644 --- a/spec/cucumber/core/test/result_spec.rb +++ b/spec/cucumber/core/test/result_spec.rb @@ -8,8 +8,8 @@ module Cucumber module Core module Test describe Result do - let(:visitor) { double('visitor') } - let(:args) { double('args') } + let(:visitor) { double } + let(:args) { double } describe Result::Passed do subject(:result) { described_class.new(duration) } @@ -31,32 +31,25 @@ module Test end it 'has a duration' do - expect(result.duration).to eq duration - end - - it 'requires the constructor argument' do - expect { described_class.new }.to raise_error(ArgumentError) + expect(result.duration).to eq(duration) end it 'does nothing when appending the backtrace' do - expect(result.with_appended_backtrace(double)).to equal result + expect(result.with_appended_backtrace(double)).to eq(result) end it 'does nothing when filtering the backtrace' do - expect(result.with_filtered_backtrace(double)).to equal result + expect(result.with_filtered_backtrace(double)).to eq(result) end - specify { expect(result.to_sym).to eq :passed } - - specify { expect(result).to be_passed } - specify { expect(result).not_to be_failed } - specify { expect(result).not_to be_undefined } - specify { expect(result).not_to be_unknown } - specify { expect(result).not_to be_skipped } - specify { expect(result).not_to be_flaky } - - specify { expect(result).to be_ok } - specify { expect(result).to be_ok } + it { expect(result.to_sym).to eq(:passed) } + it { expect(result).to be_passed } + it { expect(result).not_to be_failed } + it { expect(result).not_to be_undefined } + it { expect(result).not_to be_unknown } + it { expect(result).not_to be_skipped } + it { expect(result).not_to be_flaky } + it { expect(result).to be_ok } end describe Result::Failed do @@ -95,7 +88,7 @@ module Test it 'appends the backtrace line of the step' do result.exception.set_backtrace('exception backtrace') step = double - expect(step).to receive(:backtrace_line).and_return('step_line') + allow(step).to receive(:backtrace_line).and_return('step_line') expect(result.with_appended_backtrace(step).exception.backtrace).to eq(['exception backtrace', 'step_line']) end @@ -104,45 +97,41 @@ module Test filter_class = double filter = double filtered_exception = double - expect(filter_class).to receive(:new).with(result.exception).and_return(filter) - expect(filter).to receive(:exception).and_return(filtered_exception) + allow(filter_class).to receive(:new).with(result.exception).and_return(filter) + allow(filter).to receive(:exception).and_return(filtered_exception) expect(result.with_filtered_backtrace(filter_class).exception).to equal filtered_exception end - specify { expect(result.to_sym).to eq :failed } - - specify { expect(result).not_to be_passed } - specify { expect(result).to be_failed } - specify { expect(result).not_to be_undefined } - specify { expect(result).not_to be_unknown } - specify { expect(result).not_to be_skipped } - specify { expect(result).not_to be_flaky } - - specify { expect(result).to_not be_ok } - specify { expect(result).not_to be_ok } + it { expect(result.to_sym).to eq(:failed) } + it { expect(result).not_to be_passed } + it { expect(result).to be_failed } + it { expect(result).not_to be_undefined } + it { expect(result).not_to be_unknown } + it { expect(result).not_to be_skipped } + it { expect(result).not_to be_flaky } + it { expect(result).not_to be_ok } end describe Result::Unknown do subject(:result) { described_class.new } it "doesn't describe itself to a visitor" do - visitor = double('never receives anything') + visitor = double result.describe_to(visitor, args) end it 'defines a with_filtered_backtrace method' do - expect(result.with_filtered_backtrace(double('filter'))).to eql result + expect(result.with_filtered_backtrace(double)).to eq(result) end - specify { expect(result.to_sym).to eq :unknown } - - specify { expect(result).not_to be_passed } - specify { expect(result).not_to be_failed } - specify { expect(result).not_to be_undefined } - specify { expect(result).to be_unknown } - specify { expect(result).not_to be_skipped } - specify { expect(result).not_to be_flaky } + it { expect(result.to_sym).to eq(:unknown) } + it { expect(result).not_to be_passed } + it { expect(result).not_to be_failed } + it { expect(result).not_to be_undefined } + it { expect(result).to be_unknown } + it { expect(result).not_to be_skipped } + it { expect(result).not_to be_flaky } it 'converts to a Cucumber::Message::TestResult' do message = result.to_message @@ -166,7 +155,7 @@ module Test it 'set the backtrace to the backtrace line of the step' do step = double - expect(step).to receive(:backtrace_line).and_return('step_line') + allow(step).to receive(:backtrace_line).and_return('step_line') expect(result.with_appended_backtrace(step).backtrace).to eq(['step_line']) end @@ -181,7 +170,7 @@ module Test it 'appends the backtrace line of the step' do step = double - expect(step).to receive(:backtrace_line).and_return('step_line') + allow(step).to receive(:backtrace_line).and_return('step_line') expect(result.with_appended_backtrace(step).backtrace).to eq(['backtrace', 'step_line']) end @@ -190,8 +179,8 @@ module Test filter_class = double filter = double filtered_result = double - expect(filter_class).to receive(:new).with(result.exception).and_return(filter) - expect(filter).to receive(:exception).and_return(filtered_result) + allow(filter_class).to receive(:new).with(result.exception).and_return(filter) + allow(filter).to receive(:exception).and_return(filtered_result) expect(result.with_filtered_backtrace(filter_class)).to equal filtered_result end @@ -212,20 +201,17 @@ module Test expect(message.status).to eq(Cucumber::Messages::TestStepResultStatus::UNDEFINED) end - specify { expect(result.to_sym).to eq :undefined } - - specify { expect(result).not_to be_passed } - specify { expect(result).not_to be_failed } - specify { expect(result).to be_undefined } - specify { expect(result).not_to be_unknown } - specify { expect(result).not_to be_skipped } - specify { expect(result).not_to be_flaky } + it { expect(result.to_sym).to eq(:undefined) } + it { expect(result).not_to be_passed } + it { expect(result).not_to be_failed } + it { expect(result).to be_undefined } + it { expect(result).not_to be_unknown } + it { expect(result).not_to be_skipped } + it { expect(result).not_to be_flaky } + it { expect(result).to be_ok } - specify { expect(result).to be_ok } - specify { expect(result).to be_ok } - - be_strict = Result::StrictConfiguration.new([:undefined]) - specify { expect(result).not_to be_ok(be_strict) } + strict = Result::StrictConfiguration.new([:undefined]) + it { expect(result).not_to be_ok(strict: strict) } end describe Result::Skipped do @@ -242,17 +228,14 @@ module Test expect(message.status).to eq(Cucumber::Messages::TestStepResultStatus::SKIPPED) end - specify { expect(result.to_sym).to eq :skipped } - - specify { expect(result).not_to be_passed } - specify { expect(result).not_to be_failed } - specify { expect(result).not_to be_undefined } - specify { expect(result).not_to be_unknown } - specify { expect(result).to be_skipped } - specify { expect(result).not_to be_flaky } - - specify { expect(result).to be_ok } - specify { expect(result).to be_ok } + it { expect(result.to_sym).to eq(:skipped) } + it { expect(result).not_to be_passed } + it { expect(result).not_to be_failed } + it { expect(result).not_to be_undefined } + it { expect(result).not_to be_unknown } + it { expect(result).to be_skipped } + it { expect(result).not_to be_flaky } + it { expect(result).to be_ok } end describe Result::Pending do @@ -269,26 +252,22 @@ module Test expect(message.status).to eq(Cucumber::Messages::TestStepResultStatus::PENDING) end - specify { expect(result.to_sym).to eq :pending } - - specify { expect(result).not_to be_passed } - specify { expect(result).not_to be_failed } - specify { expect(result).not_to be_undefined } - specify { expect(result).not_to be_unknown } - specify { expect(result).not_to be_skipped } - specify { expect(result).not_to be_flaky } - specify { expect(result).to be_pending } - - specify { expect(result).to be_ok } - specify { expect(result).to be_ok } + it { expect(result.to_sym).to eq(:pending) } + it { expect(result).not_to be_passed } + it { expect(result).not_to be_failed } + it { expect(result).not_to be_undefined } + it { expect(result).not_to be_unknown } + it { expect(result).not_to be_skipped } + it { expect(result).not_to be_flaky } + it { expect(result).to be_ok } - be_strict = Result::StrictConfiguration.new([:pending]) - specify { expect(result).not_to be_ok(be_strict) } + strict = Result::StrictConfiguration.new([:pending]) + it { expect(result).not_to be_ok(strict: strict) } end describe Result::Flaky do - specify { expect(described_class).to be_ok(false) } - specify { expect(described_class).not_to be_ok(true) } + it { expect(described_class).to be_ok(strict: false) } + it { expect(described_class).not_to be_ok(strict: true) } end describe Result::StrictConfiguration do @@ -467,22 +446,22 @@ def describe_to(visitor, *args) it 'pending result is ok if not strict' do pending.describe_to summary expect(summary.ok?).to be true - be_strict = Result::StrictConfiguration.new([:pending]) - expect(summary.ok?(be_strict)).to be false + strict = Result::StrictConfiguration.new([:pending]) + expect(summary.ok?(strict: strict)).to be false end it 'undefined result is ok if not strict' do undefined.describe_to summary expect(summary.ok?).to be true - be_strict = Result::StrictConfiguration.new([:undefined]) - expect(summary.ok?(be_strict)).to be false + strict = Result::StrictConfiguration.new([:undefined]) + expect(summary.ok?(strict: strict)).to be false end it 'flaky result is ok if not strict' do summary.flaky expect(summary.ok?).to be true - be_strict = Result::StrictConfiguration.new([:flaky]) - expect(summary.ok?(be_strict)).to be false + strict = Result::StrictConfiguration.new([:flaky]) + expect(summary.ok?(strict: strict)).to be false end end end diff --git a/spec/cucumber/core/test/runner_spec.rb b/spec/cucumber/core/test/runner_spec.rb index 70790f78..67e08137 100644 --- a/spec/cucumber/core/test/runner_spec.rb +++ b/spec/cucumber/core/test/runner_spec.rb @@ -125,7 +125,7 @@ module Test expect(event_bus).to receive(:test_case_finished) do |_test_case, result| expect(result.backtrace).to eq(['step line']) end - expect(undefined).to receive(:backtrace_line).and_return('step line') + allow(undefined).to receive(:backtrace_line).and_return('step line') test_case.describe_to runner end @@ -145,7 +145,7 @@ module Test expect(event_bus).to receive(:test_case_finished) do |_test_case, result| expect(result.backtrace.last).to eq('step line') end - expect(pending).to receive(:backtrace_line).and_return('step line') + allow(pending).to receive(:backtrace_line).and_return('step line') test_case.describe_to runner end @@ -165,7 +165,7 @@ module Test expect(event_bus).to receive(:test_case_finished) do |_test_case, result| expect(result.backtrace.last).to eq('step line') end - expect(skipping).to receive(:backtrace_line).and_return('step line') + allow(skipping).to receive(:backtrace_line).and_return('step line') test_case.describe_to runner end @@ -185,7 +185,7 @@ module Test expect(event_bus).to receive(:test_case_finished) do |_test_case, result| expect(result.exception.backtrace.last).to eq('step line') end - expect(failing).to receive(:backtrace_line).and_return('step line') + allow(failing).to receive(:backtrace_line).and_return('step line') test_case.describe_to runner end @@ -218,7 +218,8 @@ module Test it 'skips, rather than executing the second step' do expect(passing).not_to receive(:execute) - expect(passing).to receive(:skip).and_return(Result::Skipped.new) + + allow(passing).to receive(:skip).and_return(Result::Skipped.new) test_case.describe_to runner end end diff --git a/spec/cucumber/core/test/step_spec.rb b/spec/cucumber/core/test/step_spec.rb index 6a5997b5..c8e8321e 100644 --- a/spec/cucumber/core/test/step_spec.rb +++ b/spec/cucumber/core/test/step_spec.rb @@ -76,9 +76,9 @@ module Test it 'exposes the location of the action as attribute' do location = double - action = double(location: location) + action = instance_double(Test::Action, location: location) test_step = described_class.new(id, text, location, action) - expect(test_step.action_location).to eq location + expect(test_step.action_location).to eq(location) end it 'returns the text when converted to a string' do