Class: ConvenientService::RSpec::PrimitiveMatchers::Classes::BeDirectDescendantOf

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

Overview

Instance Method Summary collapse

Constructor Details

#initialize(base_klass) ⇒ BeDirectDescendantOf

Returns a new instance of BeDirectDescendantOf.



18
19
20
# File 'lib/convenient_service/rspec/primitive_matchers/classes/be_direct_descendant_of.rb', line 18

def initialize(base_klass)
  @base_klass = base_klass
end

Instance Method Details

#descriptionObject



28
29
30
# File 'lib/convenient_service/rspec/primitive_matchers/classes/be_direct_descendant_of.rb', line 28

def description
  "be a direct descendant of `#{base_klass}`"
end

#failure_messageObject

NOTE: ‘failure_message` is only called when `matches?` returns `false`. rubydoc.info/github/rspec/rspec-expectations/RSpec/Matchers/MatcherProtocol#failure_message-instance_method



36
37
38
# File 'lib/convenient_service/rspec/primitive_matchers/classes/be_direct_descendant_of.rb', line 36

def failure_message
  "expected #{klass} to be a direct descendant of `#{base_klass}`"
end

#failure_message_when_negatedObject

NOTE: ‘failure_message_when_negated` is only called when `matches?` returns `false`. rubydoc.info/github/rspec/rspec-expectations/RSpec/Matchers/MatcherProtocol#failure_message-instance_method



44
45
46
# File 'lib/convenient_service/rspec/primitive_matchers/classes/be_direct_descendant_of.rb', line 44

def failure_message_when_negated
  "expected #{klass} NOT to be a direct descendant of `#{base_klass}`"
end

#matches?(klass) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
25
26
# File 'lib/convenient_service/rspec/primitive_matchers/classes/be_direct_descendant_of.rb', line 22

def matches?(klass)
  @klass = klass

  klass.superclass == base_klass
end