Class: Minicrest::DescendsFrom
- Defined in:
- lib/minicrest/value_matchers.rb
Overview
Matcher that checks if a value is an instance of a given type.
Uses Ruby’s is_a? method which checks class hierarchy and module inclusion.
Instance Method Summary collapse
-
#description ⇒ String
Returns a description of what this matcher expects.
-
#failure_message(actual) ⇒ String
Returns the failure message when the match fails.
-
#initialize(expected_type) ⇒ DescendsFrom
constructor
Creates a new type matcher.
-
#matches?(actual) ⇒ Boolean
Checks if actual is an instance of the expected type.
-
#negated_failure_message(actual) ⇒ String
Returns the failure message when a negated match fails.
Methods inherited from Matcher
Constructor Details
#initialize(expected_type) ⇒ DescendsFrom
Creates a new type matcher.
103 104 105 106 |
# File 'lib/minicrest/value_matchers.rb', line 103 def initialize(expected_type) super() @expected_type = expected_type end |
Instance Method Details
#description ⇒ String
Returns a description of what this matcher expects.
119 120 121 |
# File 'lib/minicrest/value_matchers.rb', line 119 def description "an instance of #{@expected_type}" end |
#failure_message(actual) ⇒ String
Returns the failure message when the match fails.
127 128 129 130 131 132 133 |
# File 'lib/minicrest/value_matchers.rb', line 127 def (actual) <<~MSG.chomp expected #{actual.inspect} to be an instance of #{@expected_type} but was #{actual.class} MSG end |
#matches?(actual) ⇒ Boolean
Checks if actual is an instance of the expected type.
112 113 114 |
# File 'lib/minicrest/value_matchers.rb', line 112 def matches?(actual) actual.is_a?(@expected_type) end |
#negated_failure_message(actual) ⇒ String
Returns the failure message when a negated match fails.
139 140 141 142 143 144 145 |
# File 'lib/minicrest/value_matchers.rb', line 139 def (actual) <<~MSG.chomp expected #{actual.inspect} not to be an instance of #{@expected_type} but it is MSG end |