Class: RightSupport::CI::JavaSpecFormatter

Inherits:
RSpec::Core::Formatters::BaseFormatter
  • Object
show all
Defined in:
lib/right_support/ci/java_spec_formatter.rb,
lib/right_support/ci/java_spec_formatter.rb

Overview

RSpec 2.x

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ JavaSpecFormatter

Returns a new instance of JavaSpecFormatter.



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/right_support/ci/java_spec_formatter.rb', line 17

def initialize(*args)
  begin
    require 'builder'
  rescue LoadError => e
    raise NotImplementedError, "Your Gemfile or gemspec must include builder (~> 3.0) in order to use this class"
  end
  super(*args)
  @current_example_group = nil
  @test_times = {}
  @test_groups = {}
  @test_results = {}
  @test_failures = {}
end

Instance Method Details

#classname_for(example) ⇒ Object



93
94
95
96
97
98
99
# File 'lib/right_support/ci/java_spec_formatter.rb', line 93

def classname_for(example)
  # Take our best guess, by looking at the description of the example group
  # and assuming the first word is a class name
  group = @test_groups[example]
  klass = group.description.split(/\s+/).first
  "rspec.#{klass}"
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
79
80
81
82
83
84
# File 'lib/right_support/ci/java_spec_formatter.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.testsuite :errors => 0, :failures => failure_count, :skipped => pending_count, :tests => example_count, :time => duration, :timestamp => Time.now.iso8601 do
    builder.properties
    @test_results.each_pair do |test, result|
      classname        = classname_for(test)
      full_description = test.description

      # The full description always begins with the classname, but this is useless info when
      # generating the XML report.
      if full_description.start_with?(classname)
        full_description = full_description[classname.length..-1].strip
      end

      builder.testcase(:classname => classname, :name => full_description, :time => @test_times[test]) do
        case result
        when "failed"
          builder.failure :message => "failed #{full_description}", :type => "failed" do
            builder.cdata! failure_details_for(test)
          end
        when "pending" then
          builder.skipped
        end
      end
    end
  end
  output.puts builder.target!
end

#example_failed(example) ⇒ Object



45
46
47
48
49
# File 'lib/right_support/ci/java_spec_formatter.rb', line 45

def example_failed(example, counter, failure)
  @test_times[example] = Time.now - @example_started_at
  @test_results[example] = 'failed'
  @test_failures[example] = failure
end

#example_group_started(example) ⇒ Object



31
32
33
# File 'lib/right_support/ci/java_spec_formatter.rb', line 31

def example_group_started(example)
  @current_example_group = example
end

#example_passed(example) ⇒ Object



40
41
42
43
# File 'lib/right_support/ci/java_spec_formatter.rb', line 40

def example_passed(example)
  @test_times[example] = Time.now - @example_started_at
  @test_results[example] = 'passed'
end

#example_pending(example) ⇒ Object



51
52
53
54
# File 'lib/right_support/ci/java_spec_formatter.rb', line 51

def example_pending(example, message, deprecated_pending_location=nil)
  @test_times[example] = Time.now - @example_started_at
  @test_results[example] = 'pending'
end

#example_started(example) ⇒ Object



35
36
37
38
# File 'lib/right_support/ci/java_spec_formatter.rb', line 35

def example_started(example)
  @test_groups[example] = @current_example_group
  @example_started_at = Time.now
end

#failure_details_for(example) ⇒ Object



88
89
90
91
# File 'lib/right_support/ci/java_spec_formatter.rb', line 88

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