lib/spec/matchers/respond_to.rb in rspec-0.8.2 vs lib/spec/matchers/respond_to.rb in rspec-0.9.0

- old
+ new

@@ -1,35 +1,45 @@ module Spec module Matchers class RespondTo #:nodoc: - def initialize(sym) - @sym = sym + def initialize(*names) + @names = names + @names_not_responded_to = [] end def matches?(target) - return target.respond_to?(@sym) + @names.each do |name| + unless target.respond_to?(name) + @names_not_responded_to << name + end + end + return @names_not_responded_to.empty? end def failure_message - "expected target to respond to #{@sym.inspect}" + "expected target to respond to #{@names_not_responded_to.collect {|name| name.inspect }.join(', ')}" end def negative_failure_message - "expected target not to respond to #{@sym.inspect}" + "expected target not to respond to #{@names.collect {|name| name.inspect }.join(', ')}" end def description - "respond to ##{@sym.to_s}" + "respond to ##{@names.to_s}" end end # :call-seq: - # should respond_to(:sym) - # should_not respond_to(:sym) + # should respond_to(*names) + # should_not respond_to(*names) # - # Matches if the target object responds to :sym - def respond_to(sym) - Matchers::RespondTo.new(sym) + # Matches if the target object responds to all of the names + # provided. Names can be Strings or Symbols. + # + # == Examples + # + def respond_to(*names) + Matchers::RespondTo.new(*names) end end end