Sha256: 8d216831f639912781ec0715172820700370358bf192e6f271b1dcfe73baaa4f

Contents?: true

Size: 809 Bytes

Versions: 47

Compression:

Stored size: 809 Bytes

Contents

module Spec
  module Matchers

    class BeClose #:nodoc:
      def initialize(expected, delta)
        @expected = expected
        @delta = delta
      end
      
      def matches?(actual)
        @actual = actual
        (@actual - @expected).abs < @delta
      end
      
      def failure_message
        "expected #{@expected} +/- (< #{@delta}), got #{@actual}"
      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 actual == 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

47 entries across 47 versions & 9 rubygems

Version Path
jnstq-acts_as_sms-0.1.0 test/vendor/plugins/rspec/lib/spec/matchers/be_close.rb
jnstq-acts_as_sms-0.1.1 test/vendor/plugins/rspec/lib/spec/matchers/be_close.rb
jnstq-acts_as_sms-0.1.3 test/vendor/plugins/rspec/lib/spec/matchers/be_close.rb
jnstq-acts_as_sms-0.1.4 test/vendor/plugins/rspec/lib/spec/matchers/be_close.rb
deckshuffler-0.0.2 vendor/plugins/rspec/lib/spec/matchers/be_close.rb
has_finder-0.1.1 spec/rails/vendor/plugins/rspec/lib/spec/matchers/be_close.rb
has_finder-0.1.2 spec/rails/vendor/plugins/rspec/lib/spec/matchers/be_close.rb
has_finder-0.1.3 spec/rails/vendor/plugins/rspec/lib/spec/matchers/be_close.rb
picolena-0.0.99 app_generators/picolena/templates/vendor/plugins/rspec/lib/spec/matchers/be_close.rb
picolena-0.1.0 rails_plugins/rspec/lib/spec/matchers/be_close.rb
picolena-0.1.1 rails_plugins/rspec/lib/spec/matchers/be_close.rb
picolena-0.1.3 rails_plugins/rspec/lib/spec/matchers/be_close.rb
picolena-0.1.4 rails_plugins/rspec/lib/spec/matchers/be_close.rb
picolena-0.1.2 rails_plugins/rspec/lib/spec/matchers/be_close.rb
picolena-0.1.5 rails_plugins/rspec/lib/spec/matchers/be_close.rb
pictrails-0.5.0 vendor/plugins/rspec/lib/spec/matchers/be_close.rb
radiant-0.6.5.1 vendor/plugins/rspec/lib/spec/matchers/be_close.rb
radiant-0.6.5 vendor/plugins/rspec/lib/spec/matchers/be_close.rb
radiant-0.6.6 vendor/plugins/rspec/lib/spec/matchers/be_close.rb
radiant-0.6.7 vendor/plugins/rspec/lib/spec/matchers/be_close.rb