yarjuf 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/HISTORY.txt +8 -1
  2. data/lib/yarjuf.rb +38 -28
  3. metadata +2 -2
@@ -2,4 +2,11 @@
2
2
  - Initial release
3
3
 
4
4
  1.0.1
5
- - Fixing incompatibility with rspec 2.12
5
+ - Bug in RSpec 2.12 needs coding around
6
+
7
+ 1.0.2
8
+ - Added dependency on the 'builder' gem
9
+
10
+ 1.0.3
11
+ - Bug fix in RSpec 2.12.1 means we can go back to how it was before 1.0.1
12
+
@@ -3,6 +3,9 @@ require 'builder'
3
3
  require 'rspec/core/formatters/base_formatter'
4
4
 
5
5
  class JUnit < RSpec::Core::Formatters::BaseFormatter
6
+
7
+ #rspec formatter methods we care about
8
+
6
9
  def initialize(output)
7
10
  super output
8
11
  @test_suite_results = {}
@@ -20,6 +23,14 @@ class JUnit < RSpec::Core::Formatters::BaseFormatter
20
23
  add_to_test_suite_results(example)
21
24
  end
22
25
 
26
+ def dump_summary(duration, example_count, failure_count, pending_count)
27
+ builder = Builder::XmlMarkup.new :indent => 2
28
+ build_results builder, duration, example_count, failure_count, pending_count
29
+ output.puts builder.target!
30
+ end
31
+
32
+ protected
33
+
23
34
  def add_to_test_suite_results(example)
24
35
  suite_name = root_group_name_for(example)
25
36
  @test_suite_results[suite_name] = [] unless @test_suite_results.keys.include?(suite_name)
@@ -27,17 +38,13 @@ class JUnit < RSpec::Core::Formatters::BaseFormatter
27
38
  end
28
39
 
29
40
  def root_group_name_for(example)
30
- group_hierarchy_for(example).first[:description]
31
- end
32
-
33
- def group_hierarchy_for(example)
34
41
  group_hierarchy = []
35
42
  current_example_group = example.metadata[:example_group]
36
43
  until current_example_group.nil? do
37
44
  group_hierarchy.unshift current_example_group
38
45
  current_example_group = current_example_group[:example_group]
39
46
  end
40
- group_hierarchy
47
+ group_hierarchy.first[:description]
41
48
  end
42
49
 
43
50
  def failure_details_for(example)
@@ -45,36 +52,39 @@ class JUnit < RSpec::Core::Formatters::BaseFormatter
45
52
  exception.nil? ? "" : "#{exception.message}\n#{format_backtrace(exception.backtrace, example).join("\n")}"
46
53
  end
47
54
 
48
- def fail_count_for_suite(suite)
49
- suite.select {|example| example.metadata[:execution_result][:status] == "failed"}.size
55
+ def count_in_suite_of_type(suite, test_case_result_type)
56
+ suite.select {|example| example.metadata[:execution_result][:status] == test_case_result_type}.size
50
57
  end
51
58
 
52
- def skipped_count_for_suite(suite)
53
- suite.select {|example| example.metadata[:execution_result][:status] == "pending"}.size
54
- end
59
+ #methods to build the xml for test suites and individual tests
55
60
 
56
- def dump_summary(duration, example_count, failure_count, pending_count)
57
- builder = Builder::XmlMarkup.new :indent => 2
61
+ def build_results(builder, duration, example_count, failure_count, pending_count)
58
62
  builder.instruct! :xml, :version => "1.0", :encoding => "UTF-8"
59
63
  builder.testsuites :errors => 0, :failures => failure_count, :skipped => pending_count, :tests => example_count, :time => duration, :timestamp => Time.now.iso8601 do
60
- @test_suite_results.each do |suite_name, tests|
61
- builder.testsuite :name => suite_name, :tests => tests.size, :errors => 0, :failures => fail_count_for_suite(tests), :skipped => skipped_count_for_suite(tests) do
62
- builder.properties
63
- tests.each do |test|
64
- builder.testcase :name => test.metadata[:full_description], :time => test.metadata[:execution_result][:run_time] do
65
- case test.metadata[:execution_result][:status]
66
- when "pending" then builder.skipped
67
- when "failed"
68
- builder.failure :message => "failed #{test.metadata[:full_description]}", :type => "failed" do
69
- builder.cdata! failure_details_for test
70
- end
71
- end
72
- end
73
- end
74
- end
64
+ @test_suite_results.each {|suite_name, tests| build_test_suite builder, suite_name, tests}
65
+ end
66
+ end
67
+
68
+ def build_test_suite(builder, suite_name, tests)
69
+ builder.testsuite :name => suite_name, :tests => tests.size, :errors => 0, :failures => count_in_suite_of_type(tests, "failed"), :skipped => count_in_suite_of_type(tests, "pending") do
70
+ builder.properties
71
+ tests.each {|test| build_test builder, test}
72
+ end
73
+ end
74
+
75
+ def build_test(builder, test)
76
+ builder.testcase :name => test.metadata[:full_description], :time => test.metadata[:execution_result][:run_time] do
77
+ case test.metadata[:execution_result][:status]
78
+ when "pending" then builder.skipped
79
+ when "failed" then build_failed_test builder, test
75
80
  end
76
81
  end
77
- output.puts builder.target!
82
+ end
83
+
84
+ def build_failed_test(builder, test)
85
+ builder.failure :message => "failed #{test.metadata[:full_description]}", :type => "failed" do
86
+ builder.cdata! failure_details_for test
87
+ end
78
88
  end
79
89
  end
80
90
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yarjuf
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-06 00:00:00.000000000 Z
12
+ date: 2012-12-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec