Class: Cucumber::Formatter::Junit

Inherits:
Ast::Visitor show all
Defined in:
lib/cucumber/formatter/junit.rb

Instance Attribute Summary

Attributes inherited from Ast::Visitor

#options, #step_mother

Instance Method Summary collapse

Methods inherited from Ast::Visitor

#announce, #matches_scenario_names?, #visit_background, #visit_background_name, #visit_comment, #visit_comment_line, #visit_examples, #visit_examples_array, #visit_examples_name, #visit_exception, #visit_feature_element, #visit_features, #visit_multiline_arg, #visit_outline_table, #visit_py_string, #visit_step, #visit_step_name, #visit_table_cell, #visit_table_cell_value, #visit_table_row, #visit_tag_name, #visit_tags

Constructor Details

#initialize(step_mother, io, options) ⇒ Junit

Returns a new instance of Junit.



12
13
14
15
16
17
# File 'lib/cucumber/formatter/junit.rb', line 12

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

Instance Method Details

#visit_feature(feature) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/cucumber/formatter/junit.rb', line 19

def visit_feature(feature)
  @failures = @errors = @tests = 0
  @builder = Builder::XmlMarkup.new( :indent => 2 )
  super

  @testsuite = Builder::XmlMarkup.new( :indent => 2 )
  @testsuite.instruct!
  @testsuite.testsuite(
    :failures => @failures,
    :errors => @errors,
    :tests => @tests,
    :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

#visit_feature_name(name) ⇒ Object



39
40
41
42
# File 'lib/cucumber/formatter/junit.rb', line 39

def visit_feature_name(name)
  lines = name.split(/\r?\n/)
  @feature_name = lines[0].sub(/Feature\:/, '').strip
end

#visit_scenario_name(keyword, name, file_colon_line, source_indent) ⇒ Object



44
45
46
# File 'lib/cucumber/formatter/junit.rb', line 44

def visit_scenario_name(keyword, name, file_colon_line, source_indent)
  @scenario = name
end

#visit_step_result(keyword, step_match, multiline_arg, status, exception, source_indent, background) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/cucumber/formatter/junit.rb', line 55

def visit_step_result(keyword, step_match, multiline_arg, status, exception, source_indent, background)
  step_name = keyword + " " + step_match.format_args(lambda{|param| "*#{param}*"})
  @builder.testcase(:classname => "#{@feature_name}.#{@scenario}", :name => step_name) do
    if status != :passed
      @builder.failure(:message => step_name) do
        @builder.text!(format_exception(exception)) if exception
      end
      @steps_failed = true
    end
  end
end

#visit_steps(steps) ⇒ Object



48
49
50
51
52
53
# File 'lib/cucumber/formatter/junit.rb', line 48

def visit_steps(steps)
  @steps_failed = false
  super
  @failures += 1 if @steps_failed
  @tests += 1
end