Sha256: c659914e5677a5e0a0a196f172c96c3f1062caa5d5df6555a7fdffd0f86dbec7

Contents?: true

Size: 1.7 KB

Versions: 27

Compression:

Stored size: 1.7 KB

Contents

require 'spec_helper'
module RSpec
  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 failure message for should tno" do
        #given
          matcher = be_close(5.0, 0.5)
        #when
          matcher.matches?(5.49)
        #then
          matcher.failure_message_for_should_not.should == "expected 5.0 +/- (< 0.5), got 5.49"
      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

27 entries across 27 versions & 2 rubygems

Version Path
rspec-expectations-2.0.1 spec/rspec/matchers/be_close_spec.rb
gemrage-1.0.0 vendor/ruby/1.8/gems/rspec-expectations-2.0.0/spec/rspec/matchers/be_close_spec.rb
gemrage-0.4.1 vendor/ruby/1.8/gems/rspec-expectations-2.0.0/spec/rspec/matchers/be_close_spec.rb
gemrage-0.4.0 vendor/ruby/1.8/gems/rspec-expectations-2.0.0/spec/rspec/matchers/be_close_spec.rb
gemrage-0.3.2 vendor/ruby/1.8/gems/rspec-expectations-2.0.0/spec/rspec/matchers/be_close_spec.rb
gemrage-0.3.1 vendor/ruby/1.8/gems/rspec-expectations-2.0.0/spec/rspec/matchers/be_close_spec.rb
gemrage-0.3.0 vendor/ruby/1.8/gems/rspec-expectations-2.0.0/spec/rspec/matchers/be_close_spec.rb
gemrage-0.2.0 vendor/ruby/1.8/gems/rspec-expectations-2.0.0/spec/rspec/matchers/be_close_spec.rb
gemrage-0.1.2 vendor/ruby/1.8/gems/rspec-expectations-2.0.0/spec/rspec/matchers/be_close_spec.rb
gemrage-0.1.1 vendor/ruby/1.8/gems/rspec-expectations-2.0.0/spec/rspec/matchers/be_close_spec.rb
gemrage-0.1.0 vendor/ruby/1.8/gems/rspec-expectations-2.0.0/spec/rspec/matchers/be_close_spec.rb
gemrage-0.0.0 vendor/ruby/1.8/gems/rspec-expectations-2.0.0/spec/rspec/matchers/be_close_spec.rb
rspec-expectations-2.0.0 spec/rspec/matchers/be_close_spec.rb
rspec-expectations-2.0.0.rc spec/rspec/matchers/be_close_spec.rb
rspec-expectations-2.0.0.beta.22 spec/rspec/matchers/be_close_spec.rb
rspec-expectations-2.0.0.beta.20 spec/rspec/matchers/be_close_spec.rb
rspec-expectations-2.0.0.beta.19 spec/rspec/matchers/be_close_spec.rb
rspec-expectations-2.0.0.beta.18 spec/rspec/matchers/be_close_spec.rb
rspec-expectations-2.0.0.beta.17 spec/rspec/matchers/be_close_spec.rb
rspec-expectations-2.0.0.beta.16 spec/rspec/matchers/be_close_spec.rb