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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/barthes/action.rb', line 17
def action(action)
begin
@env.update(action['env']) if action['env']
params = evaluate_params(action['params'])
if action['expectations']
if action['max_loop']
action['max_loop'].to_i.times do
sleep action['sleep'].to_i/1000 if action['sleep']
response = @client.action(params)
action['expectations'].each do |expectation|
result = @client.compare(response, evaluate_params(expectation))
expectation.update(result)
end
if action['expectations'].all? {|e| e['result'] == true }
break
end
end
end
end
sleep action['sleep'].to_i/1000 if action['sleep']
action['request'] = params
action['response'] = response = @client.action(params)
if action['expectations'] && !action['expectations'].empty?
action['expectations'].each do |expectation|
result = @client.compare(response, evaluate_params(expectation))
expectation.update(result)
end
if !action['expectations'].all? {|e| e['result'] == true }
action['status'] = 'failure'
else
action['status'] = 'success'
end
else
action['status'] = 'success'
end
if cache_config = action['cache']
value = @client.(evaluate_params(cache_config), response)
action['cache']['value'] = value
Barthes::Cache[cache_config['key']] = value
end
rescue StandardError => e
action['status'] = 'error'
action['error'] = {
'class' => e.class,
'message' => e.message,
'backtrace' => e.backtrace
}
end
action
end
|