类: RSpec::Matchers::BuiltIn::BeWithin 私有

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

概述

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

be_within 提供实现。不打算直接实例化。

常量摘要

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(delta) ⇒BeWithin

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

返回 BeWithin 的新实例。

8
9
10
# File 'lib/rspec/matchers/built_in/be_within.rb', line 8
def initialize(delta)
  @delta = delta
end

实例方法详细信息

#descriptionString

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

返回

  • (String)
52
53
54
# File 'lib/rspec/matchers/built_in/be_within.rb', line 52
def description
  "be within #{@delta}#{@unit} of #{expected_formatted}"
end

#failure_messageString

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

返回

  • (String)
40
41
42
# File 'lib/rspec/matchers/built_in/be_within.rb', line 40
def failure_message
  "expected #{actual_formatted} to #{description}#{not_numeric_clause}"
end

#failure_message_when_negatedString

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

返回

  • (String)
46
47
48
# File 'lib/rspec/matchers/built_in/be_within.rb', line 46
def failure_message_when_negated
  "expected #{actual_formatted} not to #{description}"
end

#of(expected) ⇒Object

设置预期值。

14
15
16
17
18
19
# File 'lib/rspec/matchers/built_in/be_within.rb', line 14
def of(expected)
  @expected  = expected
  @tolerance = @delta
  @unit      = ''
  self
end

#percent_of(expected) ⇒Object

设置预期值,并使匹配器执行百分比比较。

24
25
26
27
28
29
# File 'lib/rspec/matchers/built_in/be_within.rb', line 24
def percent_of(expected)
  @expected  = expected
  @tolerance = @expected.abs * @delta / 100.0
  @unit      = '%'
  self
end