]> git.openstreetmap.org Git - rails.git/blob - vendor/gems/rspec-1.1.2/lib/spec/matchers/satisfy.rb
added RSpec and RSpec on Rails
[rails.git] / vendor / gems / rspec-1.1.2 / lib / spec / matchers / satisfy.rb
1 module Spec
2   module Matchers
3     
4     class Satisfy #:nodoc:
5       def initialize(&block)
6         @block = block
7       end
8       
9       def matches?(actual, &block)
10         @block = block if block
11         @actual = actual
12         @block.call(actual)
13       end
14       
15       def failure_message
16         "expected #{@actual} to satisfy block"
17       end
18
19       def negative_failure_message
20         "expected #{@actual} not to satisfy block"
21       end
22     end
23     
24     # :call-seq:
25     #   should satisfy {}
26     #   should_not satisfy {}
27     #
28     # Passes if the submitted block returns true. Yields target to the
29     # block.
30     #
31     # Generally speaking, this should be thought of as a last resort when
32     # you can't find any other way to specify the behaviour you wish to
33     # specify.
34     #
35     # If you do find yourself in such a situation, you could always write
36     # a custom matcher, which would likely make your specs more expressive.
37     #
38     # == Examples
39     #
40     #   5.should satisfy { |n|
41     #     n > 3
42     #   }
43     def satisfy(&block)
44       Matchers::Satisfy.new(&block)
45     end
46   end
47 end