类: RSpec::Matchers::BuiltIn::BeBetween 私有

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

概述

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

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

常量摘要

BaseMatcher 继承的常量

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

实例方法摘要 折叠

BaseMatcher 继承的方法

#diffable?, #expects_call_stack_jump?, #match_unless_raises, #supports_block_expectations?

RSpec::Matchers::BuiltIn::BaseMatcher::DefaultFailureMessages 包含的方法

#failure_message_when_negated

Composable 包含的方法

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

构造函数详细信息

#initialize(min, max) ⇒BeBetween

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

返回 BeBetween 的一个新实例。

8
9
10
11
# File 'lib/rspec/matchers/built_in/be_between.rb', line 8
def initialize(min, max)
  @min, @max = min, max
  inclusive
end

实例方法详细信息

#descriptionString

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

返回

  • (String)
57
58
59
# File 'lib/rspec/matchers/built_in/be_between.rb', line 57
def description
  "be between #{description_of @min} and #{description_of @max} (#{@mode})"
end

#exclusiveObject

使 between 比较变为排他性。

示例

expect(3).to be_between(2, 4).exclusive
33
34
35
36
37
38
# File 'lib/rspec/matchers/built_in/be_between.rb', line 33
def exclusive
  @less_than_operator = :<
  @greater_than_operator = :>
  @mode = :exclusive
  self
end

#failure_messageString

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

返回

  • (String)
51
52
53
# File 'lib/rspec/matchers/built_in/be_between.rb', line 51
def failure_message
  "#{super}#{not_comparable_clause}"
end

#inclusiveObject

注意

匹配器默认情况下是包含性的;这只是提供了一种更明确的方式。

使 between 比较变为包含性。

示例

expect(3).to be_between(2, 3).inclusive
21
22
23
24
25
26
# File 'lib/rspec/matchers/built_in/be_between.rb', line 21
def inclusive
  @less_than_operator = :<=
  @greater_than_operator = :>=
  @mode = :inclusive
  self
end

#matches?(actual) ⇒Boolean

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

返回

  • (Boolean)
42
43
44
45
46
47
# File 'lib/rspec/matchers/built_in/be_between.rb', line 42
def matches?(actual)
  @actual = actual
  comparable? && compare
rescue ArgumentError
  false
end