@api private Provides the implementation for `eq`. Not intended to be instantiated directly.
@api private @return [String]
# File lib/rspec/matchers/built_in/eq.rb, line 23 def description "#{name_to_sentence} #{@expected.inspect}" end
@api private @return [Boolean]
# File lib/rspec/matchers/built_in/eq.rb, line 29 def diffable? true end
@api private @return [String]
# File lib/rspec/matchers/built_in/eq.rb, line 11 def failure_message "\nexpected: #{format_object(expected)}\n got: #{format_object(actual)}\n\n(compared using ==)\n" end
@api private @return [String]
# File lib/rspec/matchers/built_in/eq.rb, line 17 def failure_message_when_negated "\nexpected: value != #{format_object(expected)}\n got: #{format_object(actual)}\n\n(compared using ==)\n" end
ActiveSupport sometimes overrides inspect. If `ActiveSupport` is defined use a custom format string that includes more time precision.
# File lib/rspec/matchers/built_in/eq.rb, line 66 def format_date_time(date_time) if defined?(ActiveSupport) date_time.strftime(DATE_TIME_FORMAT) else date_time.inspect end end
# File lib/rspec/matchers/built_in/eq.rb, line 39 def format_object(object) if Time === object format_time(object) elsif defined?(DateTime) && DateTime === object format_date_time(object) elsif defined?(BigDecimal) && BigDecimal === object "#{object.to_s 'F'} (#{object.inspect})" else object.inspect end end
# File lib/rspec/matchers/built_in/eq.rb, line 54 def format_time(time) time.strftime("#{TIME_FORMAT}.#{"%09d" % time.nsec} %z") end
# File lib/rspec/matchers/built_in/eq.rb, line 35 def match(expected, actual) actual == expected end