Sha256: f6cfe20076011c8676e158241a1baf9b999fd30f6b6740edcdb2f8f1bca48161

Contents?: true

Size: 787 Bytes

Versions: 1

Compression:

Stored size: 787 Bytes

Contents

module TestHelpers
  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
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pulse-meter-0.0.1 lib/test_helpers/matchers.rb