Class Spec::Matchers::BeClose

  1. lib/spec/matchers/be_close.rb
Parent: Object

Methods

public class

  1. new

public instance

  1. description
  2. failure_message_for_should
  3. matches?

Public class methods

new (expected, delta)
[show source]
# File lib/spec/matchers/be_close.rb, line 5
      def initialize(expected, delta)
        @expected, @delta = expected, delta
      end

Public instance methods

description ()
[show source]
# File lib/spec/matchers/be_close.rb, line 18
      def description
        "be close to #{@expected} (within +- #{@delta})"
      end
failure_message_for_should ()
[show source]
# File lib/spec/matchers/be_close.rb, line 14
      def failure_message_for_should
        "expected #{@expected} +/- (< #{@delta}), got #{@actual}"
      end
matches? (actual)
[show source]
# File lib/spec/matchers/be_close.rb, line 9
      def matches?(actual)
        @actual = actual
        (@actual - @expected).abs < @delta
      end