Class: Minicrest::MatchesPattern
- Defined in:
- lib/minicrest/matches_pattern.rb
Overview
Matcher that checks if a string matches a regular expression.
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(pattern) ⇒ MatchesPattern
constructor
Creates a new pattern matcher.
-
#matches?(actual) ⇒ Boolean
Checks if actual matches the expected pattern.
-
#negated_failure_message(actual) ⇒ String
Returns the failure message when a negated match fails.
Methods inherited from Matcher
Constructor Details
#initialize(pattern) ⇒ MatchesPattern
Creates a new pattern matcher.
13 14 15 16 |
# File 'lib/minicrest/matches_pattern.rb', line 13 def initialize(pattern) super() @pattern = pattern end |
Instance Method Details
#description ⇒ String
Returns a description of what this matcher expects.
33 34 35 |
# File 'lib/minicrest/matches_pattern.rb', line 33 def description "a string matching #{@pattern.inspect}" end |
#failure_message(actual) ⇒ String
Returns the failure message when the match fails.
41 42 43 44 45 46 |
# File 'lib/minicrest/matches_pattern.rb', line 41 def (actual) <<~MSG.chomp expected #{actual.inspect} to match pattern #{@pattern.inspect} MSG end |
#matches?(actual) ⇒ Boolean
Checks if actual matches the expected pattern.
22 23 24 25 26 27 28 |
# File 'lib/minicrest/matches_pattern.rb', line 22 def matches?(actual) return false unless actual.respond_to?(:to_str) @pattern.match?(actual) rescue TypeError false end |
#negated_failure_message(actual) ⇒ String
Returns the failure message when a negated match fails.
52 53 54 55 56 57 58 |
# File 'lib/minicrest/matches_pattern.rb', line 52 def (actual) <<~MSG.chomp expected #{actual.inspect} not to match pattern #{@pattern.inspect} but it does MSG end |