class RSpec::Matchers::BuiltIn::HaveAttributes

Public Class Methods

new(*) click to toggle source
Calls superclass method
# File lib/super_diff/rspec/monkey_patches.rb, line 488
def initialize(*)
  super
  @actual = nil
end

Public Instance Methods

actual_for_diff() click to toggle source

Override so that the differ knows that this is a partial object

# File lib/super_diff/rspec/monkey_patches.rb, line 514
def actual_for_diff
  @actual
end
actual_for_matcher_text() click to toggle source

Override to use the whole object, not just part of it

# File lib/super_diff/rspec/monkey_patches.rb, line 504
def actual_for_matcher_text
  description_of(@actual)
end
actual_has_attribute?(attribute_key, attribute_value) click to toggle source
# File lib/super_diff/rspec/monkey_patches.rb, line 551
def actual_has_attribute?(attribute_key, attribute_value)
  values_match?(attribute_value, @values.fetch(attribute_key))
end
cache_all_values() click to toggle source

Override this method to skip non-existent attributes, and to use public_send

# File lib/super_diff/rspec/monkey_patches.rb, line 540
def cache_all_values
  @values = @expected.keys.inject({}) do |hash, attribute_key|
    if @actual.respond_to?(attribute_key)
      actual_value = @actual.public_send(attribute_key)
      hash.merge(attribute_key => actual_value)
    else
      hash
    end
  end
end
expected_for_diff() click to toggle source

Override so that the differ knows that this is a partial object

# File lib/super_diff/rspec/monkey_patches.rb, line 519
def expected_for_diff
  if respond_to_failed
    matchers.an_object_having_attributes(
      @expected.select { |k, v| !@actual.respond_to?(k) }
    )
  else
    matchers.an_object_having_attributes(@expected)
  end
end
expected_for_matcher_text() click to toggle source

Override to use (…) as delimiters rather than {…}

Calls superclass method
# File lib/super_diff/rspec/monkey_patches.rb, line 509
def expected_for_matcher_text
  super.sub(/^\{ /, '(').gsub(/ \}$/, ')')
end
failure_message() click to toggle source

Use the message in the base matcher

Calls superclass method
# File lib/super_diff/rspec/monkey_patches.rb, line 494
def failure_message
  respond_to_failure_message_or { super }
end
failure_message_when_negated() click to toggle source

Use the message in the base matcher

Calls superclass method
# File lib/super_diff/rspec/monkey_patches.rb, line 499
def failure_message_when_negated
  respond_to_failure_message_or { super }
end
respond_to_attributes?() click to toggle source

Override to force @values to get populated so that we can show a proper diff

# File lib/super_diff/rspec/monkey_patches.rb, line 531
def respond_to_attributes?
  cache_all_values
  matches = respond_to_matcher.matches?(@actual)
  @respond_to_failed = !matches
  matches
end
respond_to_failure_message_or() { || ... } click to toggle source

Override to not improve_hash_formatting

# File lib/super_diff/rspec/monkey_patches.rb, line 556
def respond_to_failure_message_or
  if respond_to_failed
    respond_to_matcher.failure_message
  else
    yield
  end
end