Class: Endo::ExpectationTarget
- Inherits:
-
Object
- Object
- Endo::ExpectationTarget
- Defined in:
- lib/endo/expectation_target.rb
Instance Attribute Summary collapse
-
#actual ⇒ Object
readonly
Returns the value of attribute actual.
Instance Method Summary collapse
- #expected ⇒ Object
-
#initialize(target, query) ⇒ ExpectationTarget
constructor
A new instance of ExpectationTarget.
- #matches?(res) ⇒ Boolean
- #to(matcher) ⇒ Object
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
#actual ⇒ Object (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
#expected ⇒ Object
29 30 31 |
# File 'lib/endo/expectation_target.rb', line 29 def expected @matcher.expected end |
#matches?(res) ⇒ 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 |