minitest-junit 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/minitest/junit/version.rb +1 -1
- data/lib/minitest/junit.rb +27 -8
- data/test/reporter_test.rb +48 -13
- data/test/testcase_formatter_test.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e9e6fe53a55b11d36289c47953e13279e41afff916cb27a7161d64baa61d914
|
4
|
+
data.tar.gz: 9311c1d71be9be105f06c0f035bd8411e74f7c3a468d77e85a9cca34b11097f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5fd510f4009f0c504c3d7c75f8dc8c217c61a895c92fabb912908d20ccfdfb63454152cf56257e5deb16ae499244505bfbbae768a26b9894650f1a8fa0733d9c
|
7
|
+
data.tar.gz: d47bf2f92fb7a8814be1a4337826cbe4e0cb803ac8f6d0a55e285b2a77e3ae642f7f2c597127300f080f25305d887b5a433da6e1906ff81dcca64d4d9734d18a
|
data/lib/minitest/junit.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'minitest/junit/version'
|
2
2
|
require 'minitest'
|
3
3
|
require 'builder'
|
4
|
+
require 'socket'
|
5
|
+
require 'time'
|
4
6
|
|
5
7
|
# :nodoc:
|
6
8
|
module Minitest
|
@@ -11,6 +13,8 @@ module Minitest
|
|
11
13
|
@io = io
|
12
14
|
@results = []
|
13
15
|
@options = options
|
16
|
+
@options[:timestamp] = options.fetch(:timestamp, Time.now.iso8601)
|
17
|
+
@options[:hostname] = options.fetch(:hostname, Socket.gethostname)
|
14
18
|
end
|
15
19
|
|
16
20
|
def passed?
|
@@ -24,15 +28,26 @@ module Minitest
|
|
24
28
|
end
|
25
29
|
|
26
30
|
def report
|
27
|
-
|
28
|
-
|
29
|
-
|
31
|
+
xml = Builder::XmlMarkup.new(:indent => 2)
|
32
|
+
xml.testsuite(name: 'minitest',
|
33
|
+
timestamp: @options[:timestamp],
|
34
|
+
hostname: @options[:hostname],
|
35
|
+
tests: @results.count,
|
36
|
+
skipped: @results.count { |result| result.skipped? },
|
37
|
+
failures: @results.count { |result| !result.error? && result.failure },
|
38
|
+
errors: @results.count { |result| result.error? },
|
39
|
+
time: format_time(@results.inject(0) { |a, e| a += e.time })) do
|
40
|
+
@results.each { |result| format(result, xml) }
|
41
|
+
end
|
42
|
+
@io.puts xml.target!
|
30
43
|
end
|
31
44
|
|
32
|
-
def format(result)
|
33
|
-
xml = Builder::XmlMarkup.new
|
34
|
-
xml.testcase classname: format_class(result),
|
35
|
-
|
45
|
+
def format(result, parent = nil)
|
46
|
+
xml = Builder::XmlMarkup.new(:target => parent, :indent => 2)
|
47
|
+
xml.testcase classname: format_class(result),
|
48
|
+
name: format_name(result),
|
49
|
+
time: format_time(result.time),
|
50
|
+
assertions: result.assertions do |t|
|
36
51
|
if result.skipped?
|
37
52
|
t.skipped message: result
|
38
53
|
else
|
@@ -42,7 +57,7 @@ module Minitest
|
|
42
57
|
end
|
43
58
|
end
|
44
59
|
end
|
45
|
-
xml
|
60
|
+
xml
|
46
61
|
end
|
47
62
|
|
48
63
|
private
|
@@ -70,6 +85,10 @@ module Minitest
|
|
70
85
|
def format_name(result)
|
71
86
|
result.name
|
72
87
|
end
|
88
|
+
|
89
|
+
def format_time(time)
|
90
|
+
Kernel::format('%.6f', time)
|
91
|
+
end
|
73
92
|
end
|
74
93
|
end
|
75
94
|
end
|
data/test/reporter_test.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'minitest/autorun'
|
2
|
+
require 'builder'
|
2
3
|
require 'stringio'
|
3
4
|
require 'time'
|
4
5
|
|
@@ -10,34 +11,68 @@ class ReporterTest < Minitest::Test
|
|
10
11
|
|
11
12
|
reporter.report
|
12
13
|
|
13
|
-
|
14
|
+
assert_match(/^<testsuite name="minitest" timestamp="[^"]+" hostname="[^"]+" tests="0" skipped="0" failures="0" errors="0" time="0.000000">\n<\/testsuite>\n$/, reporter.output)
|
14
15
|
end
|
15
16
|
|
16
|
-
def
|
17
|
+
def test_formats_each_successful_result_with_a_formatter
|
17
18
|
reporter = create_reporter
|
18
|
-
|
19
|
-
|
19
|
+
|
20
|
+
results = do_formatting_test(reporter, count: rand(100), cause_failures: 0)
|
21
|
+
|
22
|
+
results.each do |result|
|
23
|
+
assert_match("<testcase classname=\"FakeTestName\" name=\"#{result.name}\"", reporter.output)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_formats_each_failed_result_with_a_formatter
|
28
|
+
reporter = create_reporter
|
29
|
+
|
30
|
+
results = do_formatting_test(reporter, count: rand(100), cause_failures: 1)
|
31
|
+
|
32
|
+
results.each do |result|
|
33
|
+
assert_match("<testcase classname=\"FakeTestName\" name=\"#{result.name}\"", reporter.output)
|
34
|
+
assert_match(/<failure/, reporter.output)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def do_formatting_test(reporter, count: 1, cause_failures: 0)
|
41
|
+
results = count.times.map do |i|
|
42
|
+
result = create_test_result(methodname: "test_name#{i}", failures: cause_failures)
|
20
43
|
reporter.record result
|
21
44
|
result
|
22
45
|
end
|
23
46
|
|
24
47
|
reporter.report
|
25
48
|
|
26
|
-
|
27
|
-
assert_equal expected, reporter.output
|
49
|
+
results
|
28
50
|
end
|
29
51
|
|
30
|
-
|
52
|
+
def create_test_result(name: FakeTestName, methodname: 'test_method_name', successes: 1, failures: 0)
|
53
|
+
test = Class.new Minitest::Test do
|
54
|
+
define_method 'class' do
|
55
|
+
name
|
56
|
+
end
|
57
|
+
end.new methodname
|
58
|
+
test.time = rand(100)
|
59
|
+
test.assertions = successes + failures
|
60
|
+
test.failures = failures.times.map do |i|
|
61
|
+
Class.new Minitest::Assertion do
|
62
|
+
define_method 'backtrace' do
|
63
|
+
["Model failure \##{i}", 'This is a test backtrace']
|
64
|
+
end
|
65
|
+
end.new
|
66
|
+
end
|
67
|
+
Minitest::Result.from test
|
68
|
+
end
|
31
69
|
|
32
|
-
def create_reporter
|
33
|
-
io = StringIO.new
|
34
|
-
reporter = Minitest::Junit::Reporter.new io,
|
70
|
+
def create_reporter(options = {})
|
71
|
+
io = StringIO.new ''
|
72
|
+
reporter = Minitest::Junit::Reporter.new io, options
|
35
73
|
def reporter.output
|
36
74
|
@io.string
|
37
75
|
end
|
38
|
-
def reporter.format(result)
|
39
|
-
result
|
40
|
-
end
|
41
76
|
reporter.start
|
42
77
|
reporter
|
43
78
|
end
|
@@ -17,7 +17,7 @@ class TestCaseFormatter < Minitest::Test
|
|
17
17
|
test = create_test_result
|
18
18
|
reporter = create_reporter
|
19
19
|
|
20
|
-
assert_match test.name, reporter.format(test)
|
20
|
+
assert_match test.name, reporter.format(test).target!
|
21
21
|
end
|
22
22
|
|
23
23
|
def test_skipped_tests_generates_skipped_tag
|
@@ -28,7 +28,7 @@ class TestCaseFormatter < Minitest::Test
|
|
28
28
|
|
29
29
|
reporter.report
|
30
30
|
|
31
|
-
assert_match(/<skipped message="[^<>]+"
|
31
|
+
assert_match(/<skipped message="[^<>]+"\/>\n<\/testcase>\n<\/testsuite>\n/, reporter.output)
|
32
32
|
end
|
33
33
|
|
34
34
|
def test_failing_tests_creates_failure_tag
|