Class: Endo::ExpectationTarget

Inherits:
Object
  • Object
show all
Defined in:
lib/endo/expectation_target.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target, query) ⇒ ExpectationTarget

Returns a new instance of ExpectationTarget.



5
6
7
8
# File 'lib/endo/expectation_target.rb', line 5

def initialize(target, query)
  @target = target
  @query = query
end

Instance Attribute Details

#actualObject (readonly)

Returns the value of attribute actual.



3
4
5
# File 'lib/endo/expectation_target.rb', line 3

def actual
  @actual
end

Instance Method Details

#expectedObject



29
30
31
# File 'lib/endo/expectation_target.rb', line 29

def expected
  @matcher.expected
end

#matches?(res) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/endo/expectation_target.rb', line 14

def matches?(res)
  case @target
  when :header
    @actual = res.header[@query]
  when :body
    obj = JSON.parse res.body
    @actual = if @query.is_a? Proc
                obj.instance_exec(&@query)
              else
                obj[@query]
              end
  end
  @matcher.matches?(@actual)
end

#to(matcher) ⇒ Object



10
11
12
# File 'lib/endo/expectation_target.rb', line 10

def to(matcher)
  @matcher = matcher
end