Class: JUnitFormatter
- Inherits:
-
RSpec::Core::Formatters::BaseFormatter
- Object
- RSpec::Core::Formatters::BaseFormatter
- JUnitFormatter
- Defined in:
- lib/rspec-extra-formatters/junit_formatter.rb
Instance Attribute Summary collapse
-
#test_results ⇒ Object
readonly
Returns the value of attribute test_results.
Instance Method Summary collapse
- #_xml_escape(x) ⇒ Object
- #dump_summary(duration, example_count, failure_count, pending_count) ⇒ Object
- #example_failed(example) ⇒ Object
- #example_passed(example) ⇒ Object
- #example_pending(example) ⇒ Object
-
#initialize(output) ⇒ JUnitFormatter
constructor
A new instance of JUnitFormatter.
- #read_failure(t) ⇒ Object
Constructor Details
#initialize(output) ⇒ JUnitFormatter
Returns a new instance of JUnitFormatter.
36 37 38 39 |
# File 'lib/rspec-extra-formatters/junit_formatter.rb', line 36 def initialize(output) super(output) @test_results = { :failures => [], :successes => [] } end |
Instance Attribute Details
#test_results ⇒ Object (readonly)
Returns the value of attribute test_results.
34 35 36 |
# File 'lib/rspec-extra-formatters/junit_formatter.rb', line 34 def test_results @test_results end |
Instance Method Details
#_xml_escape(x) ⇒ Object
92 93 94 95 96 97 |
# File 'lib/rspec-extra-formatters/junit_formatter.rb', line 92 def _xml_escape(x) x.gsub("&", "&"). gsub("\"", """). gsub(">", ">"). gsub("<", "<") end |
#dump_summary(duration, example_count, failure_count, pending_count) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/rspec-extra-formatters/junit_formatter.rb', line 66 def dump_summary(duration, example_count, failure_count, pending_count) super(duration, example_count, failure_count, pending_count) output.puts("<?xml version=\"1.0\" encoding=\"utf-8\" ?>") output.puts("<testsuite errors=\"0\" failures=\"#{failure_count+pending_count}\" tests=\"#{example_count}\" time=\"#{duration}\" timestamp=\"#{Time.now.iso8601}\">") output.puts(" <properties />") @test_results[:successes].each do |t| md = t. runtime = md[:execution_result][:run_time] description = _xml_escape(md[:full_description]) file_path = _xml_escape(md[:file_path]) output.puts(" <testcase classname=\"#{file_path}\" name=\"#{description}\" time=\"#{runtime}\" />") end @test_results[:failures].each do |t| md = t. description = _xml_escape(md[:full_description]) file_path = _xml_escape(md[:file_path]) runtime = md[:execution_result][:run_time] output.puts(" <testcase classname=\"#{file_path}\" name=\"#{description}\" time=\"#{runtime}\">") output.puts(" <failure message=\"failure\" type=\"failure\">") output.puts("<![CDATA[ #{read_failure(t)} ]]>") output.puts(" </failure>") output.puts(" </testcase>") end output.puts("</testsuite>") end |
#example_failed(example) ⇒ Object
50 51 52 53 |
# File 'lib/rspec-extra-formatters/junit_formatter.rb', line 50 def example_failed(example) super(example) @test_results[:failures].push(example) end |
#example_passed(example) ⇒ Object
41 42 43 44 |
# File 'lib/rspec-extra-formatters/junit_formatter.rb', line 41 def example_passed(example) super(example) @test_results[:successes].push(example) end |
#example_pending(example) ⇒ Object
46 47 48 |
# File 'lib/rspec-extra-formatters/junit_formatter.rb', line 46 def example_pending(example) self.example_failed(example) end |
#read_failure(t) ⇒ Object
55 56 57 58 59 60 61 62 63 64 |
# File 'lib/rspec-extra-formatters/junit_formatter.rb', line 55 def read_failure(t) exception = t.[:execution_result][:exception_encountered] || t.[:execution_result][:exception] = "" unless (exception.nil?) = exception. += "\n" += format_backtrace(exception.backtrace, t).join("\n") end return() end |