Class: ConvenientService::RSpec::PrimitiveMatchers::Classes::HaveAbstractMethod

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

Instance Method Summary collapse

Constructor Details

#initialize(method_name) ⇒ HaveAbstractMethod

Returns a new instance of HaveAbstractMethod.



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

def initialize(method_name)
  @method_name = method_name
end

Instance Method Details

#descriptionObject



26
27
28
# File 'lib/convenient_service/rspec/primitive_matchers/classes/have_abstract_method.rb', line 26

def description
  "have abstract method `#{method_name}`"
end

#failure_messageObject



30
31
32
# File 'lib/convenient_service/rspec/primitive_matchers/classes/have_abstract_method.rb', line 30

def failure_message
  "expected `#{object.class}` to have abstract method `#{method_name}`"
end

#failure_message_when_negatedObject



34
35
36
# File 'lib/convenient_service/rspec/primitive_matchers/classes/have_abstract_method.rb', line 34

def failure_message_when_negated
  "expected `#{object.class}` NOT to have abstract method `#{method_name}`"
end

#matches?(object) ⇒ Boolean

Returns:

  • (Boolean)


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

def matches?(object)
  @object = object

  begin
    object.__send__(method_name)

    false
  rescue ConvenientService::Support::AbstractMethod::Exceptions::AbstractMethodNotOverridden
    true
  rescue
    false
  end
end