Sha256: 41ffb77426b1ebdd5d91c849c304b5be921314c2923b21cba84bb90b7118ea35

Contents?: true

Size: 1.05 KB

Versions: 3

Compression:

Stored size: 1.05 KB

Contents

module Spec
  module Matchers

    class RespondTo #:nodoc:
      def initialize(*names)
        @names = names
        @names_not_responded_to = []
      end

      def matches?(target)
        @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 #{@names_not_responded_to.collect {|name| name.inspect }.join(', ')}"
      end

      def negative_failure_message
        "expected target 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

3 entries across 3 versions & 1 rubygems

Version Path
picolena-0.1.6 rails_plugins/rspec/lib/spec/matchers/respond_to.rb
picolena-0.1.7 rails_plugins/rspec/lib/spec/matchers/respond_to.rb
picolena-0.1.8 rails_plugins/rspec/lib/spec/matchers/respond_to.rb