spectre-core 1.12.0 → 1.12.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,100 +1,102 @@
1
- # https://llg.cubic.org/docs/junit/
2
- # Azure mappings: https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/test/publish-test-results?view=azure-devops&tabs=junit%2Cyaml
3
-
4
- module Spectre::Reporter
5
- class JUnit
6
- def initialize config
7
- @config = config
8
- end
9
-
10
- def report run_infos
11
- now = Time.now.getutc
12
- timestamp = now.strftime('%s')
13
- datetime = now.strftime('%FT%T%:z')
14
-
15
- xml_str = '<?xml version="1.0" encoding="UTF-8" ?>'
16
- xml_str += '<testsuites>'
17
-
18
- suite_id = 0
19
-
20
- run_infos.group_by { |x| x.spec.subject }.each do |subject, run_infos|
21
- failures = run_infos.select { |x| x.failure != nil }
22
- errors = run_infos.select { |x| x.error != nil }
23
- skipped = run_infos.select { |x| x.skipped? }
24
-
25
- xml_str += '<testsuite package="' + subject.desc + '" id="' + suite_id.to_s + '" name="' + subject.desc + '" timestamp="' + datetime + '" tests="' + run_infos.count.to_s + '" failures="' + failures.count.to_s + '" errors="' + errors.count.to_s + '" skipped="' + skipped.count.to_s + '">'
26
- suite_id += 1
27
-
28
- run_infos.each do |run_info|
29
- xml_str += '<testcase classname="' + run_info.spec.file.to_s + '" name="' + run_info.spec.desc + '" timestamp="' + run_info.started.to_s + '" time="' + ('%.3f' % run_info.duration) + '">'
30
-
31
- if run_info.failure and !run_info.failure.cause
32
- failure_message = "Expected #{run_info.failure.expectation}"
33
- failure_message += " with #{run_info.data}" if run_info.data
34
-
35
- if run_info.failure.message
36
- failure_message += " but it failed with #{run_info.failure.message}"
37
- else
38
- failure_message += " but it failed"
39
- end
40
-
41
- xml_str += '<failure message="' + failure_message.gsub('"', '`') + '"></failure>'
42
- end
43
-
44
-
45
- if run_info.error or (run_info.failure and run_info.failure.cause)
46
- error = run_info.error || run_info.failure.cause
47
-
48
- type = error.class.name
49
- failure_message = error.message
50
- text = error.backtrace.join "\n"
51
-
52
- xml_str += '<error message="' + failure_message.gsub('"', '`') + '" type="' + type + '">'
53
- xml_str += '<![CDATA[' + text + ']]>'
54
- xml_str += '</error>'
55
- end
56
-
57
-
58
- if run_info.log.count > 0 or run_info.properties.count > 0 or run_info.data
59
- xml_str += '<system-out>'
60
- xml_str += '<![CDATA['
61
-
62
- if run_info.properties.count > 0
63
- run_info.properties.each do |key, val|
64
- xml_str += "#{key}: #{val}\n"
65
- end
66
- end
67
-
68
- if run_info.data
69
- data_str = run_info.data
70
- data_str = run_info.data.inspect unless run_info.data.is_a? String or run_info.data.is_a? Integer
71
- xml_str += "data: #{data_str}\n"
72
- end
73
-
74
- if run_info.log.count > 0
75
- messages = run_info.log.map { |x| "[#{x[0].strftime('%F %T')}] #{x[1]}" }
76
- xml_str += messages.join("\n")
77
- end
78
-
79
- xml_str += ']]>'
80
- xml_str += '</system-out>'
81
- end
82
-
83
- xml_str += '</testcase>'
84
- end
85
-
86
- xml_str += '</testsuite>'
87
- end
88
-
89
- xml_str += '</testsuites>'
90
-
91
- Dir.mkdir @config['out_path'] unless Dir.exist? @config['out_path']
92
-
93
- file_path = File.join(@config['out_path'], "spectre-junit_#{timestamp}.xml")
94
-
95
- File.open(file_path, 'w') do |file|
96
- file.write(xml_str)
97
- end
98
- end
99
- end
100
- end
1
+ require 'CGI'
2
+
3
+ # https://llg.cubic.org/docs/junit/
4
+ # Azure mappings: https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/test/publish-test-results?view=azure-devops&tabs=junit%2Cyaml
5
+
6
+ module Spectre::Reporter
7
+ class JUnit
8
+ def initialize config
9
+ @config = config
10
+ end
11
+
12
+ def report run_infos
13
+ now = Time.now.getutc
14
+ timestamp = now.strftime('%s')
15
+ datetime = now.strftime('%FT%T%:z')
16
+
17
+ xml_str = '<?xml version="1.0" encoding="UTF-8" ?>'
18
+ xml_str += '<testsuites>'
19
+
20
+ suite_id = 0
21
+
22
+ run_infos.group_by { |x| x.spec.subject }.each do |subject, run_infos|
23
+ failures = run_infos.select { |x| x.failure != nil }
24
+ errors = run_infos.select { |x| x.error != nil }
25
+ skipped = run_infos.select { |x| x.skipped? }
26
+
27
+ xml_str += '<testsuite package="' + CGI::escapeHTML(subject.desc) + '" id="' + CGI::escapeHTML(suite_id.to_s) + '" name="' + CGI::escapeHTML(subject.desc) + '" timestamp="' + datetime + '" tests="' + run_infos.count.to_s + '" failures="' + failures.count.to_s + '" errors="' + errors.count.to_s + '" skipped="' + skipped.count.to_s + '">'
28
+ suite_id += 1
29
+
30
+ run_infos.each do |run_info|
31
+ xml_str += '<testcase classname="' + CGI::escapeHTML(run_info.spec.file.to_s) + '" name="' + CGI::escapeHTML(run_info.spec.desc) + '" timestamp="' + run_info.started.to_s + '" time="' + ('%.3f' % run_info.duration) + '">'
32
+
33
+ if run_info.failure and !run_info.failure.cause
34
+ failure_message = "Expected #{run_info.failure.expectation}"
35
+ failure_message += " with #{run_info.data}" if run_info.data
36
+
37
+ if run_info.failure.message
38
+ failure_message += " but it failed with #{run_info.failure.message}"
39
+ else
40
+ failure_message += " but it failed"
41
+ end
42
+
43
+ xml_str += '<failure message="' + CGI::escapeHTML(failure_message.gsub('"', '`')) + '"></failure>'
44
+ end
45
+
46
+
47
+ if run_info.error or (run_info.failure and run_info.failure.cause)
48
+ error = run_info.error || run_info.failure.cause
49
+
50
+ type = error.class.name
51
+ failure_message = error.message
52
+ text = error.backtrace.join "\n"
53
+
54
+ xml_str += '<error message="' + CGI::escapeHTML(failure_message.gsub('"', '`')) + '" type="' + type + '">'
55
+ xml_str += '<![CDATA[' + text + ']]>'
56
+ xml_str += '</error>'
57
+ end
58
+
59
+
60
+ if run_info.log.count > 0 or run_info.properties.count > 0 or run_info.data
61
+ xml_str += '<system-out>'
62
+ xml_str += '<![CDATA['
63
+
64
+ if run_info.properties.count > 0
65
+ run_info.properties.each do |key, val|
66
+ xml_str += "#{key}: #{val}\n"
67
+ end
68
+ end
69
+
70
+ if run_info.data
71
+ data_str = run_info.data
72
+ data_str = run_info.data.inspect unless run_info.data.is_a? String or run_info.data.is_a? Integer
73
+ xml_str += "data: #{data_str}\n"
74
+ end
75
+
76
+ if run_info.log.count > 0
77
+ messages = run_info.log.map { |x| "[#{x[0].strftime('%F %T')}] #{x[1]}" }
78
+ xml_str += messages.join("\n")
79
+ end
80
+
81
+ xml_str += ']]>'
82
+ xml_str += '</system-out>'
83
+ end
84
+
85
+ xml_str += '</testcase>'
86
+ end
87
+
88
+ xml_str += '</testsuite>'
89
+ end
90
+
91
+ xml_str += '</testsuites>'
92
+
93
+ Dir.mkdir @config['out_path'] unless Dir.exist? @config['out_path']
94
+
95
+ file_path = File.join(@config['out_path'], "spectre-junit_#{timestamp}.xml")
96
+
97
+ File.open(file_path, 'w') do |file|
98
+ file.write(xml_str)
99
+ end
100
+ end
101
+ end
102
+ end
@@ -1,49 +1,49 @@
1
- require_relative '../spectre'
2
-
3
- require 'ostruct'
4
-
5
- module Spectre
6
- module Resources
7
- class ResourceCollection
8
- def initialize
9
- @items = {}
10
- end
11
-
12
- def add name, path
13
- @items[name] = path
14
- end
15
-
16
- def [] name
17
- raise "Resource with name '#{name}' does not exist" unless @items.key? name
18
-
19
- @items[name]
20
- end
21
- end
22
-
23
- class << self
24
- @@resources = ResourceCollection.new
25
-
26
- def resources
27
- @@resources
28
- end
29
- end
30
-
31
- Spectre.register do |config|
32
- return unless config.key? 'resource_paths'
33
-
34
- config['resource_paths'].each do |resource_path|
35
- resource_files = Dir.glob File.join(resource_path, '**/*')
36
-
37
- resource_files.each do |file|
38
- file.slice! resource_path
39
- file = file[1..-1]
40
- @@resources.add file, File.expand_path(File.join resource_path, file)
41
- end
42
- end
43
-
44
- @@resources.freeze
45
- end
46
-
47
- Spectre.delegate :resources, to: self
48
- end
49
- end
1
+ require_relative '../spectre'
2
+
3
+ require 'ostruct'
4
+
5
+ module Spectre
6
+ module Resources
7
+ class ResourceCollection
8
+ def initialize
9
+ @items = {}
10
+ end
11
+
12
+ def add name, path
13
+ @items[name] = path
14
+ end
15
+
16
+ def [] name
17
+ raise "Resource with name '#{name}' does not exist" unless @items.key? name
18
+
19
+ @items[name]
20
+ end
21
+ end
22
+
23
+ class << self
24
+ @@resources = ResourceCollection.new
25
+
26
+ def resources
27
+ @@resources
28
+ end
29
+ end
30
+
31
+ Spectre.register do |config|
32
+ return unless config.key? 'resource_paths'
33
+
34
+ config['resource_paths'].each do |resource_path|
35
+ resource_files = Dir.glob File.join(resource_path, '**/*')
36
+
37
+ resource_files.each do |file|
38
+ file.slice! resource_path
39
+ file = file[1..-1]
40
+ @@resources.add file, File.expand_path(File.join resource_path, file)
41
+ end
42
+ end
43
+
44
+ @@resources.freeze
45
+ end
46
+
47
+ Spectre.delegate :resources, to: self
48
+ end
49
+ end