Sha256: a6c968bc30218520c812deb8f3fccaddae952f2123c51a37f8ebfeed927787f9

Contents?: true

Size: 1.94 KB

Versions: 61

Compression:

Stored size: 1.94 KB

Contents

require 'spec_helper'

module RSpec
  module Matchers
    describe "[actual.should] be_within(delta).of(expected)" do
      it "matches when actual == expected" do
        be_within(0.5).of(5.0).matches?(5.0).should be_true
      end

      it "matches when actual < (expected + delta)" do
        be_within(0.5).of(5.0).matches?(5.49).should be_true
      end

      it "matches when actual > (expected - delta)" do
        be_within(0.5).of(5.0).matches?(4.51).should be_true
      end

      it "matches when actual == (expected - delta)" do
        be_within(0.5).of(5.0).matches?(4.5).should be_true
      end

      it "does not match when actual < (expected - delta)" do
        be_within(0.5).of(5.0).matches?(4.49).should be_false
      end

      it "matches when actual == (expected + delta)" do
        be_within(0.5).of(5.0).matches?(5.5).should be_true
      end

      it "does not match when actual > (expected + delta)" do
        be_within(0.5).of(5.0).matches?(5.51).should be_false
      end

      it "provides a failure message for should" do
        #given
          matcher = be_within(0.5).of(5.0)
        #when
          matcher.matches?(5.51)
        #then
          matcher.failure_message_for_should.should == "expected 5.51 to be within 0.5 of 5.0"
      end

      it "provides a failure message for should not" do
        #given
          matcher = be_within(0.5).of(5.0)
        #when
          matcher.matches?(5.49)
        #then
          matcher.failure_message_for_should_not.should == "expected 5.49 not to be within 0.5 of 5.0"
      end

      it "provides a description" do
        matcher = be_within(0.5).of(5.0)
        matcher.matches?(5.1)
        matcher.description.should == "be within 0.5 of 5.0"
      end

      it "raises an error if no expected value is given" do
        matcher = be_within(0.5)
        expect { matcher.matches?(5.1) }.to raise_error(ArgumentError, /must set an expected value using #of/)
      end
    end
  end
end

Version data entries

61 entries across 56 versions & 5 rubygems

Version Path
classiccms-0.7.5 vendor/bundle/gems/rspec-expectations-2.10.0/spec/rspec/matchers/be_within_spec.rb
classiccms-0.7.4 vendor/bundle/gems/rspec-expectations-2.10.0/spec/rspec/matchers/be_within_spec.rb
classiccms-0.7.3 vendor/bundle/gems/rspec-expectations-2.10.0/spec/rspec/matchers/be_within_spec.rb
classiccms-0.7.2 vendor/bundle/gems/rspec-expectations-2.10.0/spec/rspec/matchers/be_within_spec.rb
classiccms-0.7.1 vendor/bundle/gems/rspec-expectations-2.10.0/spec/rspec/matchers/be_within_spec.rb
classiccms-0.7.0 vendor/bundle/gems/rspec-expectations-2.10.0/spec/rspec/matchers/be_within_spec.rb
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/rspec-expectations-2.10.0/spec/rspec/matchers/be_within_spec.rb
classiccms-0.6.9 vendor/bundle/gems/rspec-expectations-2.10.0/spec/rspec/matchers/be_within_spec.rb
classiccms-0.6.8 vendor/bundle/gems/rspec-expectations-2.10.0/spec/rspec/matchers/be_within_spec.rb
classiccms-0.6.7 vendor/bundle/gems/rspec-expectations-2.10.0/spec/rspec/matchers/be_within_spec.rb
classiccms-0.6.6 vendor/bundle/gems/rspec-expectations-2.10.0/spec/rspec/matchers/be_within_spec.rb
classiccms-0.6.5 vendor/bundle/gems/rspec-expectations-2.10.0/spec/rspec/matchers/be_within_spec.rb
classiccms-0.6.4 vendor/bundle/gems/rspec-expectations-2.10.0/spec/rspec/matchers/be_within_spec.rb
classiccms-0.6.3 vendor/bundle/gems/rspec-expectations-2.10.0/spec/rspec/matchers/be_within_spec.rb
classiccms-0.6.2 vendor/bundle/gems/rspec-expectations-2.10.0/spec/rspec/matchers/be_within_spec.rb
classiccms-0.6.1 vendor/bundle/gems/rspec-expectations-2.10.0/spec/rspec/matchers/be_within_spec.rb
classiccms-0.6.0 vendor/bundle/gems/rspec-expectations-2.10.0/spec/rspec/matchers/be_within_spec.rb
classiccms-0.5.17 vendor/bundle/gems/rspec-expectations-2.10.0/spec/rspec/matchers/be_within_spec.rb
classiccms-0.5.16 vendor/bundle/gems/rspec-expectations-2.10.0/spec/rspec/matchers/be_within_spec.rb
classiccms-0.5.15 vendor/bundle/gems/rspec-expectations-2.10.0/spec/rspec/matchers/be_within_spec.rb