Sha256: 37d6a9cf5032a08face4fbc29b916121c76cd00beeea835a0619740b88c8ca92

Contents?: true

Size: 1.46 KB

Versions: 2

Compression:

Stored size: 1.46 KB

Contents

require File.dirname(__FILE__) + '/../../spec_helper.rb'
module Spec
  module Matchers
    describe "[actual.should] be_close(expected, delta)" do
      it "matches when actual == expected" do
        be_close(5.0, 0.5).matches?(5.0).should be_true
      end
      it "matches when actual < (expected + delta)" do
        be_close(5.0, 0.5).matches?(5.49).should be_true
      end
      it "matches when actual > (expected - delta)" do
        be_close(5.0, 0.5).matches?(4.51).should be_true
      end
      it "does not match when actual == (expected - delta)" do
        be_close(5.0, 0.5).matches?(4.5).should be_false
      end
      it "does not match when actual < (expected - delta)" do
        be_close(5.0, 0.5).matches?(4.49).should be_false
      end
      it "does not match when actual == (expected + delta)" do
        be_close(5.0, 0.5).matches?(5.5).should be_false
      end
      it "does not match when actual > (expected + delta)" do
        be_close(5.0, 0.5).matches?(5.51).should be_false
      end
      it "provides a failure message for should" do
        #given
          matcher = be_close(5.0, 0.5)
        #when
          matcher.matches?(5.51)
        #then
          matcher.failure_message_for_should.should == "expected 5.0 +/- (< 0.5), got 5.51"
      end
      it "provides a description" do
        matcher = be_close(5.0, 0.5)
        matcher.matches?(5.1)
        matcher.description.should == "be close to 5.0 (within +- 0.5)"
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rspec-1.2.2 spec/spec/matchers/be_close_spec.rb
rspec-1.2.1 spec/spec/matchers/be_close_spec.rb