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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bb01cc706e87563df21ee3ac59414bea9dc4a72b321daa289daf264e4b69625f
4
- data.tar.gz: 79494de211ef61d553f06fd802708b6364514b7143f7f010ba604283c5a751a9
3
+ metadata.gz: 4e9e6fe53a55b11d36289c47953e13279e41afff916cb27a7161d64baa61d914
4
+ data.tar.gz: 9311c1d71be9be105f06c0f035bd8411e74f7c3a468d77e85a9cca34b11097f7
5
5
  SHA512:
6
- metadata.gz: 917d4fb7ce3de650069496ed1b599e30661040cac256f543263cc0104d73d82823f291c336040a0dc8f588c7a4b46a1ce1f61b9a06382d880c729c5034a5a7b1
7
- data.tar.gz: 5ed9083720ab9b4f9b0caa185cfe8d1577b216f2c82b808c70d9a08df3bc6daab61472d2ed97e4479803cce8d84fa93dae56e3c070c4a9542b55493afd0d2852
6
+ metadata.gz: 5fd510f4009f0c504c3d7c75f8dc8c217c61a895c92fabb912908d20ccfdfb63454152cf56257e5deb16ae499244505bfbbae768a26b9894650f1a8fa0733d9c
7
+ data.tar.gz: d47bf2f92fb7a8814be1a4337826cbe4e0cb803ac8f6d0a55e285b2a77e3ae642f7f2c597127300f080f25305d887b5a433da6e1906ff81dcca64d4d9734d18a
@@ -1,6 +1,6 @@
1
1
  module Minitest
2
2
  # :nodoc:
3
3
  module Junit
4
- VERSION = '1.0.0'
4
+ VERSION = '1.1.0'
5
5
  end
6
6
  end
@@ -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
- @io.puts '<testsuite>'
28
- @results.each { |result| @io.puts format(result) }
29
- @io.puts '</testsuite>'
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), name: format_name(result),
35
- time: result.time, assertions: result.assertions do |t|
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.target!
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
@@ -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
- assert_equal "<testsuite>\n</testsuite>\n", reporter.output
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 test_formats_each_result_with_a_formatter
17
+ def test_formats_each_successful_result_with_a_formatter
17
18
  reporter = create_reporter
18
- results = rand(100).times.map do |i|
19
- result = "test_name#{i}"
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
- expected = "<testsuite>\n#{results.join "\n"}\n</testsuite>\n"
27
- assert_equal expected, reporter.output
49
+ results
28
50
  end
29
51
 
30
- private
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="[^<>]+"\/><\/testcase>\n<\/testsuite>\n/, reporter.output)
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minitest-junit
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Allan Espinosa