Module: Evergreen::Reports
- Defined in:
- lib/evergreen/reports.rb
Class Method Summary collapse
- .collect_data(suite) ⇒ Object
- .dir ⇒ Object
- .filename(spec_result, index) ⇒ Object
- .find_filename(spec_result) ⇒ Object
- .publish!(suite) ⇒ Object
- .publish_spec(spec_result) ⇒ Object
Class Method Details
.collect_data(suite) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/evergreen/reports.rb', line 14 def self.collect_data(suite) # open new reporter runners = suite.runner.instance_eval('spec_runners') result_data = runners.map do |specrunner| { :name => specrunner.spec.name, :passed => specrunner.spec.passed?, :results => specrunner.examples.map { |r| row = r.instance_variable_get("@row") hash = {} row.each {|k,v| hash[k] = v} hash } } end end |
.dir ⇒ Object
10 11 12 |
# File 'lib/evergreen/reports.rb', line 10 def self.dir ENV['CI_REPORTS'] || File.("#{Dir.getwd}/reports") end |
.filename(spec_result, index) ⇒ Object
6 7 8 |
# File 'lib/evergreen/reports.rb', line 6 def self.filename(spec_result, index) File.join(dir, "#{spec_result[:name]}.#{index}.xml") end |
.find_filename(spec_result) ⇒ Object
31 32 33 34 35 36 37 |
# File 'lib/evergreen/reports.rb', line 31 def self.find_filename(spec_result) index = 0 while File.exists?(filename(spec_result, index)) index = index + 1 end filename(spec_result, index) end |
.publish!(suite) ⇒ Object
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/evergreen/reports.rb', line 68 def self.publish!(suite) result_data = collect_data(suite) FileUtils.rm_rf(dir) FileUtils.mkdir_p(dir) result_data.each do |spec_result| publish_spec(spec_result) end end |
.publish_spec(spec_result) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/evergreen/reports.rb', line 39 def self.publish_spec(spec_result) File.open(find_filename(spec_result), "w") do |f| builder = Builder::XmlMarkup.new(:target => f, :indent => 2, :escape_attrs => true) builder.instruct! tests = 0 failures = 0 spec_result[:results].each do |result| tests = tests + 1 failures = failures + 1 unless result['passed'] end builder.testsuite({:name => spec_result[:name], :tests => tests, :failures => failures}) do spec_result[:results].each do |result| builder.testcase({'name' => "#{spec_result[:name]} - #{result['name']}"}) do unless result['passed'] builder.failure(:message => result['message']) do builder.text!('Failed: '+result['name']+' '+result['message']) if result['trace'] builder.text!(" -> in #{result['trace']['fileName']}:#{result['trace']['lineNumber']}") end end end end end end end end |