Class: ConvenientService::RSpec::PrimitiveMatchers::Classes::BeDirectDescendantOf
- Inherits:
-
Object
- Object
- ConvenientService::RSpec::PrimitiveMatchers::Classes::BeDirectDescendantOf
- Defined in:
- lib/convenient_service/rspec/primitive_matchers/classes/be_direct_descendant_of.rb
Overview
NOTE: Navigate to the link below and Ctrl + F
for "Custom Matcher from scratch"
for a guide of how to define a complex custom matcher.
https://rubydoc.info/github/rspec/rspec-expectations/RSpec/Matchers
More info:
Instance Method Summary collapse
- #description ⇒ Object
-
#failure_message ⇒ Object
NOTE:
failure_message
is only called whenmatches?
returnsfalse
. -
#failure_message_when_negated ⇒ Object
NOTE:
failure_message_when_negated
is only called whenmatches?
returnsfalse
. -
#initialize(base_klass) ⇒ BeDirectDescendantOf
constructor
A new instance of BeDirectDescendantOf.
- #matches?(klass) ⇒ Boolean
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
#description ⇒ Object
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_message ⇒ Object
NOTE: failure_message
is only called when matches?
returns false
.
https://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 "expected #{klass} to be a direct descendant of `#{base_klass}`" end |
#failure_message_when_negated ⇒ Object
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_direct_descendant_of.rb', line 44 def "expected #{klass} NOT to be a direct descendant of `#{base_klass}`" end |
#matches?(klass) ⇒ 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 |