Class: Cucumber::Formatter::Junit
- Inherits:
-
Object
- Object
- Cucumber::Formatter::Junit
- Includes:
- Io
- Defined in:
- lib/cucumber/formatter/junit.rb
Overview
The formatter used for --format junit
Defined Under Namespace
Classes: UnNamedFeatureError
Instance Method Summary collapse
-
#initialize(config) ⇒ Junit
constructor
A new instance of Junit.
- #on_test_case_finished(event) ⇒ Object
- #on_test_case_started(event) ⇒ Object
- #on_test_run_finished(_event) ⇒ Object
- #on_test_step_finished(event) ⇒ Object
Methods included from Io
ensure_dir, ensure_file, ensure_io
Constructor Details
#initialize(config) ⇒ Junit
Returns a new instance of Junit.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/cucumber/formatter/junit.rb', line 21 def initialize(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 { |h,k| h[k] = { feature: nil, failures: 0, errors: 0, tests: 0, skipped: 0, time: 0, builder: Builder::XmlMarkup.new(:indent => 2) }} end |
Instance Method Details
#on_test_case_finished(event) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/cucumber/formatter/junit.rb', line 58 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) 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
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/cucumber/formatter/junit.rb', line 39 def on_test_case_started(event) test_case = event.test_case unless same_feature_as_previous_test_case?(test_case.feature) start_feature(test_case.feature) end @failing_step_source = 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
71 72 73 |
# File 'lib/cucumber/formatter/junit.rb', line 71 def on_test_run_finished(_event) @features_data.each { |file, data| end_feature(data) } end |
#on_test_step_finished(event) ⇒ Object
51 52 53 54 55 56 |
# File 'lib/cucumber/formatter/junit.rb', line 51 def on_test_step_finished(event) test_step, result = *event.attributes return if @failing_step_source @failing_step_source = test_step.source.last unless result.ok?(@config.strict) end |