yarjuf 1.0.4 → 1.0.5

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 +4 -0
  2. data/lib/yarjuf.rb +58 -34
  3. metadata +2 -2
@@ -10,3 +10,7 @@
10
10
  1.0.3
11
11
  - Bug fix in RSpec 2.12.1 means we can go back to how it was before 1.0.1
12
12
 
13
+ 1.0.4
14
+ - No functional changes, just a big refactor to make the code more
15
+ maintainable.
16
+
@@ -2,6 +2,7 @@ require 'time'
2
2
  require 'builder'
3
3
  require 'rspec/core/formatters/base_formatter'
4
4
 
5
+ #An RSpec formatter for generating results in JUnit format
5
6
  class JUnit < RSpec::Core::Formatters::BaseFormatter
6
7
 
7
8
  #rspec formatter methods we care about
@@ -9,35 +10,46 @@ class JUnit < RSpec::Core::Formatters::BaseFormatter
9
10
  def initialize(output)
10
11
  super output
11
12
  @test_suite_results = {}
13
+ @builder = Builder::XmlMarkup.new :indent => 2
12
14
  end
13
15
 
14
16
  def example_passed(example)
15
- add_to_test_suite_results(example)
17
+ add_to_test_suite_results example
16
18
  end
17
19
 
18
20
  def example_failed(example)
19
- add_to_test_suite_results(example)
21
+ add_to_test_suite_results example
20
22
  end
21
23
 
22
24
  def example_pending(example)
23
- add_to_test_suite_results(example)
25
+ add_to_test_suite_results example
24
26
  end
25
27
 
26
28
  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!
29
+ build_results duration, example_count, failure_count, pending_count
30
+ output.puts @builder.target!
30
31
  end
31
32
 
32
33
  protected
33
34
 
34
35
  def add_to_test_suite_results(example)
35
- suite_name = root_group_name_for(example)
36
- @test_suite_results[suite_name] = [] unless @test_suite_results.keys.include?(suite_name)
36
+ suite_name = JUnit.root_group_name_for example
37
+ @test_suite_results[suite_name] = [] unless @test_suite_results.keys.include? suite_name
37
38
  @test_suite_results[suite_name] << example
38
39
  end
39
40
 
40
- def root_group_name_for(example)
41
+ def failure_details_for(example)
42
+ exception = example.metadata[:execution_result][:exception]
43
+ exception.nil? ? "" : "#{exception.message}\n#{format_backtrace(exception.backtrace, example).join("\n")}"
44
+ end
45
+
46
+ #utility methods
47
+
48
+ def self.count_in_suite_of_type(suite, test_case_result_type)
49
+ suite.select {|example| example.metadata[:execution_result][:status] == test_case_result_type}.size
50
+ end
51
+
52
+ def self.root_group_name_for(example)
41
53
  group_hierarchy = []
42
54
  current_example_group = example.metadata[:example_group]
43
55
  until current_example_group.nil? do
@@ -47,43 +59,55 @@ class JUnit < RSpec::Core::Formatters::BaseFormatter
47
59
  group_hierarchy.first[:description]
48
60
  end
49
61
 
50
- def failure_details_for(example)
51
- exception = example.metadata[:execution_result][:exception]
52
- exception.nil? ? "" : "#{exception.message}\n#{format_backtrace(exception.backtrace, example).join("\n")}"
53
- end
54
-
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
57
- end
58
-
59
62
  #methods to build the xml for test suites and individual tests
60
63
 
61
- def build_results(builder, duration, example_count, failure_count, pending_count)
62
- builder.instruct! :xml, :version => "1.0", :encoding => "UTF-8"
63
- builder.testsuites :errors => 0, :failures => failure_count, :skipped => pending_count, :tests => example_count, :time => duration, :timestamp => Time.now.iso8601 do
64
- @test_suite_results.each {|suite_name, tests| build_test_suite builder, suite_name, tests}
64
+ def build_results(duration, example_count, failure_count, pending_count)
65
+ @builder.instruct! :xml, :version => "1.0", :encoding => "UTF-8"
66
+ @builder.testsuites :errors => 0, :failures => failure_count, :skipped => pending_count, :tests => example_count, :time => duration, :timestamp => Time.now.iso8601 do
67
+ build_all_suites
68
+ end
69
+ end
70
+
71
+ def build_all_suites
72
+ @test_suite_results.each do |suite_name, tests|
73
+ build_test_suite suite_name, tests
65
74
  end
66
75
  end
67
76
 
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}
77
+ def build_test_suite(suite_name, tests)
78
+ failure_count = JUnit.count_in_suite_of_type tests, "failed"
79
+ skipped_count = JUnit.count_in_suite_of_type tests, "pending"
80
+
81
+ @builder.testsuite :name => suite_name, :tests => tests.size, :errors => 0, :failures => failure_count, :skipped => skipped_count do
82
+ @builder.properties
83
+ build_all_tests tests
84
+ end
85
+ end
86
+
87
+ def build_all_tests(tests)
88
+ tests.each do |test|
89
+ build_test test
72
90
  end
73
91
  end
74
92
 
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
93
+ def build_test(test)
94
+ test_name = test.metadata[:full_description]
95
+ execution_time = test.metadata[:execution_result][:run_time]
96
+ test_status = test.metadata[:execution_result][:status]
97
+
98
+ @builder.testcase :name => test_name, :time => execution_time do
99
+ case test_status
100
+ when "pending" then @builder.skipped
101
+ when "failed" then build_failed_test test
80
102
  end
81
103
  end
82
104
  end
83
105
 
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
106
+ def build_failed_test(test)
107
+ failure_message = "failed #{test.metadata[:full_description]}"
108
+
109
+ @builder.failure :message => failure_message, :type => "failed" do
110
+ @builder.cdata! failure_details_for test
87
111
  end
88
112
  end
89
113
  end
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.4
4
+ version: 1.0.5
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-11 00:00:00.000000000 Z
12
+ date: 2013-01-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec