Sha256: a0376f2beadec1d2392f077c8c653109d3ac2ae824e1b2f678fa340b268b41a8

Contents?: true

Size: 977 Bytes

Versions: 2

Compression:

Stored size: 977 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), "#{subject.class.name} does not have instance method ##{method}"
        end
      end

      def method_type
        "instance method"
      end
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
test-belt-1.1.1 lib/test_belt/matchers/have_instance_methods.rb
test-belt-1.1.0 lib/test_belt/matchers/have_instance_methods.rb