Skip to content

Commit

Permalink
Monkey patch Eq matcher to make failure messages involving Pace and R…
Browse files Browse the repository at this point in the history
…unbyTime easier to read
  • Loading branch information
tygerbytes committed Nov 28, 2016
1 parent ef416cd commit be08ee9
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions spec/support/matchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,22 @@ def format_time_range(expected_time_s, seconds_variation_s)
"#{slow_time}-#{fast_time}"
end
end

module RSpec
module Matchers
module BuiltIn
class Eq < BaseMatcher
private
# Monkey patch the "Eq" matcher to make failure messages involving Pace and RunbyTime easier to read
# Let me know if there is an idiomatic way to do this
def actual_formatted
formatted_object = RSpec::Support::ObjectFormatter.format(@actual)
if [Runby::RunbyTime, Runby::Pace].include? @actual.class
return "#{@actual.to_s}\n #{formatted_object}"
end
formatted_object
end
end
end
end
end

0 comments on commit be08ee9

Please sign in to comment.