Sha256: b7b7db1ac8fb87eb895f7723138b07f77d3d304acf1686aefe274af10aadc0dd

Contents?: true

Size: 983 Bytes

Versions: 3

Compression:

Stored size: 983 Bytes

Contents

module TestBelt::Matchers
  module HaveInstanceMethods

    def self.included(receiver)
      receiver.send(:extend, ClassMethods)
    end

    module ClassMethods
      def have_instance_methods(*meths)
        meths.collect do |meth|
          Matcher.new(meth)
        end
      end
      alias_method :have_instance_method, :have_instance_methods
    end

    class Matcher < ::TestBelt::Matchers::Base
      def initialize(method)
        unless method.kind_of?(::String) || method.kind_of?(::Symbol)
          raise ArgumentError, "please specify the method name using a string or symbol"
        end
        @method = method
      end

      def desc
        "respond to #{method_type} ##{@method}"
      end

      def test
        using(@method) do |method|
          assert subject.respond_to?(method, true), "#{subject.class.name} does not have instance method ##{method}"
        end
      end

      def method_type
        "instance method"
      end
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
test-belt-2.0.1 lib/test_belt/matchers/have_instance_methods.rb
test-belt-2.0.0 lib/test_belt/matchers/have_instance_methods.rb
test-belt-1.1.2 lib/test_belt/matchers/have_instance_methods.rb