Class: Brine::Selecting::Selector
- Inherits:
-
Object
- Object
- Brine::Selecting::Selector
- Includes:
- ParameterTransforming, RSpec::Matchers
- Defined in:
- lib/brine/selecting.rb
Overview
Allow selection of one or more values. This Selector will test whether the targeted value itself satisfies the assertion.
RSpec is used within this implementation to perform assertions. The Selector ultimately perform this assertion by accepting an RSpec matcher which it applied against the targeted value.
Direct Known Subclasses
Constant Summary
Constants included from ParameterTransforming
ParameterTransforming::DATE, ParameterTransforming::MILLIS, ParameterTransforming::TIME, ParameterTransforming::TZ
Instance Attribute Summary collapse
-
#coercer ⇒ Object
- Coercer
-
Expose the Coercer that may modify values prior to performing assertions.
Instance Method Summary collapse
-
#assert_that(value, binding, negated = nil) ⇒ Object
Perform the provided assertion against the instance target.
-
#filter_matcher(matcher) ⇒ RSpec::Matcher
Optionally perform some modification to the RSpec matcher prior to assertion.
-
#initialize(target, negated = false) ⇒ Selector
constructor
Construct a selector to perform assertions against a provided target.
Methods included from ParameterTransforming
#expand, #parameter_transformers, #transformed_parameter
Constructor Details
permalink #initialize(target, negated = false) ⇒ Selector
Construct a selector to perform assertions against a provided target.
42 43 44 45 |
# File 'lib/brine/selecting.rb', line 42 def initialize(target, negated=false) @target = target @negated = negated end |
Instance Attribute Details
permalink #coercer ⇒ Object
- Coercer
-
Expose the Coercer that may modify values prior to performing assertions.
33 34 35 |
# File 'lib/brine/selecting.rb', line 33 def coercer @coercer end |
Instance Method Details
permalink #assert_that(value, binding, negated = nil) ⇒ Object
Perform the provided assertion against the instance target.
The values will be coerced prior to evaluation.
73 74 75 76 77 78 79 80 |
# File 'lib/brine/selecting.rb', line 73 def assert_that(value, binding, negated=nil) # shim while moving negation to assertions. negated = @negated if negated.nil? target, value = coercer.coerce((@target, binding), (value, binding)) = negated ? :to_not : :to matcher = filter_matcher(yield(value)) expect(target).send(, matcher) end |
permalink #filter_matcher(matcher) ⇒ RSpec::Matcher
Optionally perform some modification to the RSpec matcher prior to assertion.
This is designed to allow subclassess to be able to modify the way in which matchers are applied against the values. The default implementation is a passthrough.
57 58 59 |
# File 'lib/brine/selecting.rb', line 57 def filter_matcher(matcher) matcher end |