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

Inherits:
BaseMatcher
  • Object
show all
Defined in:
lib/rspec/matchers/built_in/have_attributes.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Provides the implementation for have_attributes. Not intended to be instantiated directly.

Constant Summary

Constant Summary

Constants inherited from BaseMatcher

BaseMatcher::UNDEFINED

Instance Method Summary (collapse)

Methods inherited from BaseMatcher

#expects_call_stack_jump?, #match_unless_raises, #supports_block_expectations?

Methods included from Composable

#===, #and, #description_of, #or, should_enumerate?, surface_descriptions_in, unreadable_io?, #values_match?

Constructor Details

- (HaveAttributes) initialize(expected)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of HaveAttributes

11
12
13
14
15
16
# File 'lib/rspec/matchers/built_in/have_attributes.rb', line 11
def initialize(expected)
  @expected = expected
  @values = {}
  @respond_to_failed = false
  @negated = false
end

Instance Method Details

- (String) description

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (String)
43
44
45
46
# File 'lib/rspec/matchers/built_in/have_attributes.rb', line 43
def description
  described_items = surface_descriptions_in(expected)
  improve_hash_formatting "have attributes #{RSpec::Support::ObjectFormatter.format(described_items)}"
end

- (Boolean) diffable?

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)
50
51
52
# File 'lib/rspec/matchers/built_in/have_attributes.rb', line 50
def diffable?
  !@respond_to_failed && !@negated
end

- (Boolean) does_not_match?(actual)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)
34
35
36
37
38
39
# File 'lib/rspec/matchers/built_in/have_attributes.rb', line 34
def does_not_match?(actual)
  @actual = actual
  @negated = true
  return false unless respond_to_attributes?
  perform_match(:none?)
end

- (String) failure_message

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (String)
56
57
58
59
60
# File 'lib/rspec/matchers/built_in/have_attributes.rb', line 56
def failure_message
  respond_to_failure_message_or do
    "expected #{actual_formatted} to #{description} but had attributes #{ formatted_values }"
  end
end

- (String) failure_message_when_negated

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (String)
64
65
66
# File 'lib/rspec/matchers/built_in/have_attributes.rb', line 64
def failure_message_when_negated
  respond_to_failure_message_or { "expected #{actual_formatted} not to #{description}" }
end

- (Boolean) matches?(actual)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)
25
26
27
28
29
30
# File 'lib/rspec/matchers/built_in/have_attributes.rb', line 25
def matches?(actual)
  @actual = actual
  @negated = false
  return false unless respond_to_attributes?
  perform_match(:all?)
end