Class: Cucumber::Formatter::Junit

Inherits:
Object
  • Object
show all
Includes:
Io
Defined in:
lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-8.0.0/lib/cucumber/formatter/junit.rb

Overview

The formatter used for --format junit

Defined Under Namespace

Classes: UnNamedFeatureError

Instance Method Summary collapse

Methods included from Io

ensure_dir, ensure_file, ensure_io, included, io?, url?

Constructor Details

#initialize(config) ⇒ Junit

Returns a new instance of Junit.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-8.0.0/lib/cucumber/formatter/junit.rb', line 22

def initialize(config)
  @ast_lookup = AstLookup.new(config)
  config.on_event :test_case_started, &method(:on_test_case_started)
  config.on_event :test_case_finished, &method(:on_test_case_finished)
  config.on_event :test_step_finished, &method(:on_test_step_finished)
  config.on_event :test_run_finished, &method(:on_test_run_finished)
  @reportdir = ensure_dir(config.out_stream, 'junit')
  @config = config
  @features_data = Hash.new do |h, k|
    h[k] = {
      feature: nil,
      failures: 0,
      errors: 0,
      tests: 0,
      skipped: 0,
      time: 0,
      builder: Builder::XmlMarkup.new(indent: 2)
    }
  end
end

Instance Method Details

#on_test_case_finished(event) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-8.0.0/lib/cucumber/formatter/junit.rb', line 60

def on_test_case_finished(event)
  test_case, result = *event.attributes
  result = result.with_filtered_backtrace(Cucumber::Formatter::BacktraceFilter)
  test_case_name = NameBuilder.new(test_case, @ast_lookup)
  scenario = test_case_name.scenario_name
  scenario_designation = "#{scenario}#{test_case_name.name_suffix}"
  output = create_output_string(test_case, scenario, result, test_case_name.row_name)
  build_testcase(result, scenario_designation, output)

  Interceptor::Pipe.unwrap! :stdout
  Interceptor::Pipe.unwrap! :stderr
end

#on_test_case_started(event) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-8.0.0/lib/cucumber/formatter/junit.rb', line 43

def on_test_case_started(event)
  test_case = event.test_case
  start_feature(test_case) unless same_feature_as_previous_test_case?(test_case)
  @failing_test_step = nil
  # In order to fill out <system-err/> and <system-out/>, we need to
  # intercept the $stderr and $stdout
  @interceptedout = Interceptor::Pipe.wrap(:stdout)
  @interceptederr = Interceptor::Pipe.wrap(:stderr)
end

#on_test_run_finished(_event) ⇒ Object



73
74
75
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-8.0.0/lib/cucumber/formatter/junit.rb', line 73

def on_test_run_finished(_event)
  @features_data.each { |_file, data| end_feature(data) }
end

#on_test_step_finished(event) ⇒ Object



53
54
55
56
57
58
# File 'lib/rubypitaya/app-template/vendor/bundle/ruby/3.1.0/gems/cucumber-8.0.0/lib/cucumber/formatter/junit.rb', line 53

def on_test_step_finished(event)
  test_step, result = *event.attributes
  return if @failing_test_step

  @failing_test_step = test_step unless result.ok?(@config.strict)
end