Sha256: 2e36b870237370fe7870ca7c9339c5c8d5cb319c931c2b2b46323fc62c3caf04

Contents?: true

Size: 830 Bytes

Versions: 18

Compression:

Stored size: 830 Bytes

Contents

module Rspec
  module Matchers
    # :call-seq:
    #   should be_close(expected, delta)
    #   should_not be_close(expected, delta)
    #
    # Passes if actual == expected +/- delta
    #
    # == Example
    #
    #   result.should be_close(3.0, 0.5)
    def be_close(expected, delta)
      Matcher.new :be_close, expected, delta do |_expected_, _delta_|
        match do |actual|
          (actual - _expected_).abs < _delta_
        end

        failure_message_for_should do |actual|
          "expected #{_expected_} +/- (< #{_delta_}), got #{actual}"
        end

        failure_message_for_should_not do |actual|
          "expected #{_expected_} +/- (< #{_delta_}), got #{actual}"
        end

        description do
          "be close to #{_expected_} (within +- #{_delta_})"
        end
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
rspec-expectations-2.0.0.beta.8 lib/rspec/matchers/be_close.rb
rspec-expectations-2.0.0.beta.7 lib/rspec/matchers/be_close.rb
rspec-expectations-2.0.0.beta.6 lib/rspec/matchers/be_close.rb
rspec-expectations-2.0.0.beta.5 lib/rspec/matchers/be_close.rb
rspec-expectations-2.0.0.beta.4 lib/rspec/matchers/be_close.rb
rspec-expectations-2.0.0.beta.3 lib/rspec/matchers/be_close.rb
rspec-expectations-2.0.0.beta.2 lib/rspec/matchers/be_close.rb
rspec-expectations-2.0.0.beta.1 lib/rspec/matchers/be_close.rb
rspec-expectations-2.0.0.a10 lib/rspec/matchers/be_close.rb
rspec-expectations-2.0.0.a9 lib/rspec/matchers/be_close.rb
rspec-expectations-2.0.0.a8 lib/rspec/matchers/be_close.rb
rspec-expectations-2.0.0.a7 lib/rspec/matchers/be_close.rb
rspec-expectations-2.0.0.a6 lib/rspec/matchers/be_close.rb
rspec-expectations-2.0.0.a5 lib/rspec/matchers/be_close.rb
rspec-expectations-2.0.0.a4 lib/rspec/matchers/be_close.rb
rspec-expectations-2.0.0.a3 lib/rspec/matchers/be_close.rb
rspec-expectations-2.0.0.a2 lib/rspec/matchers/be_close.rb
rspec-expectations-2.0.0.a1 lib/rspec/matchers/be_close.rb