diff options
| author | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2007-03-17 02:48:41 +0000 |
|---|---|---|
| committer | luke <luke@980ebf18-57e1-0310-9a29-db15c13687c0> | 2007-03-17 02:48:41 +0000 |
| commit | ba23a5ac276e59fdda8186750c6d0fd2cfecdeac (patch) | |
| tree | 1e14b25ade74ea52d8da2788ede9b12b507867e8 /test/lib/spec/matchers/be_close.rb | |
| parent | 8ea6adaeb1e3d0aa6348c2a2c3a385d185372d06 (diff) | |
| download | puppet-ba23a5ac276e59fdda8186750c6d0fd2cfecdeac.tar.gz puppet-ba23a5ac276e59fdda8186750c6d0fd2cfecdeac.tar.xz puppet-ba23a5ac276e59fdda8186750c6d0fd2cfecdeac.zip | |
Adding spec libs, so we can use them some day
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2283 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'test/lib/spec/matchers/be_close.rb')
| -rw-r--r-- | test/lib/spec/matchers/be_close.rb | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/test/lib/spec/matchers/be_close.rb b/test/lib/spec/matchers/be_close.rb new file mode 100644 index 000000000..b09e3fd2f --- /dev/null +++ b/test/lib/spec/matchers/be_close.rb @@ -0,0 +1,37 @@ +module Spec + module Matchers + + class BeClose #:nodoc: + def initialize(expected, delta) + @expected = expected + @delta = delta + end + + def matches?(actual) + @actual = actual + (@actual - @expected).abs < @delta + end + + def failure_message + "expected #{@expected} +/- (<#{@delta}), got #{@actual}" + end + + def description + "be close to #{@expected} (+- #{@delta})" + end + end + + # :call-seq: + # should be_close(expected, delta) + # should_not be_close(expected, delta) + # + # Passes if actual == expected +/- delta + # + # == Example + # + # result.should be_close(3.0, 0.5) + def be_close(expected, delta) + Matchers::BeClose.new(expected, delta) + end + end +end
\ No newline at end of file |
