Class: Ward::Matchers::Present
- Defined in:
- lib/ward/matchers/present.rb
Overview
TODO:
Once the predicate matcher is available, amend the class documentation to provide an example of how to call blank?
explicitly.
Tests whether the validation value is present.
A “present” value is one which:
* is a non-blank string, containing more than just whitespace
* responds to #empty? and returns false
* does not evaluate to false (i.e. not nil or false)
This is equivalent to ActiveSupport’s blank?
extension methods but note that blank?
is not actually used; if you define blank?
on a class which is provided to the matcher it will not be called.
Instance Attribute Summary
Attributes inherited from Matcher
Instance Method Summary collapse
-
#matches?(actual) ⇒ Boolean
Returns whether the given value is present.
Methods inherited from Matcher
#customise_error_values, error_id, #initialize
Constructor Details
This class inherits a constructor from Ward::Matchers::Matcher
Instance Method Details
#matches?(actual) ⇒ Boolean
Returns whether the given value is present.
44 45 46 47 48 49 50 51 52 |
# File 'lib/ward/matchers/present.rb', line 44 def matches?(actual) if actual.kind_of?(String) actual.match(/\S/) elsif actual.respond_to?(:empty?) not actual.empty? else actual end end |