Sha256: f842320d7047d463a1abb5de2f7fd621aa52278e4a1e434fef3e881796e601c3

Contents?: true

Size: 1.32 KB

Versions: 4

Compression:

Stored size: 1.32 KB

Contents

# frozen_string_literal: true

class Sinclair
  module Matchers
    # @api private
    # @author darthjee
    #
    # AddClassMethod is able to build an instance of {Sinclair::Matchers::AddClassMethodTo}
    #
    # @example
    #   RSpec.configure do |config|
    #     config.include Sinclair::Matchers
    #   end
    #
    #   class MyModel
    #   end
    #
    #   RSpec.describe 'MyBuilder' do
    #     let(:clazz)   { Class.new(MyModel) }
    #
    #     let(:block) do
    #       proc do
    #         clazz.define_singleton_method(:new_method) { 2 }
    #       end
    #     end
    #
    #     it do
    #       expect(&block).to add_class_method(:new_method).to(clazz)
    #     end
    #   end
    #
    #   # outputs
    #   # should add method class_method 'new_method' to #<Class:0x000055b4d0a25c80>
    class AddClassMethod < Base
      include AddMethod

      private

      # @private
      #
      # Error description on wrong usage
      #
      # @return String
      def matcher_error
        'You should specify which class the method is being added to' \
          "add_class_method(:#{method_name}).to(klass)"
      end

      # @private
      #
      # Class of the real matcher
      #
      # @return [Class<Sinclair::Matchers::Base>]
      def add_method_to_class
        AddClassMethodTo
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
sinclair-1.9.0 lib/sinclair/matchers/add_class_method.rb
sinclair-1.8.0 lib/sinclair/matchers/add_class_method.rb
sinclair-1.7.0 lib/sinclair/matchers/add_class_method.rb
sinclair-1.6.7 lib/sinclair/matchers/add_class_method.rb