Sha256: 7c3150c03bc095de8107b46f512bb4e26fb3dc80b6f41ec9642bcc644a219c03

Contents?: true

Size: 862 Bytes

Versions: 108

Compression:

Stored size: 862 Bytes

Contents

module RSpec
  module Matchers
    module BuiltIn
      class BeWithin
        include BaseMatcher

        attr_reader :delta

        def initialize(delta)
          @delta = delta
        end

        def matches?(actual)
          unless defined?(@expected)
            raise ArgumentError.new("You must set an expected value using #of: be_within(#{delta}).of(expected_value)")
          end
          (super(actual) - expected).abs < delta
        end

        def of(expected)
          @expected = expected
          self
        end

        def failure_message_for_should
          "expected #{actual} to #{description}"
        end

        def failure_message_for_should_not
          "expected #{actual} not to #{description}"
        end

        def description
          "be within #{delta} of #{expected}"
        end
      end
    end
  end
end

Version data entries

108 entries across 61 versions & 6 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/rspec-expectations-2.9.1/lib/rspec/matchers/built_in/be_within.rb
classiccms-0.7.5 vendor/bundle/gems/rspec-expectations-2.9.0/lib/rspec/matchers/built_in/be_within.rb
classiccms-0.7.4 vendor/bundle/gems/rspec-expectations-2.9.1/lib/rspec/matchers/built_in/be_within.rb
classiccms-0.7.4 vendor/bundle/gems/rspec-expectations-2.9.0/lib/rspec/matchers/built_in/be_within.rb
classiccms-0.7.3 vendor/bundle/gems/rspec-expectations-2.9.0/lib/rspec/matchers/built_in/be_within.rb
classiccms-0.7.3 vendor/bundle/gems/rspec-expectations-2.9.1/lib/rspec/matchers/built_in/be_within.rb
classiccms-0.7.2 vendor/bundle/gems/rspec-expectations-2.9.1/lib/rspec/matchers/built_in/be_within.rb
classiccms-0.7.2 vendor/bundle/gems/rspec-expectations-2.9.0/lib/rspec/matchers/built_in/be_within.rb
classiccms-0.7.1 vendor/bundle/gems/rspec-expectations-2.9.1/lib/rspec/matchers/built_in/be_within.rb
classiccms-0.7.1 vendor/bundle/gems/rspec-expectations-2.9.0/lib/rspec/matchers/built_in/be_within.rb
classiccms-0.7.0 vendor/bundle/gems/rspec-expectations-2.9.0/lib/rspec/matchers/built_in/be_within.rb
classiccms-0.7.0 vendor/bundle/gems/rspec-expectations-2.9.1/lib/rspec/matchers/built_in/be_within.rb
classiccms-0.6.9 vendor/bundle/gems/rspec-expectations-2.9.0/lib/rspec/matchers/built_in/be_within.rb
classiccms-0.6.9 vendor/bundle/gems/rspec-expectations-2.9.1/lib/rspec/matchers/built_in/be_within.rb
classiccms-0.6.8 vendor/bundle/gems/rspec-expectations-2.9.0/lib/rspec/matchers/built_in/be_within.rb
classiccms-0.6.8 vendor/bundle/gems/rspec-expectations-2.9.1/lib/rspec/matchers/built_in/be_within.rb
classiccms-0.6.7 vendor/bundle/gems/rspec-expectations-2.9.1/lib/rspec/matchers/built_in/be_within.rb
classiccms-0.6.7 vendor/bundle/gems/rspec-expectations-2.9.0/lib/rspec/matchers/built_in/be_within.rb
classiccms-0.6.6 vendor/bundle/gems/rspec-expectations-2.9.0/lib/rspec/matchers/built_in/be_within.rb
classiccms-0.6.6 vendor/bundle/gems/rspec-expectations-2.9.1/lib/rspec/matchers/built_in/be_within.rb