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

### Home Classes Methods

### In Files

- lib/rspec/matchers/built_in/be_within.rb

### Parent

Object

### Methods

- ::new
- #==
- #description
- #failure_message_for_should
- #failure_message_for_should_not
- #matches?
- #of
- #percent_of

### Class/Module Index

Quicksearch

- RSpec
- RSpec::Expectations
- RSpec::Expectations::DeprecatedConstants
- RSpec::Expectations::Deprecation
- RSpec::Expectations::Differ
- RSpec::Expectations::ExpectationHandler
- RSpec::Expectations::ExpectationNotMetError
- RSpec::Expectations::ExpectationTarget
- RSpec::Expectations::NegativeExpectationHandler
- RSpec::Expectations::PositiveExpectationHandler
- RSpec::Expectations::Syntax
- RSpec::Expectations::Syntax::ExpectExpressionGenerator
- RSpec::Expectations::Syntax::ShouldExpressionGenerator
- RSpec::Expectations::Version
- RSpec::Matchers
- RSpec::Matchers::BuiltIn
- RSpec::Matchers::BuiltIn::BaseMatcher
- RSpec::Matchers::BuiltIn::Be
- RSpec::Matchers::BuiltIn::BeAKindOf
- RSpec::Matchers::BuiltIn::BeAnInstanceOf
- RSpec::Matchers::BuiltIn::BeComparedTo
- RSpec::Matchers::BuiltIn::BeFalse
- RSpec::Matchers::BuiltIn::BeHelpers
- RSpec::Matchers::BuiltIn::BeNil
- RSpec::Matchers::BuiltIn::BePredicate
- RSpec::Matchers::BuiltIn::BeTrue
- RSpec::Matchers::BuiltIn::BeWithin
- RSpec::Matchers::BuiltIn::Change
- RSpec::Matchers::BuiltIn::Cover
- RSpec::Matchers::BuiltIn::EndWith
- RSpec::Matchers::BuiltIn::Eq
- RSpec::Matchers::BuiltIn::Eql
- RSpec::Matchers::BuiltIn::Equal
- RSpec::Matchers::BuiltIn::Exist
- RSpec::Matchers::BuiltIn::Has
- RSpec::Matchers::BuiltIn::Have
- RSpec::Matchers::BuiltIn::Include
- RSpec::Matchers::BuiltIn::Match
- RSpec::Matchers::BuiltIn::MatchArray
- RSpec::Matchers::BuiltIn::NegativeOperatorMatcher
- RSpec::Matchers::BuiltIn::PositiveOperatorMatcher
- RSpec::Matchers::BuiltIn::RaiseError
- RSpec::Matchers::BuiltIn::RespondTo
- RSpec::Matchers::BuiltIn::Satisfy
- RSpec::Matchers::BuiltIn::StartAndEndWith
- RSpec::Matchers::BuiltIn::StartWith
- RSpec::Matchers::BuiltIn::ThrowSymbol
- RSpec::Matchers::BuiltIn::YieldControl
- RSpec::Matchers::BuiltIn::YieldProbe
- RSpec::Matchers::BuiltIn::YieldSuccessiveArgs
- RSpec::Matchers::BuiltIn::YieldWithArgs
- RSpec::Matchers::BuiltIn::YieldWithNoArgs
- RSpec::Matchers::Configuration
- RSpec::Matchers::DSL
- RSpec::Matchers::DSL::Matcher
- RSpec::Matchers::Extensions
- RSpec::Matchers::Extensions::InstanceEvalWithArgs
- RSpec::Matchers::OperatorMatcher
- RSpec::Matchers::Pretty
- Array

No matching classes.

# RSpec::Matchers::BuiltIn::BeWithin

### Public Class Methods

new(delta) click to toggle source

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

### Public Instance Methods

==(actual) click to toggle source
Alias for: matches?
description() click to toggle source

    # File lib/rspec/matchers/built_in/be_within.rb, line 39
    def description
      "be within #{@delta}#{@unit} of #{@expected}"
    end

failure_message_for_should() click to toggle source

    # File lib/rspec/matchers/built_in/be_within.rb, line 31
    def failure_message_for_should
      "expected #{@actual} to #{description}"
    end

failure_message_for_should_not() click to toggle source

    # File lib/rspec/matchers/built_in/be_within.rb, line 35
    def failure_message_for_should_not
      "expected #{@actual} not to #{description}"
    end

matches?(actual) click to toggle source

    # File lib/rspec/matchers/built_in/be_within.rb, line 9
    def matches?(actual)
      @actual = actual
      raise needs_expected     unless defined? @expected
      raise needs_subtractable unless @actual.respond_to? :-
      (@actual - @expected).abs <= @tolerance
    end

Also aliased as: ==
of(expected) click to toggle source

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

percent_of(expected) click to toggle source

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

[Validate]

Generated with the Darkfish Rdoc Generator 2.