Class: Ward::Matchers::Include
- Defined in:
- lib/ward/matchers/include.rb
Overview
Tests whether the validation value is contained in the expected value.
The expected value can be anything which responds to include?
; if it returns true, the matcher will pass.
Instance Attribute Summary
Attributes inherited from Matcher
Instance Method Summary collapse
-
#customise_error_values(values) ⇒ String
Adds extra information to the error message.
-
#initialize(expected = nil) ⇒ Include
constructor
Creates a new Include matcher instance.
-
#matches?(actual) ⇒ Boolean
Returns whether the given value is included in the expected value.
Methods inherited from Matcher
Constructor Details
#initialize(expected = nil) ⇒ Include
Creates a new Include matcher instance.
23 24 25 26 27 28 29 |
# File 'lib/ward/matchers/include.rb', line 23 def initialize(expected = nil) raise ArgumentError, 'The Include matcher requires that a value which responds ' \ 'to #include? is supplied' unless expected.respond_to?(:include?) super end |
Instance Method Details
#customise_error_values(values) ⇒ String
Adds extra information to the error message.
47 48 49 50 |
# File 'lib/ward/matchers/include.rb', line 47 def customise_error_values(values) values[:expected] = Ward::Errors.format_exclusive_list(@expected) values end |
#matches?(actual) ⇒ Boolean
Returns whether the given value is included in the expected value.
38 39 40 |
# File 'lib/ward/matchers/include.rb', line 38 def matches?(actual) @expected.include?(actual) end |