Class: Aspec::Formatter::JUnit

Inherits:
Object
  • Object
show all
Defined in:
lib/aspec/formatters/junit.rb

Instance Method Summary collapse

Constructor Details

#initialize(test_file_name, verbose = false, out_file_name = '.junit_aspecs') ⇒ JUnit

Returns a new instance of JUnit


5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/aspec/formatters/junit.rb', line 5

def initialize(test_file_name, verbose = false, out_file_name = '.junit_aspecs')
  @test_results = { :failures => [], :successes => [] }
  @out = File.open(out_file_name, 'w')
  @test_file_name = test_file_name
  @exceptions = []
  at_exit do
    unless @out.closed?
      @out.flush
      @out.close
      puts "Output junit results to .junit_aspecs"
    end
  end
end

Instance Method Details

#clearObject


19
20
# File 'lib/aspec/formatters/junit.rb', line 19

def clear
end

#comment(comment_string) ⇒ Object


22
23
# File 'lib/aspec/formatters/junit.rb', line 22

def comment(comment_string)
end

#debugObject


41
42
# File 'lib/aspec/formatters/junit.rb', line 41

def debug
end

#dump_summary(summary) ⇒ Object


44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/aspec/formatters/junit.rb', line 44

def dump_summary(summary)
  @out.puts("<?xml version=\"1.0\" encoding=\"utf-8\" ?>")
  @out.puts("<testsuite errors=\"0\" failures=\"#{failure_count}\" tests=\"#{example_count}\" time=\"#{duration=0}\" timestamp=\"#{Time.now.iso8601}\">")
  @out.puts("  <properties />")

  @test_results[:successes].each do |success_string|
    #TODO: Add timings
    runtime = 0
    @out.puts("  <testcase classname=\"#{@test_file_name}\" name=\"#{test_name(success_string)}\" time=\"#{runtime}\" />")
  end
  @test_results[:failures].each do |(failure_string, exceptions)|
    runtime = 0
    @out.puts("  <testcase classname=\"#{@test_file_name}\" name=\"#{failure_string}\" time=\"#{runtime}\">")

    @out.puts("    <failure message=\"failure\" type=\"failure\">")
    @out.puts("<![CDATA[ #{exceptions} ]]>")
    @out.puts("    </failure>")
    @out.puts("  </testcase>")
  end
  @out.puts("</testsuite>")
end

#exception(error_string) ⇒ Object


30
31
32
# File 'lib/aspec/formatters/junit.rb', line 30

def exception(error_string)
  @exceptions << error_string
end

#step_error(step) ⇒ Object


25
26
27
28
# File 'lib/aspec/formatters/junit.rb', line 25

def step_error(step)
  @test_results[:failures] << [step_line(step), @exceptions]
  @exceptions = []
end

#step_error_title(step) ⇒ Object


34
35
# File 'lib/aspec/formatters/junit.rb', line 34

def step_error_title(step)
end

#step_pass(step) ⇒ Object


37
38
39
# File 'lib/aspec/formatters/junit.rb', line 37

def step_pass(step)
  @test_results[:successes] << step_line(step)
end