Class: Ward::Matchers::Satisfy
- Defined in:
- lib/ward/matchers/satisfy.rb
Overview
Tests whether the validation value satisfies the given block.
If the block returns any value other than false, the matcher will assume that the match passed.
Alternatively, you may pass a Symbol which identifies a method name; the method will be run with it’s return value used to determine if the matcher passed.
Adding an explict error message is advised, since the message generated by Ward isn’t very helpful: “… is invalid”.
Instance Attribute Summary
Attributes inherited from Matcher
Instance Method Summary collapse
-
#initialize(expected = nil, *extra_args, &block) ⇒ Satisfy
constructor
Creates a new matcher instance.
-
#matches?(actual, record = nil) ⇒ Boolean
Returns whether the given value is satisfied by the expected block.
Methods inherited from Matcher
#customise_error_values, error_id
Constructor Details
#initialize(expected = nil, *extra_args, &block) ⇒ Satisfy
Creates a new matcher instance.
42 43 44 |
# File 'lib/ward/matchers/satisfy.rb', line 42 def initialize(expected = nil, *extra_args, &block) super(block, *extra_args) end |
Instance Method Details
#matches?(actual, record = nil) ⇒ Boolean
Returns whether the given value is satisfied by the expected block.
55 56 57 58 59 60 61 |
# File 'lib/ward/matchers/satisfy.rb', line 55 def matches?(actual, record = nil) if @expected.arity != 1 @expected.call(actual, record) else @expected.call(actual) end end |