lib/tests_formatter.rb in continuous4r-0.0.1 vs lib/tests_formatter.rb in continuous4r-0.0.2

- old
+ new

@@ -4,61 +4,28 @@ # Classe de formatage des resultats renvoyes par les # differents tests unitaires # Author: Vincent Dubois # ===================================================== class TestsFormatter - attr_accessor :params - - # Constructeur - def initialize params - self.params = params - end - # Methode qui permet de fabriquer le flux HTML a partir des flux console # de tests unitaires def to_html html = "<table class='bodyTable'><thead><th>Testing element</th><th>Pass</th><th>Result</th></thead><tbody>" i = 0 - self.params.each('runner') do |runner| - puts " Running #{runner['type']} tests..." - pass = true - html = html + "<tr class='#{ i % 2 == 0 ? 'a' : 'b'}'><td><strong>#{runner['type']}</strong></td>" - case runner['type'] - when "units" - pass = system("rake test:units > test_units.log") - if !pass - puts " #{File.read("test_units.log")}" - raise " BUILD FAILED." - end - html = html + "<td style='text-align: center;'><img src='images/icon_#{pass ? 'success' : 'error'}_sml.gif'/></td>" - html = html + "<td><pre>#{File.read("test_units.log")}</pre></td></tr>" - when "functionals" - pass = system("rake test:functionals > test_functionals.log") - if !pass - puts " #{File.read("test_functionals.log")}" - raise " BUILD FAILED." - end - html = html + "<td style='text-align: center;'><img src='images/icon_#{pass ? 'success' : 'error'}_sml.gif'/></td>" - html = html + "<td><pre>#{File.read("test_functionals.log")}</pre></td></tr>" - when "integration" - pass = system("rake test:integration > test_integration.log") - if !pass - puts " #{File.read("test_integration.log")}" - raise " BUILD FAILED." - end - html = html + "<td style='text-align: center;'><img src='images/icon_#{pass ? 'success' : 'error'}_sml.gif'/></td>" - html = html + "<td><pre>#{File.read("test_integration.log")}</pre></td></tr>" - when "rspec" - pass = system("rake spec > test_rspec.log") - if !pass - puts " #{File.read("test_rspec.log")}" - raise " BUILD FAILED." - end - html = html + "<td style='text-align: center;'><img src='images/icon_#{pass ? 'success' : 'error'}_sml.gif'/></td>" - html = html + "<td><pre>#{File.read("test_rspec.log").gsub(/\[32m|\[0m|\[31m/,"")}</pre></td></tr>" - else - raise " Don't know how to run '#{runner['type']}' test.\n BUILD FAILED." + project = XmlElements.fromString(File.read("continuous4r-project.xml")) + ['units','functionals','integration'].each do |runner| + puts " Running #{runner} tests..." + html = html + "<tr class='#{ i % 2 == 0 ? 'a' : 'b'}'><td><strong>#{runner}</strong></td>" + result = Utils.run_command("rake test:#{runner}") + passed = (result.index("Failure:").nil? and result.index("Error:").nil? and result.index("pending migrations").nil? and result.split(/$/).length > 1) + if project['ignore-tests-failures'] == "false" and passed == false + raise " #{runner} tests failed.\n BUILD FAILED." end + f = File.open("#{Continuous4r::WORK_DIR}/test_#{runner}.log", "w") + f.write(result) + f.close + html = html + "<td style='text-align: center;'><img src='images/icon_#{passed ? 'success' : 'error'}_sml.gif'/></td>" + html = html + "<td><pre>#{File.read("#{Continuous4r::WORK_DIR}/test_#{runner}.log")}</pre></td></tr>" i = i + 1 end html = html + "</tbody></table>" end end