class RspecTestlinkJunitformatter

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

Attributes

started[R]

Public Instance Methods

dump_summary(notification) click to toggle source
# File lib/rspec_testlink_junit_formatter.rb, line 27
def dump_summary(notification)
  @summary_notification = notification
  xml_dump
end
start(notification) click to toggle source
Calls superclass method
# File lib/rspec_testlink_junit_formatter.rb, line 17
def start(notification)
  @start_notification = notification
  @started = Time.now
  super
end
stop(notification) click to toggle source
# File lib/rspec_testlink_junit_formatter.rb, line 23
def stop(notification)
  @examples_notification = notification
end

Private Instance Methods

classname_for(notification) click to toggle source
# File lib/rspec_testlink_junit_formatter.rb, line 56
def classname_for(notification)
  notification.example.file_path.sub(%r{\.[^/]*\Z}, "").gsub("/", ".").gsub(%r{\A\.+|\.+\Z}, "")
end
description_for(notification) click to toggle source
# File lib/rspec_testlink_junit_formatter.rb, line 64
def description_for(notification)
  notification.example.full_description
end
duration() click to toggle source
# File lib/rspec_testlink_junit_formatter.rb, line 44
def duration
  @summary_notification.duration
end
duration_for(notification) click to toggle source
# File lib/rspec_testlink_junit_formatter.rb, line 60
def duration_for(notification)
  notification.example.execution_result[:run_time]
end
example_count() click to toggle source
# File lib/rspec_testlink_junit_formatter.rb, line 36
def example_count
  @summary_notification.examples.count
end
examples() click to toggle source
# File lib/rspec_testlink_junit_formatter.rb, line 48
def examples
  @examples_notification.notifications
end
exception_for(notification) click to toggle source
# File lib/rspec_testlink_junit_formatter.rb, line 68
def exception_for(notification)
  notification.example.execution_result[:exception]
end
failure_count() click to toggle source
# File lib/rspec_testlink_junit_formatter.rb, line 40
def failure_count
  @summary_notification.failed_examples.count
end
formatted_backtrace_for(notification) click to toggle source
# File lib/rspec_testlink_junit_formatter.rb, line 72
def formatted_backtrace_for(notification)
  backtrace = notification.formatted_backtrace
end
result_of(notification) click to toggle source
# File lib/rspec_testlink_junit_formatter.rb, line 52
def result_of(notification)
  notification.example.execution_result[:status]
end
xml() click to toggle source
# File lib/rspec_testlink_junit_formatter.rb, line 78
def xml
  @xml ||= Builder::XmlMarkup.new target: output, indent: 2
end
xml_dump() click to toggle source
# File lib/rspec_testlink_junit_formatter.rb, line 82
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
xml_dump_example(example, &block) click to toggle source
# File lib/rspec_testlink_junit_formatter.rb, line 117
def xml_dump_example(example, &block)
  xml.testcase classname: classname_for(example), name: example.example.description.split('|')[1].strip, time: "%.6f" % duration_for(example), &block
end
xml_dump_examples() click to toggle source
# File lib/rspec_testlink_junit_formatter.rb, line 90
def xml_dump_examples
  examples.each do |example|
    send :"xml_dump_#{result_of(example)}", example
  end
end
xml_dump_failed(example) click to toggle source
# File lib/rspec_testlink_junit_formatter.rb, line 106
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
xml_dump_passed(example) click to toggle source
# File lib/rspec_testlink_junit_formatter.rb, line 96
def xml_dump_passed(example)
  xml_dump_example(example)
end
xml_dump_pending(example) click to toggle source
# File lib/rspec_testlink_junit_formatter.rb, line 100
def xml_dump_pending(example)
  xml_dump_example(example) do
    xml.skipped
  end
end