lib/cucumber/formatter/junit.rb in aslakhellesoy-cucumber-0.3.102.2 vs lib/cucumber/formatter/junit.rb in aslakhellesoy-cucumber-0.3.103

- old
+ new

@@ -1,93 +1,99 @@ require 'cucumber/formatter/ordered_xml_markup' module Cucumber module Formatter # The formatter used for <tt>--format junit</tt> - class Junit < Cucumber::Ast::Visitor - + class Junit def initialize(step_mother, io, options) - super(step_mother) raise "You *must* specify --out DIR for the junit formatter" unless String === io && File.directory?(io) @reportdir = io @options = options end - def visit_feature(feature) + def before_feature(feature) @failures = @errors = @tests = 0 @builder = OrderedXmlMarkup.new( :indent => 2 ) @time = 0 - super - + end + + def after_feature(feature) @testsuite = OrderedXmlMarkup.new( :indent => 2 ) @testsuite.instruct! @testsuite.testsuite( :failures => @failures, :errors => @errors, :tests => @tests, :time => "%.6f" % @time, - :name => @feature_name ) do + :name => @feature_name ) do @testsuite << @builder.target! end basename = File.basename(feature.file)[0...-File.extname(feature.file).length] feature_filename = File.join(@reportdir, "TEST-#{basename}.xml") File.open(feature_filename, 'w') { |file| file.write(@testsuite.target!) } end - def visit_background(name) + def before_background(*args) @in_background = true - super + end + + def after_background(*args) @in_background = false end - def visit_feature_name(name) + def feature_name(name) lines = name.split(/\r?\n/) @feature_name = lines[0].sub(/Feature\:/, '').strip end - def visit_scenario_name(keyword, name, file_colon_line, source_indent) + def scenario_name(keyword, name, file_colon_line, source_indent) scenario_name = name.strip.delete(".\r\n") scenario_name = "Unnamed scenario" if name.blank? @scenario = scenario_name @outline = keyword.include?('Scenario Outline') @output = "Scenario#{ " outline" if @outline}: #{@scenario}\n\n" end - def visit_steps(steps) + def before_steps(steps) + @steps_start = Time.now + end + + def after_steps(steps) return if @in_background - start = Time.now - super - duration = Time.now - start + duration = Time.now - @steps_start unless @outline if steps.failed? steps.each { |step| @output += "#{step.keyword} #{step.name}\n" } @output += "\nMessage:\n" end build_testcase(duration, steps.status, steps.exception) end end - def visit_outline_table(outline_table) + def before_outline_table(outline_table) @header_row = true - super(outline_table) end - def visit_table_row(table_row) + def before_table_row(table_row) if @outline - start = Time.now - super(table_row) - duration = Time.now - start + @table_start = Time.now + end + + @header_row = false + end + + def after_table_row(table_row) + if @outline + duration = Time.now - @table_start unless @header_row name_suffix = " (outline example : #{table_row.name})" if table_row.failed? @output += "Example row: #{table_row.name}\n" @output += "\nMessage:\n" end build_testcase(duration, table_row.status, table_row.exception, name_suffix) end - else - super(table_row) end @header_row = false end private