类: RSpec::Matchers::BuiltIn::BeComparedTo 私有

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

概述

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

提供 be <operator> value 的实现。不建议直接实例化。

常量摘要

BaseMatcher 继承的常量

RSpec::Matchers::BuiltIn::BaseMatcher::UNDEFINED

实例方法摘要 折叠

BaseMatcher 继承的方法

#diffable?, #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(operand, operator) ⇒BeComparedTo

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

返回 BeComparedTo 的新实例。

139
140
141
142
143
# File 'lib/rspec/matchers/built_in/be.rb', line 139
def initialize(operand, operator)
  @expected = operand
  @operator = operator
  @args = []
end

实例方法详情

#descriptionString

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

返回

  • (String)
178
179
180
# File 'lib/rspec/matchers/built_in/be.rb', line 178
def description
  "be #{@operator} #{expected_to_sentence}#{args_to_sentence}"
end

#does_not_match?(actual) ⇒Boolean

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

返回

  • (Boolean)
151
152
153
154
155
# File 'lib/rspec/matchers/built_in/be.rb', line 151
def does_not_match?(actual)
  !perform_match(actual)
rescue ArgumentError, NoMethodError
  false
end

#failure_messageString

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

返回

  • (String)
159
160
161
162
# File 'lib/rspec/matchers/built_in/be.rb', line 159
def failure_message
  "expected: #{@operator} #{expected_formatted}\n" \
  "     got: #{@operator.to_s.gsub(/./, ' ')} #{actual_formatted}"
end

#failure_message_when_negatedString

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

返回

  • (String)
166
167
168
169
170
171
172
173
174
# File 'lib/rspec/matchers/built_in/be.rb', line 166
def failure_message_when_negated
  message = "`expect(#{actual_formatted}).not_to " \
            "be #{@operator} #{expected_formatted}`"
  if [:<, :>, :<=, :>=].include?(@operator)
    message + " not only FAILED, it is a bit confusing."
  else
    message
  end
end

#matches?(actual) ⇒Boolean

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

返回

  • (Boolean)
145
146
147
148
149
# File 'lib/rspec/matchers/built_in/be.rb', line 145
def matches?(actual)
  perform_match(actual)
rescue ArgumentError, NoMethodError
  false
end