Class: Brine::Selecting::Selector
- Inherits:
-
Object
- Object
- Brine::Selecting::Selector
- Includes:
- RSpec::Matchers
- Defined in:
- lib/brine/selecting.rb
Overview
An object responsible for selecting 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
Instance Attribute Summary collapse
-
#coercer ⇒ Object
- Coercer
-
The Coercer that may modify values prior to performing assertions.
Instance Method Summary collapse
-
#assert_that(value, 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.
Constructor Details
#initialize(target, negated = false) ⇒ Selector
Construct a selector to perform assertions against a provided target.
40 41 42 43 |
# File 'lib/brine/selecting.rb', line 40 def initialize(target, negated=false) @target = target @negated = negated end |
Instance Attribute Details
#coercer ⇒ Object
- Coercer
-
The Coercer that may modify values prior to performing assertions.
31 32 33 |
# File 'lib/brine/selecting.rb', line 31 def coercer @coercer end |
Instance Method Details
#assert_that(value, negated = nil) ⇒ Object
Perform the provided assertion against the instance target.
The values will be coerced prior to evaluation.
69 70 71 72 73 74 75 76 |
# File 'lib/brine/selecting.rb', line 69 def assert_that(value, negated=nil) # shim while moving negation to assertions. negated = @negated if negated.nil? target, value = coercer.coerce(@target, value) = negated ? :to_not : :to matcher = filter_matcher(yield(value)) expect(target).send(, matcher) end |
#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. This method is a pass-through in this class.
54 55 56 |
# File 'lib/brine/selecting.rb', line 54 def filter_matcher(matcher) matcher end |