Class: ArgumentSpecification::Matchers::All
- Inherits:
-
BaseMatcher
- Object
- BaseMatcher
- ArgumentSpecification::Matchers::All
- Defined in:
- lib/argspec/matchers/all.rb
Instance Attribute Summary collapse
-
#expected ⇒ Object
readonly
Returns the value of attribute expected.
Attributes inherited from BaseMatcher
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’.
-
#initialize(expected) ⇒ All
constructor
Create a new matcher instance.
-
#matches? ⇒ Boolean
Check if the actual object matches.
Methods inherited from BaseMatcher
Constructor Details
#initialize(expected) ⇒ All
Create a new matcher instance
Arguments:
expected: (BaseMatcher)
Example:
>> symbol_matcher = ArgumentSpecification::Matchers::BeA.new(Symbol)
>> ArgumentSpecification::Matchers::All.new(symbol_matcher)
=> #<ArgumentSpecification::Matchers::All:0x00000000000000 @expected=#<ArgumentSpecification::Matchers::BeA:0x00000000000000 @expected=Symbol>>
18 19 20 21 22 23 24 |
# File 'lib/argspec/matchers/all.rb', line 18 def initialize(expected) if expected.is_a?(BaseMatcher) == false || expected.is_a?(All) raise ArgumentError, 'You must provide a matcher as an argument (excluding the all matcher).' end @expected = expected end |
Instance Attribute Details
#expected ⇒ Object (readonly)
Returns the value of attribute expected.
6 7 8 |
# File 'lib/argspec/matchers/all.rb', line 6 def expected @expected end |
Instance Method Details
#failure_message ⇒ Object
The failure message when using ‘should’
Example:
>> matcher.
=> "'test' should be a 'Symbol'"
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/argspec/matchers/all.rb', line 32 def actual = prettify_args(@actual) matcher = prettify_matcher(@expected.[:name]) if @expected.[:args].count > 0 args = prettify_args(*@expected.[:args]) "'#{actual}' should all #{matcher} '#{args}'" else "'#{actual}' should all #{matcher}" end end |
#failure_message_when_negated ⇒ Object
The failure message when using ‘should not’
Example:
>> matcher.
=> "':test' should not be a 'Symbol'"
51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/argspec/matchers/all.rb', line 51 def actual = prettify_args(@actual) matcher = prettify_matcher(@expected.[:name]) if @expected.[:args].count > 0 args = prettify_args(*@expected.[:args]) "'#{actual}' should not all #{matcher} '#{args}'" else "'#{actual}' should not all #{matcher}" end end |
#matches? ⇒ Boolean
Check if the actual object matches
Example:
>> matcher.matches?
=> true
70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/argspec/matchers/all.rb', line 70 def matches? actual = @actual.is_a?(Array) ? @actual : [@actual] actual.each do |value| @expected.send(:actual=, value) @expected.send(:block=, @block) if @block return false unless @expected.matches? end true end |