Sha256: 624676164be5b4f49afd886aa42b01e88cba81a187a98493bc5b30f0b93d8da4

Contents?: true

Size: 1.12 KB

Versions: 17

Compression:

Stored size: 1.12 KB

Contents

module Spec
  module Matchers
    
    class RespondTo #:nodoc:
      def initialize(*names)
        @names = names
        @names_not_responded_to = []
      end
      
      def matches?(given)
        @given = given
        @names.each do |name|
          unless given.respond_to?(name)
            @names_not_responded_to << name
          end
        end
        return @names_not_responded_to.empty?
      end
      
      def failure_message
        "expected #{@given.inspect} to respond to #{@names_not_responded_to.collect {|name| name.inspect }.join(', ')}"
      end
      
      def negative_failure_message
        "expected #{@given.inspect} not to respond to #{@names.collect {|name| name.inspect }.join(', ')}"
      end
      
      def description
        "respond to ##{@names.to_s}"
      end
    end
    
    # :call-seq:
    #   should respond_to(*names)
    #   should_not respond_to(*names)
    #
    # 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

Version data entries

17 entries across 17 versions & 5 rubygems

Version Path
dchelimsky-rspec-1.1.10 lib/spec/matchers/respond_to.rb
dchelimsky-rspec-1.1.11 lib/spec/matchers/respond_to.rb
merb-core-1.1.3 spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/lib/spec/matchers/respond_to.rb
merb-core-1.1.2 spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/lib/spec/matchers/respond_to.rb
merb-core-1.1.1 spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/lib/spec/matchers/respond_to.rb
merb-core-1.1.0 spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/lib/spec/matchers/respond_to.rb
merb-core-1.1.0.rc1 spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/lib/spec/matchers/respond_to.rb
merb-core-1.1.0.pre spec10/public/webrat/test_app/gems/gems/rspec-1.1.11/lib/spec/matchers/respond_to.rb
mack-0.8.2 lib/gems/rspec-1.1.11/lib/spec/matchers/respond_to.rb
rspec-1.1.10 lib/spec/matchers/respond_to.rb
rspec-1.1.7 lib/spec/matchers/respond_to.rb
rspec-1.1.6 lib/spec/matchers/respond_to.rb
rspec-1.1.11 lib/spec/matchers/respond_to.rb
rspec-1.1.8 lib/spec/matchers/respond_to.rb
rspec-1.1.9 lib/spec/matchers/respond_to.rb
typo-5.1.98 vendor/plugins/rspec/lib/spec/matchers/respond_to.rb
typo-5.2 vendor/plugins/rspec/lib/spec/matchers/respond_to.rb