Class: ArgumentSpecification::Matchers::BaseMatcher
- Inherits:
-
Object
- Object
- ArgumentSpecification::Matchers::BaseMatcher
- Defined in:
- lib/argspec/matchers/base_matcher.rb
Direct Known Subclasses
All, Be, BeA, BeComparedTo, BeEmpty, BeFalsey, BeNil, BeOneOf, BeTruthy, BeWithinRange, CaseEqual, Cover, EndWith, Equal, Match, RespondTo, Satisfy, StartWith
Instance Attribute Summary collapse
-
#actual ⇒ Object
readonly
Returns the value of attribute actual.
-
#block ⇒ Object
readonly
Returns the value of attribute block.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
Class Method Summary collapse
-
.matcher_name(*names) ⇒ Object
Add matcher names.
Instance Method Summary collapse
-
#failure_message ⇒ Object
The failure message when using ‘should’.
-
#failure_message_when_negated ⇒ Object
The failure message when using ‘should not’.
-
#matches? ⇒ Boolean
Check if the actual object matches.
Instance Attribute Details
#actual ⇒ Object
Returns the value of attribute actual.
25 26 27 |
# File 'lib/argspec/matchers/base_matcher.rb', line 25 def actual @actual end |
#block ⇒ Object
Returns the value of attribute block.
25 26 27 |
# File 'lib/argspec/matchers/base_matcher.rb', line 25 def block @block end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
25 26 27 |
# File 'lib/argspec/matchers/base_matcher.rb', line 25 def end |
Class Method Details
.matcher_name(*names) ⇒ Object
Add matcher names
Arguments:
names: (Splat)
Example:
>> class TestMatcher < BaseMatcher
>> matcher_name :test_matcher
>> end
=> TestMatcher
16 17 18 19 20 21 22 |
# File 'lib/argspec/matchers/base_matcher.rb', line 16 def matcher_name(*names) names.each do |name| next unless name.is_a?(Symbol) DSL::Matchers.register(self, name) end end |
Instance Method Details
#failure_message ⇒ Object
The failure message when using ‘should’
Example:
>> matcher.
=> "'test' should be a 'Symbol'"
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/argspec/matchers/base_matcher.rb', line 33 def actual = prettify_args(@actual) matcher = prettify_matcher([:name]) if [:args].count > 0 args = prettify_args(*[:args]) "'#{actual}' should #{matcher} '#{args}'" else "'#{actual}' should #{matcher}" end end |
#failure_message_when_negated ⇒ Object
The failure message when using ‘should not’
Example:
>> matcher.
=> "':test' should not be a 'Symbol'"
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/argspec/matchers/base_matcher.rb', line 52 def actual = prettify_args(@actual) matcher = prettify_matcher([:name]) if [:args].count > 0 args = prettify_args(*[:args]) "'#{actual}' should not #{matcher} '#{args}'" else "'#{actual}' should not #{matcher}" end end |
#matches? ⇒ Boolean
Check if the actual object matches
You must override this method!
Example:
>> matcher.matches?
=> true
73 74 75 |
# File 'lib/argspec/matchers/base_matcher.rb', line 73 def matches? raise NotImplementedError, 'You must override the matches? method in your matcher.' end |