class RSpec::Matchers::BuiltIn::Eq
@api private Provides the implementation for `eq`. Not intended to be instantiated directly.
Constants
- DATE_TIME_FORMAT
- TIME_FORMAT
Public Instance Methods
description()
click to toggle source
@api private @return [String]
# File lib/rspec/matchers/built_in/eq.rb, line 22 def description "#{name_to_sentence} #{@expected.inspect}" end
diffable?()
click to toggle source
@api private @return [Boolean]
# File lib/rspec/matchers/built_in/eq.rb, line 28 def diffable? true end
failure_message()
click to toggle source
@api private @return [String]
# File lib/rspec/matchers/built_in/eq.rb, line 10 def failure_message "\nexpected: #{format_object(expected)}\n got: #{format_object(actual)}\n\n(compared using ==)\n" end
failure_message_when_negated()
click to toggle source
@api private @return [String]
# File lib/rspec/matchers/built_in/eq.rb, line 16 def failure_message_when_negated "\nexpected: value != #{format_object(expected)}\n got: #{format_object(actual)}\n\n(compared using ==)\n" end
Private Instance Methods
format_date_time(date_time)
click to toggle source
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 65 def format_date_time(date_time) if defined?(ActiveSupport) date_time.strftime(DATE_TIME_FORMAT) else date_time.inspect end end
format_object(object)
click to toggle source
# File lib/rspec/matchers/built_in/eq.rb, line 38 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
format_time(time)
click to toggle source
# File lib/rspec/matchers/built_in/eq.rb, line 53 def format_time(time) time.strftime("#{TIME_FORMAT}.#{"%09d" % time.nsec} %z") end
match(expected, actual)
click to toggle source
# File lib/rspec/matchers/built_in/eq.rb, line 34 def match(expected, actual) actual == expected end