Skip to content

Commit

Permalink
Use max for duration and load_time in SummaryNotification
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasdundacek committed Mar 16, 2024
1 parent 222f289 commit 8316958
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
10 changes: 9 additions & 1 deletion lib/flatware/rspec/marshalable/summary_notification.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
25 changes: 17 additions & 8 deletions spec/flatware/rspec/marshalable/summary_notification_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8316958

Please sign in to comment.