Class: RSpec::Matchers::BuiltIn::HaveAttributes

Inherits:
Object
  • Object
show all
Includes:
SuperDiff::RSpec::AugmentedMatcher
Defined in:
lib/super_diff/rspec/monkey_patches.rb

Instance Method Summary collapse

Methods included from SuperDiff::RSpec::AugmentedMatcher

#description, #diffable?, #failure_message, #failure_message_when_negated

Instance Method Details

#actual_has_attribute?(attribute_key, attribute_value) ⇒ Boolean

Returns:

  • (Boolean)


529
530
531
# File 'lib/super_diff/rspec/monkey_patches.rb', line 529

def actual_has_attribute?(attribute_key, attribute_value)
  values_match?(attribute_value, @values.fetch(attribute_key))
end

#cache_all_valuesObject

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



518
519
520
521
522
523
524
525
526
527
# File 'lib/super_diff/rspec/monkey_patches.rb', line 518

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

#respond_to_attributes?Boolean

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

Returns:

  • (Boolean)


509
510
511
512
513
514
# File 'lib/super_diff/rspec/monkey_patches.rb', line 509

def respond_to_attributes?
  cache_all_values
  matches = respond_to_matcher.matches?(@actual)
  @respond_to_failed = !matches
  matches
end

#respond_to_failure_message_orObject

Override to not improve_hash_formatting



534
535
536
537
538
539
540
# File 'lib/super_diff/rspec/monkey_patches.rb', line 534

def respond_to_failure_message_or
  if respond_to_failed
    respond_to_matcher.failure_message
  else
    yield
  end
end