Sha256: f7a6f2395c1da84319fb8126dd23110760b8d8178c1f28d5acd8f682f7887327

Contents?: true

Size: 803 Bytes

Versions: 17

Compression:

Stored size: 803 Bytes

Contents

module Spec
  module Matchers

    class BeClose #:nodoc:
      def initialize(expected, delta)
        @expected = expected
        @delta = delta
      end
      
      def matches?(given)
        @given = given
        (@given - @expected).abs < @delta
      end
      
      def failure_message
        "expected #{@expected} +/- (< #{@delta}), got #{@given}"
      end
      
      def description
        "be close to #{@expected} (within +- #{@delta})"
      end
    end
    
    # :call-seq:
    #   should be_close(expected, delta)
    #   should_not be_close(expected, delta)
    #
    # Passes if given == expected +/- delta
    #
    # == Example
    #
    #   result.should be_close(3.0, 0.5)
    def be_close(expected, delta)
      Matchers::BeClose.new(expected, delta)
    end
  end
end

Version data entries

17 entries across 17 versions & 5 rubygems

Version Path
dchelimsky-rspec-1.1.10 lib/spec/matchers/be_close.rb
dchelimsky-rspec-1.1.11 lib/spec/matchers/be_close.rb
merb-core-1.1.3 spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/lib/spec/matchers/be_close.rb
merb-core-1.1.2 spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/lib/spec/matchers/be_close.rb
merb-core-1.1.1 spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/lib/spec/matchers/be_close.rb
merb-core-1.1.0 spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/lib/spec/matchers/be_close.rb
merb-core-1.1.0.rc1 spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/lib/spec/matchers/be_close.rb
merb-core-1.1.0.pre spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/lib/spec/matchers/be_close.rb
mack-0.8.2 lib/gems/rspec-1.1.11/lib/spec/matchers/be_close.rb
rspec-1.1.10 lib/spec/matchers/be_close.rb
rspec-1.1.7 lib/spec/matchers/be_close.rb
rspec-1.1.6 lib/spec/matchers/be_close.rb
rspec-1.1.11 lib/spec/matchers/be_close.rb
rspec-1.1.9 lib/spec/matchers/be_close.rb
rspec-1.1.8 lib/spec/matchers/be_close.rb
typo-5.1.98 vendor/plugins/rspec/lib/spec/matchers/be_close.rb
typo-5.2 vendor/plugins/rspec/lib/spec/matchers/be_close.rb