Class Expectations::SuiteResults
In: lib/expectations/suite_results.rb
Parent: Object

Methods

Attributes

expectations  [RW] 
out  [RW] 

Public Class methods

[Source]

   # File lib/expectations/suite_results.rb, line 4
4:   def initialize(out)
5:     self.out, self.expectations = out, []
6:     out.print "Expectations "
7:   end

Public Instance methods

[Source]

    # File lib/expectations/suite_results.rb, line 9
 9:   def <<(expectation_result)
10:     out.print expectation_result.char
11:     self.expectations << expectation_result
12:     self
13:   end

[Source]

    # File lib/expectations/suite_results.rb, line 23
23:   def errors
24:     expectations.select { |expectation| expectation.error? }
25:   end

[Source]

    # File lib/expectations/suite_results.rb, line 27
27:   def failures
28:     expectations.select { |expectation| expectation.failure? }
29:   end

[Source]

     # File lib/expectations/suite_results.rb, line 93
 93:   def filter_backtrace(trace)
 94:     patterns_to_strip = [/\/expectations\/lib\/expectations\//, /\/lib\/ruby\/1\.[89]/]
 95:     result = patterns_to_strip.inject(trace) do |result, element|
 96:       result = result.select { |line| line !~ element}
 97:     end
 98:     result.collect do |line|
 99:       "\n#{line}"
100:     end
101:   end

[Source]

    # File lib/expectations/suite_results.rb, line 19
19:   def fulfilled
20:     expectations.select { |expectation| expectation.fulfilled? }
21:   end

[Source]

    # File lib/expectations/suite_results.rb, line 46
46:   def print_fail
47:     out.puts "\nFailure: #{failures.size} failed, #{errors.size} errors, #{fulfilled.size} fulfilled"
48:     out.puts "\n--Errors--" if errors.any?
49:     errors.each do |error|
50:       out.puts "#{error.file}:#{error.line}:in `expect'" if ENV["TM_MODE"]
51:       out.puts "file <#{error.file}>"
52:       out.puts "line <#{error.line}>"
53:       out.puts "error <#{error.exception.message}>"
54:       out.puts "trace #{filter_backtrace(error.exception.backtrace).join('')}"
55:       out.puts "#{error.message}" if error.message && error.message.any?
56:       out.puts "\n"
57:     end
58:     out.puts "\n--Failures--" if failures.any?
59:     failures.each do |failure|
60:       out.puts "#{failure.file}:#{failure.line}:in `expect'" if ENV["TM_MODE"]
61:       out.puts "file <#{failure.file}>"
62:       out.puts "line <#{failure.line}>"
63:       out.puts "#{failure.message}\n\n"
64:     end
65:   end

[Source]

    # File lib/expectations/suite_results.rb, line 31
31:   def print_results(benchmark)
32:     run_time = benchmark.real
33:     run_time = 0.001 if run_time < 0.001
34:     out.puts "\nFinished in #{run_time.to_s.gsub(/(\d*)\.(\d{0,5}).*/,'\1.\2')} seconds"
35:     if succeeded?
36:       print_success
37:     else
38:       print_fail
39:     end
40:   end

[Source]

    # File lib/expectations/suite_results.rb, line 42
42:   def print_success
43:     out.puts "\nSuccess: #{fulfilled.size} fulfilled"
44:   end

[Source]

    # File lib/expectations/suite_results.rb, line 15
15:   def succeeded?
16:     expectations.all? { |expectation| expectation.fulfilled? }
17:   end

[Source]

    # File lib/expectations/suite_results.rb, line 67
67:   def write_junit_xml(path)
68:     FileUtils.rm_rf path if File.exist?(path)
69:     FileUtils.mkdir_p path
70:     grouped_expectations = expectations.inject({}) do |result, expectation|
71:       result[expectation.file] = [] if result[expectation.file].nil?
72:       result[expectation.file] << expectation
73:       result
74:     end
75:     grouped_expectations.keys.each do |file_name|
76:       class_name = "#{File.basename(file_name, ".rb")}.xml"
77:       File.open("#{path}/TEST-#{class_name}", "w") do |file|
78:         file << '<?xml version="1.0" encoding="UTF-8" ?>'
79:         grouped_fulfilled = grouped_expectations[file_name].select { |expectation| expectation.fulfilled? }
80:         grouped_errors = grouped_expectations[file_name].select { |expectation| expectation.error? }
81:         grouped_failures = grouped_expectations[file_name].select { |expectation| expectation.failure? }
82:         file << %[<testsuite errors="#{grouped_errors.size}" skipped="0" tests="#{grouped_expectations[file_name].size}" time="0.00" failures="#{grouped_failures.size}" name="#{class_name}">]
83:         grouped_expectations[file_name].each do |expectation|
84:           file << %[<testcase time="0.0" name="line:#{expectation.line}">]
85:           file << %[<failure type="java.lang.AssertionError" message="#{ERB::Util.h(expectation.message)}"/>] if expectation.failure?
86:           file << %[</testcase>]
87:         end
88:         file << %[</testsuite>]
89:       end
90:     end
91:   end

[Validate]