Class: RSpec::Core::Formatters::JUnitFormatter

Inherits:
BaseFormatter
  • Object
show all
Defined in:
lib/rspec/core/formatters/j_unit_formatter.rb

Overview

Dumps rspec results as a JUnit XML file. Based on XML schema: windyroad.org/dl/Open%20Source/JUnit.xsd

Instance Method Summary collapse

Instance Method Details

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



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/rspec/core/formatters/j_unit_formatter.rb', line 13

def dump_summary duration, example_count, failure_count, pending_count
  super
  
  xml.instruct!
  xml.testsuite :tests => example_count, :failures => failure_count, :errors => 0, :time => '%.6f' % duration, :timestamp => @start.iso8601 do
    xml.properties
    examples.each do |example|
      send :"dump_summary_example_#{example.execution_result[:status]}", example
    end
  end
end

#dump_summary_example_failed(example) ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'lib/rspec/core/formatters/j_unit_formatter.rb', line 39

def dump_summary_example_failed example
  exception = example.execution_result[:exception]
  backtrace = format_backtrace exception.backtrace, example
  
  xml_example example do
    xml.failure :message => exception.to_s, :type => exception.class.name do
      xml.cdata! "#{exception.message}\n#{backtrace.join "\n"}"
    end
  end
end

#dump_summary_example_passed(example) ⇒ Object



29
30
31
# File 'lib/rspec/core/formatters/j_unit_formatter.rb', line 29

def dump_summary_example_passed example
  xml_example example
end

#dump_summary_example_pending(example) ⇒ Object



33
34
35
36
37
# File 'lib/rspec/core/formatters/j_unit_formatter.rb', line 33

def dump_summary_example_pending example
  xml_example example do
    xml.skipped
  end
end

#start(example_count) ⇒ Object



8
9
10
11
# File 'lib/rspec/core/formatters/j_unit_formatter.rb', line 8

def start example_count
  @start = Time.now
  super
end

#xmlObject



4
5
6
# File 'lib/rspec/core/formatters/j_unit_formatter.rb', line 4

def xml
  @xml ||= Builder::XmlMarkup.new :target => output, :indent => 2 
end

#xml_example(example, &block) ⇒ Object



25
26
27
# File 'lib/rspec/core/formatters/j_unit_formatter.rb', line 25

def xml_example example, &block
  xml.testcase :classname => example.file_path, :name => example.full_description, :time => '%.6f' % example.execution_result[:run_time], &block
end