Class: 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_after_test_case(event) ⇒ Object
- #on_after_test_step(event) ⇒ Object
- #on_before_test_case(event) ⇒ Object
- #on_finished_testing(event) ⇒ Object
Methods included from Io
ensure_dir, ensure_file, ensure_io
Constructor Details
#initialize(config) ⇒ Junit
Returns a new instance of Junit.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/cucumber/formatter/junit.rb', line 20 def initialize(config) config.on_event :before_test_case, &method(:on_before_test_case) config.on_event :after_test_case, &method(:on_after_test_case) config.on_event :after_test_step, &method(:on_after_test_step) config.on_event :finished_testing, &method(:on_finished_testing) @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_after_test_case(event) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/cucumber/formatter/junit.rb', line 56 def on_after_test_case(event) test_case = event.test_case result = event.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_after_test_step(event) ⇒ Object
50 51 52 53 54 |
# File 'lib/cucumber/formatter/junit.rb', line 50 def on_after_test_step(event) return if @failing_step_source @failing_step_source = event.test_step.source.last unless event.result.ok?(@config.strict?) end |
#on_before_test_case(event) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/cucumber/formatter/junit.rb', line 38 def on_before_test_case(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_finished_testing(event) ⇒ Object
69 70 71 |
# File 'lib/cucumber/formatter/junit.rb', line 69 def on_finished_testing(event) @features_data.each { |file, data| end_feature(data) } end |