diff --git a/lib/flatware/rspec/marshalable/summary_notification.rb b/lib/flatware/rspec/marshalable/summary_notification.rb index 0d16b88..924f347 100644 --- a/lib/flatware/rspec/marshalable/summary_notification.rb +++ b/lib/flatware/rspec/marshalable/summary_notification.rb @@ -6,7 +6,15 @@ module RSpec module Marshalable class SummaryNotification < ::RSpec::Core::Notifications::SummaryNotification def +(other) - self.class.new(*zip(other).map { |a, b| a + b }) + values = to_h.map do |key, value| + if %i[duration load_time].include?(key) + [value, other.public_send(key)].max + else + value + other.public_send(key) + end + end + + self.class.new(*values) end def failures? diff --git a/spec/flatware/rspec/marshalable/summary_notification_spec.rb b/spec/flatware/rspec/marshalable/summary_notification_spec.rb index f827a89..a8e4b06 100644 --- a/spec/flatware/rspec/marshalable/summary_notification_spec.rb +++ b/spec/flatware/rspec/marshalable/summary_notification_spec.rb @@ -2,19 +2,28 @@ require 'flatware/rspec/marshalable/summary_notification' describe Flatware::RSpec::Marshalable::SummaryNotification do - def args - [1, [], [], []] + (5..described_class.members.size).to_a - end + let(:args1) { [1, [], [], [], 0.2, 6] } + let(:args2) { [2, [], [], [], 0.3, 6] } + + it 'can be added together (duration and load_time handled with #max)' do + expected_result = { + duration: 2, + examples: [], + failed_examples: [], + pending_examples: [], + load_time: 0.3, + errors_outside_of_examples_count: 12 + } - it 'can be added together' do - summary1 = described_class.new(*args) - summary2 = described_class.new(*args) + summary1 = described_class.new(*args1) + summary2 = described_class.new(*args2) result = summary1 + summary2 - expect(result.to_a).to eq(args.map { |x| x * 2 }) + + expect(result.to_h).to eq(expected_result) end it 'plays nice with the rspec formatting stuff' do - notification = RSpec::Core::Notifications::SummaryNotification.new(*args) + notification = RSpec::Core::Notifications::SummaryNotification.new(*args1) summary = described_class.from_rspec(notification) expect(summary.fully_formatted).to match(/Finished/) end