Sha256: e7439184597df536a0deec8c9945cfa0241423e7fcfdd3ba6dfe146fa0f5d41c

Contents?: true

Size: 714 Bytes

Versions: 41

Compression:

Stored size: 714 Bytes

Contents

module Matchers

  class GenerallyEqual

    EPSILON = 0.0001

    def initialize(expected)
      @expected = expected
    end

    def matches?(actual)
      @actual = actual

      if @actual.kind_of?(Float) || @expected.kind_of?(Float)
        (@expected - EPSILON .. @expected + EPSILON).include? @actual
      else
         @expected == @actual
      end
    end

    def failure_message_for_should
      "expected #{@actual.inspect} to be generally equal to #{@expected.inspect}"
    end

    def failure_message_for_should_not
      "expected #{@actual.inspect} not to be generally equal to #{@expected.inspect}"
    end
  end

  def be_generally_equal(expected)
    GenerallyEqual.new(expected)
  end

end

Version data entries

41 entries across 41 versions & 2 rubygems

Version Path
pulse_meter_core-0.5.3 spec/support/matchers.rb
pulse_meter_core-0.5.2 spec/support/matchers.rb
pulse_meter_core-0.5.1 spec/support/matchers.rb
pulse_meter_core-0.5.0 spec/support/matchers.rb
pulse_meter_core-0.4.13 spec/support/matchers.rb
pulse-meter-0.4.9 spec/support/matchers.rb
pulse-meter-0.4.8 spec/support/matchers.rb
pulse-meter-0.4.7 spec/support/matchers.rb
pulse-meter-0.4.6 spec/support/matchers.rb
pulse-meter-0.4.5 spec/support/matchers.rb
pulse-meter-0.4.4 spec/support/matchers.rb
pulse-meter-0.4.3 spec/support/matchers.rb
pulse-meter-0.4.2 spec/support/matchers.rb
pulse-meter-0.4.1 spec/support/matchers.rb
pulse-meter-0.4.0 spec/support/matchers.rb
pulse-meter-0.3.2 spec/support/matchers.rb
pulse-meter-0.3.1 spec/support/matchers.rb
pulse-meter-0.3.0 spec/support/matchers.rb
pulse-meter-0.2.11 spec/support/matchers.rb
pulse-meter-0.2.10 spec/support/matchers.rb