Module: Matchi::MatchersBase
- Included in:
- Matchi::Matchers::BeFalse::Matcher, Matchi::Matchers::BeNil::Matcher, Matchi::Matchers::BeTrue::Matcher, Matchi::Matchers::Eql::Matcher, Matchi::Matchers::Equal::Matcher, Matchi::Matchers::Match::Matcher, Matchi::Matchers::RaiseException::Matcher
- Defined in:
- lib/matchi/matchers_base.rb
Overview
Common matcher methods.
Instance Method Summary collapse
-
#matches? ⇒ Boolean
Abstract matcher class.
-
#to_h ⇒ Hash
Returns a hash of one key-value pair with a key corresponding to the matcher and a value corresponding to its initialize parameters.
-
#to_s ⇒ String
Returns a string representing the matcher.
Instance Method Details
#matches? ⇒ Boolean
Abstract matcher class.
9 10 11 |
# File 'lib/matchi/matchers_base.rb', line 9 def matches? raise NotImplementedError, 'The matcher MUST respond to matches? method.' end |
#to_h ⇒ Hash
Returns a hash of one key-value pair with a key corresponding to the
matcher and a value corresponding to its initialize parameters.
37 38 39 |
# File 'lib/matchi/matchers_base.rb', line 37 def to_h { matcher_name.to_sym => (defined?(@expected) ? Array(@expected) : []) } end |
#to_s ⇒ String
Returns a string representing the matcher.
20 21 22 23 24 25 26 27 |
# File 'lib/matchi/matchers_base.rb', line 20 def to_s s = matcher_name .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') .gsub(/([a-z\d])([A-Z])/, '\1_\2') .downcase defined?(@expected) ? [s, @expected.inspect].join(' ') : s end |