Sha256: e20d9962dd6487ce5e48f3df7d4b54ccb3841e1b2da6e4d0a250f8cdd6254153

Contents?: true

Size: 517 Bytes

Versions: 1

Compression:

Stored size: 517 Bytes

Contents

module BaconExpect; module Matcher
  class BeWithin
    def initialize(range)
      @range = range
    end

    def of(center_value)
      @center_value = center_value
      self
    end

    def matches?(subject)
      raise InvalidMatcher.new("be_within matcher incomplete. Missing .of value") unless @center_value
      (subject - @center_value).abs <= @range
    end

    def fail!(subject)
      raise FailedExpectation.new("#{subject} expected to be within #{@range} of #{@center_value}")
    end
  end
end; end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bacon-expect-1.0.2 lib/bacon-expect/matchers/be_within.rb