barthes 0.0.11 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
@@ -13,42 +13,56 @@ module Barthes
13
13
  end
14
14
 
15
15
  def action(action)
16
- @env.update(action['env']) if action['env']
17
- params = evaluate_params(action['params'])
16
+ begin
17
+ @env.update(action['env']) if action['env']
18
+ params = evaluate_params(action['params'])
18
19
 
19
- if action['expectations']
20
- if action['max_loop']
21
- action['max_loop'].to_i.times do
22
- sleep action['sleep'].to_i/1000 if action['sleep']
20
+ if action['expectations']
21
+ if action['max_loop']
22
+ action['max_loop'].to_i.times do
23
+ sleep action['sleep'].to_i/1000 if action['sleep']
23
24
 
24
- response = @client.action(params)
25
- action['expectations'].each do |expectation|
26
- result = @client.compare(response, evaluate_params(expectation))
27
- expectation.update(result)
28
- end
29
- if action['expectations'].all? {|e| e['result'] == true }
30
- break
25
+ response = @client.action(params)
26
+ action['expectations'].each do |expectation|
27
+ result = @client.compare(response, evaluate_params(expectation))
28
+ expectation.update(result)
29
+ end
30
+ if action['expectations'].all? {|e| e['result'] == true }
31
+ break
32
+ end
31
33
  end
32
34
  end
33
35
  end
34
- end
35
36
 
36
- sleep action['sleep'].to_i/1000 if action['sleep']
37
+ sleep action['sleep'].to_i/1000 if action['sleep']
37
38
 
38
- action['request'] = params
39
- action['response'] = response = @client.action(params)
39
+ action['request'] = params
40
+ action['response'] = response = @client.action(params)
40
41
 
41
- if action['expectations']
42
- action['expectations'].each do |expectation|
43
- result = @client.compare(response, evaluate_params(expectation))
44
- expectation.update(result)
42
+ if action['expectations']
43
+ action['expectations'].each do |expectation|
44
+ result = @client.compare(response, evaluate_params(expectation))
45
+ expectation.update(result)
46
+ end
47
+ if action['expectations'].all? {|e| e['result'] == true }
48
+ action['status'] = 'failure'
49
+ end
50
+ else
51
+ action['status'] = 'success'
45
52
  end
46
- end
47
53
 
48
- if cache_config = action['cache']
49
- value = @client.extract(cache_config, response)
50
- action['cache']['value'] = value
51
- Barthes::Cache[cache_config['key']] = value
54
+ if cache_config = action['cache']
55
+ value = @client.extract(cache_config, response)
56
+ action['cache']['value'] = value
57
+ Barthes::Cache[cache_config['key']] = value
58
+ end
59
+ rescue StandardError => e
60
+ action['status'] = 'error'
61
+ action['error'] = {
62
+ 'class' => e.class,
63
+ 'message' => e.message,
64
+ 'backtrace' => e.backtrace
65
+ }
52
66
  end
53
67
  action
54
68
  end
@@ -57,7 +57,20 @@ module Barthes
57
57
  when 'skipped'
58
58
  @xml.skipped
59
59
  when 'failure'
60
+ failure = "failed expectations: \n"
61
+ expectations = action['expectations'] || []
62
+ expectations.each do |expectation|
63
+ if expectation['result'] == false
64
+ failure += JSON.pretty_generate(expectation) + "\n"
65
+ end
66
+ end
67
+ @xml.failure failure
60
68
  when 'error'
69
+ error = "error:\n"
70
+ error += "class: #{json.last['error']['class']}\n"
71
+ error += "message: #{json.last['error']['message']}\n"
72
+ error += "backtrace: #{json.last['error']['backtrace'].join("\n")}\n"
73
+ @xml.error error
61
74
  end
62
75
  if json.last['status'] != 'skipped' && json.last['request'] && json.last['response']
63
76
  stdout = "request:\n"
@@ -111,9 +111,7 @@ module Barthes
111
111
  content['number'] = @num
112
112
  if Barthes::Config[:dryrun] == 0 && !@failed
113
113
  content = Action.new(env).action(content)
114
- if content['expectations'] && content['expectations'].any? {|e| e['result'] == false }
115
- @failed = true
116
- end
114
+ @failed = true if %w(failure error).include?(content['status'])
117
115
  end
118
116
  content['status'] = 'skipped' if Barthes::Config[:dryrun] > 0
119
117
  content
@@ -1,3 +1,3 @@
1
1
  module Barthes
2
- VERSION = "0.0.11"
2
+ VERSION = "0.0.12"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: barthes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.11
4
+ version: 0.0.12
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: