Sha256: a7640225b665c0faa93e7644276be50f94b45ef88228301ac9f31f419dae7024

Contents?: true

Size: 1.39 KB

Versions: 6

Compression:

Stored size: 1.39 KB

Contents

# frozen_string_literal: true

module ConvenientService
  module RSpec
    module PrimitiveMatchers
      module Classes
        class HaveAliasMethod
          def initialize(alias_name, original_name)
            @alias_name = alias_name
            @original_name = original_name
          end

          def matches?(object)
            @object = object

            ##
            # TODO: Use `Utils::Object.duck_class` to support `have_alias_method` for classes.
            #
            return false unless Utils::Method.defined?(original_name, object.class, private: true)

            return false unless Utils::Method.defined?(alias_name, object.class, private: true)

            ##
            # https://stackoverflow.com/a/45640516/12201472
            #
            object.method(alias_name).original_name == object.method(original_name).original_name
          end

          def description
            "have alias method `#{alias_name}` for `#{original_name}`"
          end

          def failure_message
            "expected `#{object.class}` to have alias method `#{alias_name}` for `#{original_name}`"
          end

          def failure_message_when_negated
            "expected `#{object.class}` NOT to have alias method `#{alias_name}` for `#{original_name}`"
          end

          private

          attr_reader :object, :alias_name, :original_name
        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/have_alias_method.rb
convenient_service-0.19.0 lib/convenient_service/rspec/primitive_matchers/classes/have_alias_method.rb
convenient_service-0.18.0 lib/convenient_service/rspec/primitive_matchers/classes/have_alias_method.rb
convenient_service-0.17.0 lib/convenient_service/rspec/primitive_matchers/classes/have_alias_method.rb
convenient_service-0.16.0 lib/convenient_service/rspec/primitive_matchers/classes/have_alias_method.rb
convenient_service-0.15.0 lib/convenient_service/rspec/primitive_matchers/classes/have_alias_method.rb