Class: Minicrest::StringMatcher Private
- Defined in:
- lib/minicrest/string_matcher.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Base class for matchers that check string properties.
Direct Known Subclasses
Instance Method Summary collapse
-
#description ⇒ String
private
Returns a description of what this matcher expects.
-
#failure_message(actual) ⇒ String
private
Returns the failure message when the match fails.
-
#initialize(substring, method, label) ⇒ StringMatcher
constructor
private
Creates a new string matcher.
-
#matches?(actual) ⇒ Boolean
private
Checks if actual matches the condition.
-
#negated_failure_message(actual) ⇒ String
private
Returns the failure message when a negated match fails.
Methods inherited from Matcher
Constructor Details
#initialize(substring, method, label) ⇒ StringMatcher
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Creates a new string matcher.
15 16 17 18 19 20 |
# File 'lib/minicrest/string_matcher.rb', line 15 def initialize(substring, method, label) super() @substring = substring @method = method @label = label end |
Instance Method Details
#description ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a description of what this matcher expects.
37 38 39 |
# File 'lib/minicrest/string_matcher.rb', line 37 def description "a string #{@label} #{@substring.inspect}" end |
#failure_message(actual) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the failure message when the match fails.
45 46 47 48 49 50 |
# File 'lib/minicrest/string_matcher.rb', line 45 def (actual) <<~MSG.chomp expected #{actual.inspect} to #{@label} #{@substring.inspect} MSG end |
#matches?(actual) ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Checks if actual matches the condition.
26 27 28 29 30 31 32 |
# File 'lib/minicrest/string_matcher.rb', line 26 def matches?(actual) return false unless actual.respond_to?(@method) actual.public_send(@method, @substring) rescue ArgumentError, NoMethodError false end |
#negated_failure_message(actual) ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the failure message when a negated match fails.
56 57 58 59 60 61 62 |
# File 'lib/minicrest/string_matcher.rb', line 56 def (actual) <<~MSG.chomp expected #{actual.inspect} not to #{@label} #{@substring.inspect} but it does MSG end |