~ubuntu-branches/ubuntu/oneiric/puppet/oneiric-security

« back to all changes in this revision

Viewing changes to vendor/gems/rspec/lib/spec/matchers/be_close.rb

  • Committer: Bazaar Package Importer
  • Author(s): Micah Anderson
  • Date: 2008-07-26 15:43:45 UTC
  • mto: (3.1.1 lenny) (1.3.1 upstream)
  • mto: This revision was merged to the branch mainline in revision 16.
  • Revision ID: james.westby@ubuntu.com-20080726154345-1fmgo76b4l72ulvc
ImportĀ upstreamĀ versionĀ 0.24.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
module Spec
 
2
  module Matchers
 
3
 
 
4
    class BeClose #:nodoc:
 
5
      def initialize(expected, delta)
 
6
        @expected = expected
 
7
        @delta = delta
 
8
      end
 
9
      
 
10
      def matches?(actual)
 
11
        @actual = actual
 
12
        (@actual - @expected).abs < @delta
 
13
      end
 
14
      
 
15
      def failure_message
 
16
        "expected #{@expected} +/- (< #{@delta}), got #{@actual}"
 
17
      end
 
18
      
 
19
      def description
 
20
        "be close to #{@expected} (within +- #{@delta})"
 
21
      end
 
22
    end
 
23
    
 
24
    # :call-seq:
 
25
    #   should be_close(expected, delta)
 
26
    #   should_not be_close(expected, delta)
 
27
    #
 
28
    # Passes if actual == expected +/- delta
 
29
    #
 
30
    # == Example
 
31
    #
 
32
    #   result.should be_close(3.0, 0.5)
 
33
    def be_close(expected, delta)
 
34
      Matchers::BeClose.new(expected, delta)
 
35
    end
 
36
  end
 
37
end