Sha256: 46ece91e531b7a42a83a0df361321f3ab83db2455f377637ed08130e4e25436e

Contents?: true

Size: 1.37 KB

Versions: 49

Compression:

Stored size: 1.37 KB

Contents

require File.expand_path(File.dirname(__FILE__) + "/../../../example_helper")

describe Micronaut::Matchers do

  describe "be_close" do

    it "should match when value == target" do
      be_close(5.0, 0.5).matches?(5.0).should be_true
    end

    it "should match when value < (target + delta)" do
      be_close(5.0, 0.5).matches?(5.49).should be_true
    end

    it "should match when value > (target - delta)" do
      be_close(5.0, 0.5).matches?(4.51).should be_true
    end

    it "should not match when value == (target - delta)" do
      be_close(5.0, 0.5).matches?(4.5).should be_false
    end

    it "should not match when value < (target - delta)" do
      be_close(5.0, 0.5).matches?(4.49).should be_false
    end

    it "should not match when value == (target + delta)" do
      be_close(5.0, 0.5).matches?(5.5).should be_false
    end

    it "should not match when value > (target + delta)" do
      be_close(5.0, 0.5).matches?(5.51).should be_false
    end

    it "should provide a useful failure message" do
      #given
      matcher = be_close(5.0, 0.5)
      #when
      matcher.matches?(5.51)
      #then
      matcher.failure_message.should == "expected 5.0 +/- (< 0.5), got 5.51"
    end

    it "should describe itself" 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

Version data entries

49 entries across 49 versions & 3 rubygems

Version Path
rsanheim-micronaut-0.1.3.2 examples/lib/micronaut/matchers/be_close_example.rb
rsanheim-micronaut-0.1.4.1 examples/lib/micronaut/matchers/be_close_example.rb
spicycode-micronaut-0.0.9 examples/lib/micronaut/matchers/be_close_example.rb
spicycode-micronaut-0.1.0 examples/lib/micronaut/matchers/be_close_example.rb
spicycode-micronaut-0.1.1 examples/lib/micronaut/matchers/be_close_example.rb
spicycode-micronaut-0.1.2 examples/lib/micronaut/matchers/be_close_example.rb
spicycode-micronaut-0.1.3 examples/lib/micronaut/matchers/be_close_example.rb
spicycode-micronaut-0.1.4.1 examples/lib/micronaut/matchers/be_close_example.rb
spicycode-micronaut-0.1.4.2 examples/lib/micronaut/matchers/be_close_example.rb
spicycode-micronaut-0.1.4.3 examples/lib/micronaut/matchers/be_close_example.rb
spicycode-micronaut-0.1.4.4 examples/lib/micronaut/matchers/be_close_example.rb
spicycode-micronaut-0.1.4 examples/lib/micronaut/matchers/be_close_example.rb
spicycode-micronaut-0.1.5.2 examples/lib/micronaut/matchers/be_close_example.rb
spicycode-micronaut-0.1.5 examples/lib/micronaut/matchers/be_close_example.rb
spicycode-micronaut-0.1.6.1 examples/lib/micronaut/matchers/be_close_example.rb
spicycode-micronaut-0.1.6.8 examples/lib/micronaut/matchers/be_close_example.rb
spicycode-micronaut-0.1.6.9.1 examples/lib/micronaut/matchers/be_close_example.rb
spicycode-micronaut-0.1.6.9 examples/lib/micronaut/matchers/be_close_example.rb
spicycode-micronaut-0.1.6 examples/lib/micronaut/matchers/be_close_example.rb
spicycode-micronaut-0.1.7.1 examples/lib/micronaut/matchers/be_close_example.rb