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.



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

def initialize(base_klass)
  @base_klass = base_klass
end

Instance Method Details

#descriptionObject



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

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

#failure_messageObject



41
42
43
# File 'lib/convenient_service/rspec/primitive_matchers/classes/be_descendant_of.rb', line 41

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



49
50
51
# File 'lib/convenient_service/rspec/primitive_matchers/classes/be_descendant_of.rb', line 49

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

#matches?(klass) ⇒ Boolean

Returns:

  • (Boolean)


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

def matches?(klass)
  @klass = klass

  Utils.to_bool(klass < base_klass)
end