Class: RSpec::Matchers::BuiltIn::BeWithin Private

Inherits:
Object
  • Object
show all
Includes:
Composable
Defined in:
lib/rspec/matchers/built_in/be_within.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 be_within. Not intended to be instantiated directly.

Instance Method Summary (collapse)

Methods included from Composable

#===, #and, #description_of, enumerable?, #or, surface_descriptions_in, #values_match?

Constructor Details

- (BeWithin) initialize(delta)

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 BeWithin

10
11
12
# File 'lib/rspec/matchers/built_in/be_within.rb', line 10
def initialize(delta)
  @delta = delta
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)
54
55
56
# File 'lib/rspec/matchers/built_in/be_within.rb', line 54
def description
  "be within #{@delta}#{@unit} of #{@expected}"
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)
42
43
44
# File 'lib/rspec/matchers/built_in/be_within.rb', line 42
def failure_message
  "expected #{@actual.inspect} to #{description}#{not_numeric_clause}"
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)
48
49
50
# File 'lib/rspec/matchers/built_in/be_within.rb', line 48
def failure_message_when_negated
  "expected #{@actual.inspect} not to #{description}"
end

- (Object) of(expected)

Sets the expected value.

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

- (Object) percent_of(expected)

Sets the expected value, and makes the matcher do a percent comparison.

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