Class: ConvenientService::RSpec::PrimitiveMatchers::Classes::HaveAliasMethod

Inherits:
Object
  • Object
show all
Defined in:
lib/convenient_service/rspec/primitive_matchers/classes/have_alias_method.rb

Instance Method Summary collapse

Constructor Details

#initialize(alias_name, original_name) ⇒ HaveAliasMethod

Returns a new instance of HaveAliasMethod.



8
9
10
11
# File 'lib/convenient_service/rspec/primitive_matchers/classes/have_alias_method.rb', line 8

def initialize(alias_name, original_name)
  @alias_name = alias_name
  @original_name = original_name
end

Instance Method Details

#descriptionObject



29
30
31
# File 'lib/convenient_service/rspec/primitive_matchers/classes/have_alias_method.rb', line 29

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

#failure_messageObject



33
34
35
# File 'lib/convenient_service/rspec/primitive_matchers/classes/have_alias_method.rb', line 33

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

#failure_message_when_negatedObject



37
38
39
# File 'lib/convenient_service/rspec/primitive_matchers/classes/have_alias_method.rb', line 37

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

#matches?(object) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/convenient_service/rspec/primitive_matchers/classes/have_alias_method.rb', line 13

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