Class: JUnit

Inherits:
RSpec::Core::Formatters::BaseFormatter
  • Object
show all
Defined in:
lib/yarjuf.rb

Instance Method Summary collapse

Constructor Details

#initialize(output) ⇒ JUnit

Returns a new instance of JUnit.



6
7
8
9
# File 'lib/yarjuf.rb', line 6

def initialize(output)
  super output
  @test_suite_results = {}
end

Instance Method Details

#add_to_test_suite_results(example) ⇒ Object



23
24
25
26
27
# File 'lib/yarjuf.rb', line 23

def add_to_test_suite_results(example)
  suite_name = root_group_name_for(example)
  @test_suite_results[suite_name] = [] unless @test_suite_results.keys.include?(suite_name)
  @test_suite_results[suite_name] << example
end

#dump_summary(duration, example_count, failure_count, pending_count) ⇒ Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/yarjuf.rb', line 56

def dump_summary(duration, example_count, failure_count, pending_count)
  builder = Builder::XmlMarkup.new :indent => 2
  builder.instruct! :xml, :version => "1.0", :encoding => "UTF-8"
  builder.testsuites :errors => 0, :failures => failure_count, :skipped => pending_count, :tests => example_count, :time => duration, :timestamp => Time.now.iso8601 do
    @test_suite_results.each do |suite_name, tests|
      builder.testsuite :name => suite_name, :tests => tests.size, :errors => 0, :failures => fail_count_for_suite(tests), :skipped => skipped_count_for_suite(tests) do
        builder.properties
        tests.each do |test|
          builder.testcase :name => test.[:full_description], :time => test.[:execution_result][:run_time] do
            case test.[:execution_result][:status]
            when "pending" then builder.skipped
            when "failed"
              builder.failure :message => "failed #{test.[:full_description]}", :type => "failed" do
                builder.cdata! failure_details_for test
              end
            end
          end
        end
      end
    end
  end
output.puts builder.target!
end

#example_failed(example) ⇒ Object



15
16
17
# File 'lib/yarjuf.rb', line 15

def example_failed(example)
  add_to_test_suite_results(example)
end

#example_passed(example) ⇒ Object



11
12
13
# File 'lib/yarjuf.rb', line 11

def example_passed(example)
  add_to_test_suite_results(example)
end

#example_pending(example) ⇒ Object



19
20
21
# File 'lib/yarjuf.rb', line 19

def example_pending(example)
  add_to_test_suite_results(example)
end

#fail_count_for_suite(suite) ⇒ Object



48
49
50
# File 'lib/yarjuf.rb', line 48

def fail_count_for_suite(suite)
  suite.select {|example| example.[:execution_result][:status] == "failed"}.size
end

#failure_details_for(example) ⇒ Object



43
44
45
46
# File 'lib/yarjuf.rb', line 43

def failure_details_for(example)
  exception = example.[:execution_result][:exception]
  exception.nil? ? "" : "#{exception.message}\n#{format_backtrace(exception.backtrace).join("\n")}"
end

#group_hierarchy_for(example) ⇒ Object



33
34
35
36
37
38
39
40
41
# File 'lib/yarjuf.rb', line 33

def group_hierarchy_for(example)
  group_hierarchy = []
  current_example_group = example.[:example_group]
  until current_example_group.nil? do
    group_hierarchy.unshift current_example_group
    current_example_group = current_example_group[:example_group]
  end
  group_hierarchy
end

#root_group_name_for(example) ⇒ Object



29
30
31
# File 'lib/yarjuf.rb', line 29

def root_group_name_for(example)
  group_hierarchy_for(example).first[:description]
end

#skipped_count_for_suite(suite) ⇒ Object



52
53
54
# File 'lib/yarjuf.rb', line 52

def skipped_count_for_suite(suite)
  suite.select {|example| example.[:execution_result][:status] == "pending"}.size
end