class RSpecJUnitFormatter

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

def classname_for(example)

def classname_for(example)
  example.file_path.sub(%r{\.[^/.]+\Z}, "").gsub("/", ".").gsub(/\A\.+|\.+\Z/, "")
end

def classname_for(notification)

def classname_for(notification)
  notification.example.file_path.sub(%r{\.[^/]*\Z}, "").gsub("/", ".").gsub(%r{\A\.+|\.+\Z}, "")
end

def description_for(example)

def description_for(example)
  example.full_description
end

def description_for(notification)

def description_for(notification)
  notification.example.full_description
end

def dump_summary(duration, example_count, failure_count, pending_count)

def dump_summary(duration, example_count, failure_count, pending_count)
  super
  xml_dump
end

def dump_summary(notification)

def dump_summary(notification)
  @summary_notification = notification
  xml_dump
end

def duration

def duration
  @summary_notification.duration
end

def duration_for(example)

def duration_for(example)
  example.execution_result[:run_time]
end

def duration_for(notification)

def duration_for(notification)
  notification.example.execution_result[:run_time]
end

def example_count

def example_count
  @summary_notification.examples.count
end

def examples

def examples
  @examples_notification.notifications
end

def exception_for(example)

def exception_for(example)
  example.execution_result[:exception]
end

def exception_for(notification)

def exception_for(notification)
  notification.example.execution_result[:exception]
end

def failure_count

def failure_count
  @summary_notification.failed_examples.count
end

def formatted_backtrace_for(example)

def formatted_backtrace_for(example)
  format_backtrace exception_for(example).backtrace, example
end

def formatted_backtrace_for(notification)

def formatted_backtrace_for(notification)
  backtrace = notification.formatted_backtrace
end

def result_of(example)

def result_of(example)
  example.execution_result[:status]
end

def result_of(notification)

def result_of(notification)
  notification.example.execution_result[:status]
end

def start(example_count)

def start(example_count)
  @started = Time.now
  super
end

def start(notification)

def start(notification)
  @start_notification = notification
  @started = Time.now
  super
end

def stop(notification)

def stop(notification)
  @examples_notification = notification
end

def xml

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

def xml_dump

def xml_dump
  xml.instruct!
  xml.testsuite name: "rspec", tests: example_count, failures: failure_count, errors: 0, time: "%.6f" % duration, timestamp: started.iso8601 do
    xml.properties
    xml_dump_examples
  end
end

def xml_dump_example(example, &block)

def xml_dump_example(example, &block)
  xml.testcase classname: classname_for(example), name: description_for(example), time: "%.6f" % duration_for(example), &block
end

def xml_dump_examples

def xml_dump_examples
  examples.each do |example|
    send :"xml_dump_#{result_of(example)}", example
  end
end

def xml_dump_examples

def xml_dump_examples
  examples.each do |example|
    send :"xml_dump_#{example.execution_result[:status]}", example
  end
end

def xml_dump_failed(example)

def xml_dump_failed(example)
  exception = exception_for(example)
  backtrace = formatted_backtrace_for(example)
  xml_dump_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

def xml_dump_passed(example)

def xml_dump_passed(example)
  xml_dump_example(example)
end

def xml_dump_pending(example)

def xml_dump_pending(example)
  xml_dump_example(example) do
    xml.skipped
  end
end