Class: ConvenientService::RSpec::PrimitiveMatchers::Classes::BeDescendantOf

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

Overview

Instance Method Summary collapse

Constructor Details

#initialize(base_klass) ⇒ BeDescendantOf

Returns a new instance of BeDescendantOf.



18
19
20
# File 'lib/convenient_service/rspec/primitive_matchers/classes/be_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_descendant_of.rb', line 28

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

#failure_messageObject



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

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

#failure_message_when_negatedObject

NOTE: failure_message_when_negated is only called when matches? returns false. https://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_descendant_of.rb', line 44

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

#matches?(klass) ⇒ Boolean

Returns:

  • (Boolean)


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

def matches?(klass)
  @klass = klass

  Utils.to_bool(klass < base_klass)
end