Sha256: be88289331e75ebe7e3a414b1bf4167d77dd0cd7be2f844eeddb9e02ff8849c3

Contents?: true

Size: 1.81 KB

Versions: 6

Compression:

Stored size: 1.81 KB

Contents

# frozen_string_literal: true

module ConvenientService
  module RSpec
    module PrimitiveMatchers
      module Classes
        ##
        # @internal
        #   class User
        #     include InstanceMethods
        #
        #     singleton_class.include ClassMethods # or more common `extend ClassMethods`.
        #
        #     prepend InstanceMethods
        #
        #     singleton_class.prepend ClassMethods # no short form like `extend`.
        #   end
        #
        class SingletonPrependModule
          ##
          # @param mod [Module]
          # @return [void]
          #
          # @internal
          #   NOTE: `mod` since `module` is a keyword.
          #
          def initialize(mod)
            @mod = mod
          end

          ##
          # @param klass [Class, Module]
          # @return [Boolean]
          #
          def matches?(klass)
            @klass = klass

            klass.singleton_class.ancestors.take_while { |ancestor| ancestor != klass }.include?(mod)
          end

          ##
          # @return [String]
          #
          def description
            "`singleton_class.prepend` module `#{mod}`"
          end

          ##
          # @return [String]
          #
          def failure_message
            "expected `#{klass}` to `singleton_class.prepend` module `#{mod}`"
          end

          ##
          # @return [String]
          #
          def failure_message_when_negated
            "expected `#{klass}` NOT to `singleton_class.prepend` module `#{mod}`"
          end

          private

          ##
          # @!attribute [r] klass
          #   @return [Class, Module]
          #
          attr_reader :klass

          ##
          # @!attribute [r] mod
          #   @return [Module]
          #
          attr_reader :mod
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
convenient_service-0.19.1 lib/convenient_service/rspec/primitive_matchers/classes/singleton_prepend_module.rb
convenient_service-0.19.0 lib/convenient_service/rspec/primitive_matchers/classes/singleton_prepend_module.rb
convenient_service-0.18.0 lib/convenient_service/rspec/primitive_matchers/classes/singleton_prepend_module.rb
convenient_service-0.17.0 lib/convenient_service/rspec/primitive_matchers/classes/singleton_prepend_module.rb
convenient_service-0.16.0 lib/convenient_service/rspec/primitive_matchers/classes/singleton_prepend_module.rb
convenient_service-0.15.0 lib/convenient_service/rspec/primitive_matchers/classes/singleton_prepend_module.rb