Error when failure.message is nil #63

Closed
rkistner opened this Issue Jun 21, 2012 · 2 comments

2 participants

@rkistner

When an exception message is nil, ci_reporter crashes, and does not produce any XML logs.

The error I get is: ci/reporter/test_suite.rb:79:intrunc!': undefined method `sub' for nil:NilClass (NoMethodError)

This was tested on ci_reporter 1.7.0.

I've worked around this issue with monkeypatching:

require 'ci/reporter/test_suite'

class CI::Reporter::TestSuite
  # Creates an xml string containing the test suite results.
  def to_xml
    builder = create_builder
    # more recent version of Builder doesn't need the escaping
    def builder.trunc!(txt)
      return '' if txt.nil?
      txt.sub(/\n.*/m, '...')
    end
    builder.instruct!
    attrs = {}
    each_pair {|k,v| attrs[k] = builder.trunc!(v.to_s) unless v.nil? || v.to_s.empty? }
    builder.testsuite(attrs) do
      @testcases.each do |tc|
        tc.to_xml(builder)
      end
      builder.tag! "system-out" do
        builder.text!(self.stdout || '' )
      end
      builder.tag! "system-err" do
        builder.text!(self.stderr || '' )
      end
    end
  end
end

class CI::Reporter::TestCase

  # Writes xml representing the test result to the provided builder.
  def to_xml(builder)
    attrs = {}
    each_pair {|k,v| attrs[k] = builder.trunc!(v.to_s) unless v.nil? || v.to_s.empty?}
    builder.testcase(attrs) do
      if skipped
        builder.skipped
      else
        failures.each do |failure|
          message = failure.message || ''
          tag = case failure.class.name
                  when /TestUnitSkipped/ then :skipped
                  when /TestUnitError/, /MiniTestError/ then :error
                  else :failure end

          builder.tag!(tag, :type => builder.trunc!(failure.name), :message => builder.trunc!(message)) do
            builder.text!("#{message} (#{failure.name})\n")
            builder.text!(failure.location)
          end
        end
      end
    end
  end
end
@shepmaster
ci-reporter member

We are in the process of cleaning out old issues. If this issue still
applies to this version, please let us know, otherwise we're going to
close this issue to focus on current problems. Thanks for your report!

@shepmaster
ci-reporter member

Closing due to inactivity.

@shepmaster shepmaster closed this Jul 22, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment