Sha256: c8d63949d8afa5216f9e9f1be70e330319e2f4c0845b4f554f6d5e231ca2ffca

Contents?: true

Size: 863 Bytes

Versions: 61

Compression:

Stored size: 863 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

61 entries across 56 versions & 5 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/rspec-expectations-2.10.0/lib/rspec/matchers/built_in/be_within.rb
classiccms-0.7.4 vendor/bundle/gems/rspec-expectations-2.10.0/lib/rspec/matchers/built_in/be_within.rb
classiccms-0.7.3 vendor/bundle/gems/rspec-expectations-2.10.0/lib/rspec/matchers/built_in/be_within.rb
classiccms-0.7.2 vendor/bundle/gems/rspec-expectations-2.10.0/lib/rspec/matchers/built_in/be_within.rb
classiccms-0.7.1 vendor/bundle/gems/rspec-expectations-2.10.0/lib/rspec/matchers/built_in/be_within.rb
classiccms-0.7.0 vendor/bundle/gems/rspec-expectations-2.10.0/lib/rspec/matchers/built_in/be_within.rb
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/rspec-expectations-2.10.0/lib/rspec/matchers/built_in/be_within.rb
classiccms-0.6.9 vendor/bundle/gems/rspec-expectations-2.10.0/lib/rspec/matchers/built_in/be_within.rb
classiccms-0.6.8 vendor/bundle/gems/rspec-expectations-2.10.0/lib/rspec/matchers/built_in/be_within.rb
classiccms-0.6.7 vendor/bundle/gems/rspec-expectations-2.10.0/lib/rspec/matchers/built_in/be_within.rb
classiccms-0.6.6 vendor/bundle/gems/rspec-expectations-2.10.0/lib/rspec/matchers/built_in/be_within.rb
classiccms-0.6.5 vendor/bundle/gems/rspec-expectations-2.10.0/lib/rspec/matchers/built_in/be_within.rb
classiccms-0.6.4 vendor/bundle/gems/rspec-expectations-2.10.0/lib/rspec/matchers/built_in/be_within.rb
classiccms-0.6.3 vendor/bundle/gems/rspec-expectations-2.10.0/lib/rspec/matchers/built_in/be_within.rb
classiccms-0.6.2 vendor/bundle/gems/rspec-expectations-2.10.0/lib/rspec/matchers/built_in/be_within.rb
classiccms-0.6.1 vendor/bundle/gems/rspec-expectations-2.10.0/lib/rspec/matchers/built_in/be_within.rb
classiccms-0.6.0 vendor/bundle/gems/rspec-expectations-2.10.0/lib/rspec/matchers/built_in/be_within.rb
classiccms-0.5.17 vendor/bundle/gems/rspec-expectations-2.10.0/lib/rspec/matchers/built_in/be_within.rb
classiccms-0.5.16 vendor/bundle/gems/rspec-expectations-2.10.0/lib/rspec/matchers/built_in/be_within.rb
classiccms-0.5.15 vendor/bundle/gems/rspec-expectations-2.10.0/lib/rspec/matchers/built_in/be_within.rb