spectre-core 1.12.0 → 1.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,100 +1,100 @@
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
+ # 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,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