]> git.openstreetmap.org Git - rails.git/blob - vendor/gems/rspec-1.1.2/lib/spec/matchers/respond_to.rb
Show whether a trace is public or private in the trace list, so that a user can easil...
[rails.git] / vendor / gems / rspec-1.1.2 / lib / spec / matchers / respond_to.rb
1 module Spec
2   module Matchers
3     
4     class RespondTo #:nodoc:
5       def initialize(*names)
6         @names = names
7         @names_not_responded_to = []
8       end
9       
10       def matches?(target)
11         @names.each do |name|
12           unless target.respond_to?(name)
13             @names_not_responded_to << name
14           end
15         end
16         return @names_not_responded_to.empty?
17       end
18       
19       def failure_message
20         "expected target to respond to #{@names_not_responded_to.collect {|name| name.inspect }.join(', ')}"
21       end
22       
23       def negative_failure_message
24         "expected target not to respond to #{@names.collect {|name| name.inspect }.join(', ')}"
25       end
26       
27       def description
28         "respond to ##{@names.to_s}"
29       end
30     end
31     
32     # :call-seq:
33     #   should respond_to(*names)
34     #   should_not respond_to(*names)
35     #
36     # Matches if the target object responds to all of the names
37     # provided. Names can be Strings or Symbols.
38     #
39     # == Examples
40     # 
41     def respond_to(*names)
42       Matchers::RespondTo.new(*names)
43     end
44   end
45 end