Sha256: 7dfd2e1af464d011b5be74c95ffc4fdf4b81bd56ef20dc34ea605528a33fd16f

Contents?: true

Size: 1.44 KB

Versions: 9

Compression:

Stored size: 1.44 KB

Contents

require 'spec_helper'
require 'mspec/expectations/expectations'
require 'mspec/matchers'

# Adapted from RSpec 1.0.8
describe BeCloseMatcher do
  it "matches when actual == expected" do
    BeCloseMatcher.new(5.0, 0.5).matches?(5.0).should == true
  end

  it "matches when actual < (expected + tolerance)" do
    BeCloseMatcher.new(5.0, 0.5).matches?(5.49).should == true
  end

  it "matches when actual > (expected - tolerance)" do
    BeCloseMatcher.new(5.0, 0.5).matches?(4.51).should == true
  end

  it "does not match when actual == (expected + tolerance)" do
    BeCloseMatcher.new(5.0, 0.5).matches?(5.5).should == false
  end

  it "does not match when actual == (expected - tolerance)" do
    BeCloseMatcher.new(5.0, 0.5).matches?(4.5).should == false
  end

  it "does not match when actual < (expected - tolerance)" do
    BeCloseMatcher.new(5.0, 0.5).matches?(4.49).should == false
  end

  it "does not match when actual > (expected + tolerance)" do
    BeCloseMatcher.new(5.0, 0.5).matches?(5.51).should == false
  end

  it "provides a useful failure message" do
    matcher = BeCloseMatcher.new(5.0, 0.5)
    matcher.matches?(5.5)
    matcher.failure_message.should == ["Expected 5.0", "to be within +/- 0.5 of 5.5"]
  end

  it "provides a useful negative failure message" do
    matcher = BeCloseMatcher.new(5.0, 0.5)
    matcher.matches?(5.0)
    matcher.negative_failure_message.should == ["Expected 5.0", "not to be within +/- 0.5 of 5.0"]
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
mspec-1.9.1 spec/matchers/be_close_spec.rb
mspec-1.9.0 spec/matchers/be_close_spec.rb
mspec-1.8.0 spec/matchers/be_close_spec.rb
mspec-1.7.0 spec/matchers/be_close_spec.rb
mspec-1.6.0 spec/matchers/be_close_spec.rb
mspec-1.5.21 spec/matchers/be_close_spec.rb
mspec-1.5.20 spec/matchers/be_close_spec.rb
mspec-1.5.19 spec/matchers/be_close_spec.rb
mspec-1.5.18 spec/matchers/be_close_spec.rb