Sha256: 7915c89cfbc81314dec5bb193d130e38552570df83280bd2d9e31670679c6e5c

Contents?: true

Size: 917 Bytes

Versions: 3

Compression:

Stored size: 917 Bytes

Contents

module TestBelt::Matchers
  module HaveClassMethods

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

    module ClassMethods
      def have_class_methods(*meths)
        meths.collect do |meth|
          Matcher.new(meth)
        end
      end
      alias_method :have_class_method, :have_class_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 class method ##{@method}"
      end

      def test
        using(@method) do |method|
          assert subject.class.respond_to?(method, true), "#{subject.class.name} does not have the class method ##{method}"
        end
      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_class_methods.rb
test-belt-2.0.0 lib/test_belt/matchers/have_class_methods.rb
test-belt-1.1.2 lib/test_belt/matchers/have_class_methods.rb