Class: Barthes::Client::AceJson4
- Inherits:
-
Ace
show all
- Defined in:
- lib/barthes/client/ace_json4.rb
Constant Summary
Constants inherited
from Ace
Barthes::Client::Ace::OPTION_KEYS
Instance Method Summary
collapse
Methods inherited from Ace
#action
Methods inherited from HTTParty
#action, #set_proxy, #xpath
Constructor Details
#initialize(env) ⇒ AceJson4
Returns a new instance of AceJson4.
5
6
7
8
|
# File 'lib/barthes/client/ace_json4.rb', line 5
def initialize(env)
super(env)
@client = AceClient::Json4.new(@options)
end
|
Instance Method Details
#compare(response, expectation) ⇒ Object
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/barthes/client/ace_json4.rb', line 10
def compare(response, expectation)
result = nil
case expectation['type']
when 'response_code'
result = response.code == expectation['value']
{'result' => result, 'returned' => response.code, 'expected' => expectation['value']}
when 'jmespath_value'
text = jmespath(response, expectation['jmespath'])
if expectation['method'].nil? || expectation['method'] == 'eq'
result = (text == expectation['value'])
elsif expectation['method'] == 'regexp'
result = !(text.match Regexp.new(expectation['value'])).nil?
elsif expectation['method'] == 'ne'
result = (text != expectation['value'])
end
{'result' => result, 'returned' => text, 'expected' => expectation['value']}
when 'jmespath_size'
size = jmespath(response, expectation['jmespath']).size
if expectation['method'].nil? || expectation['method'] == 'eq'
result = (size == expectation['value'])
elsif expectation['method'] == 'gt'
result = (size > expectation['value'])
elsif expectation['method'] == 'gte'
result = (size >= expectation['value'])
elsif expectation['method'] == 'lt'
result = (size < expectation['value'])
elsif expectation['method'] == 'lte'
result = (size <= expectation['value'])
end
{'result' => result, 'returned' => size, 'expected' => expectation['value']}
else
{'result' => true}
end
end
|
45
46
47
|
# File 'lib/barthes/client/ace_json4.rb', line 45
def (config, response)
jmespath(response, config["jmespath"])
end
|
#jmespath(response, jmespath) ⇒ Object
49
50
51
|
# File 'lib/barthes/client/ace_json4.rb', line 49
def jmespath(response, jmespath)
JMESPath.search(jmespath, response.parsed_response)
end
|