Class: Selector

Inherits:
Object
  • Object
show all
Includes:
RSpec::Matchers
Defined in:
lib/brine/selector.rb

Overview

Selectors here are small wrappers around RSpec expectation behavior to encapsulate variations in some expecation associated behavior in classes.

Direct Known Subclasses

AllSelector, AnySelector

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target, negated) ⇒ Selector

Returns a new instance of Selector.



12
13
14
15
# File 'lib/brine/selector.rb', line 12

def initialize(target, negated)
  @target = target
  @message = negated ? :to_not : :to
end

Instance Attribute Details

#coercerObject

Returns the value of attribute coercer.



10
11
12
# File 'lib/brine/selector.rb', line 10

def coercer
  @coercer
end

Instance Method Details

#assert_that(value) ⇒ Object



21
22
23
24
25
# File 'lib/brine/selector.rb', line 21

def assert_that(value)
  target, value = coercer.coerce(@target, value)
  matcher = filter_matcher(yield(value))
  expect(target).send(@message, matcher)
end

#filter_matcher(matcher) ⇒ Object



17
18
19
# File 'lib/brine/selector.rb', line 17

def filter_matcher(matcher)
  matcher
end