Class: Ward::Matchers::Matcher Abstract
- Inherits:
-
Object
- Object
- Ward::Matchers::Matcher
- Defined in:
- lib/ward/matchers/matcher.rb
Overview
A base class used for creating custom matchers.
Direct Known Subclasses
Acceptance, CloseTo, EqualTo, Has, Include, Match, Nil, Predicate, Present, Satisfy
Instance Attribute Summary collapse
-
#expected ⇒ Object
readonly
Returns the expected value.
-
#extra_args ⇒ Array
readonly
Returns any extra arguments given to the matcher.
Class Method Summary collapse
-
.error_id ⇒ String
Determines the key to be used to find error messages in lang files.
Instance Method Summary collapse
-
#customise_error_values(values) ⇒ Hash{Symbol => String}
Allows matcher subclasses to change – or add values to – the hash whose values are interpolated with the error string.
-
#initialize(expected = nil, *extra_args) ⇒ Matcher
constructor
Creates a new matcher instance.
-
#matches?(actual) ⇒ Boolean
abstract
Returns whether the given value matches the expected value.
Constructor Details
#initialize(expected = nil, *extra_args) ⇒ Matcher
Creates a new matcher instance.
26 27 28 29 |
# File 'lib/ward/matchers/matcher.rb', line 26 def initialize(expected = nil, *extra_args) @expected = expected @extra_args = extra_args end |
Instance Attribute Details
#expected ⇒ Object (readonly)
Returns the expected value.
13 14 15 |
# File 'lib/ward/matchers/matcher.rb', line 13 def expected @expected end |
#extra_args ⇒ Array (readonly)
Returns any extra arguments given to the matcher.
19 20 21 |
# File 'lib/ward/matchers/matcher.rb', line 19 def extra_args @extra_args end |
Class Method Details
.error_id ⇒ String
Determines the key to be used to find error messages in lang files.
61 62 63 64 |
# File 'lib/ward/matchers/matcher.rb', line 61 def self.error_id @error_id ||= ActiveSupport::Inflector.underscore( ActiveSupport::Inflector.demodulize(to_s)) end |
Instance Method Details
#customise_error_values(values) ⇒ Hash{Symbol => String}
Allows matcher subclasses to change – or add values to – the hash whose values are interpolated with the error string.
53 54 55 |
# File 'lib/ward/matchers/matcher.rb', line 53 def customise_error_values(values) values end |
#matches?(actual) ⇒ Boolean
Returns whether the given value matches the expected value.
40 41 42 |
# File 'lib/ward/matchers/matcher.rb', line 40 def matches?(actual) true end |