Sha256: 057af5dd839149793611ac611fc32beaefe316a14da69d33f952b8aff7a896fd
Contents?: true
Size: 1.81 KB
Versions: 2
Compression:
Stored size: 1.81 KB
Contents
# frozen_string_literal: true module ConvenientService module RSpec module Matchers module Custom ## # 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: # - https://relishapp.com/rspec/rspec-expectations/v/3-11/docs/custom-matchers/define-a-custom-matcher # - http://rspec.info/documentation/3.9/rspec-expectations/RSpec/Matchers/MatcherProtocol.html # - https://makandracards.com/makandra/662-write-custom-rspec-matchers # class BeDescendantOf def initialize(base_klass) @base_klass = base_klass end def matches?(klass) @klass = klass Utils.to_bool(klass < base_klass) end def description "be a descendant of `#{base_klass}`" end ## # NOTE: `failure_message` is only called when `matches?` returns `false`. # https://rubydoc.info/github/rspec/rspec-expectations/RSpec/Matchers/MatcherProtocol#failure_message-instance_method # def failure_message "expected #{klass} to be a descendant of `#{base_klass}`" end ## # 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 # def failure_message_when_negated "expected #{klass} NOT to be a descendant of `#{base_klass}`" end private attr_reader :klass, :base_klass end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
convenient_service-0.14.0 | lib/convenient_service/rspec/matchers/custom/be_descendant_of.rb |
convenient_service-0.13.0 | lib/convenient_service/rspec/matchers/custom/be_descendant_of.rb |