类: RSpec::Matchers::BuiltIn::HaveAttributes 私有

继承
BaseMatcher
  • Object
显示全部
定义于
lib/rspec/matchers/built_in/have_attributes.rb

概述

此类是私有 API 的一部分。 应尽可能避免使用此类,因为它可能在将来被移除或更改。

提供 have_attributes 的实现。不建议直接实例化。

常量摘要

BaseMatcher 继承的常量

BaseMatcher::UNDEFINED

实例方法摘要 折叠

BaseMatcher 继承的方法

#expects_call_stack_jump?, #match_unless_raises, #supports_block_expectations?

Composable 包含的方法

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

构造函数详细信息

#initialize(expected) ⇒HaveAttributes

此方法是私有 API 的一部分。 应尽可能避免使用此方法,因为它可能在将来被移除或更改。

返回 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

实例方法详细信息

#descriptionString

此方法是私有 API 的一部分。 应尽可能避免使用此方法,因为它可能在将来被移除或更改。

返回值

  • (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

#diffable?Boolean

此方法是私有 API 的一部分。 应尽可能避免使用此方法,因为它可能在将来被移除或更改。

返回值

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

#does_not_match?(actual) ⇒Boolean

此方法是私有 API 的一部分。 应尽可能避免使用此方法,因为它可能在将来被移除或更改。

返回值

  • (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

#failure_messageString

此方法是私有 API 的一部分。 应尽可能避免使用此方法,因为它可能在将来被移除或更改。

返回值

  • (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

#failure_message_when_negatedString

此方法是私有 API 的一部分。 应尽可能避免使用此方法,因为它可能在将来被移除或更改。

返回值

  • (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

#matches?(actual) ⇒Boolean

此方法是私有 API 的一部分。 应尽可能避免使用此方法,因为它可能在将来被移除或更改。

返回值

  • (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