Class: AllureCucumber::CucumberFormatter
- Inherits:
-
Object
- Object
- AllureCucumber::CucumberFormatter
- Defined in:
- lib/allure_cucumber/formatter.rb
Overview
Main formatter class. Translates cucumber event to allure lifecycle
Constant Summary collapse
- HOOK_HANDLERS =
Returns hook handler methods.
{ "Before hook" => :start_prepare_fixture, "After hook" => :start_tear_down_fixture }.freeze
- ALLURE_STATUS =
Returns allure statuses mapping.
{ failed: Allure::Status::FAILED, skipped: Allure::Status::SKIPPED, passed: Allure::Status::PASSED }.freeze
Instance Method Summary collapse
-
#initialize(config) ⇒ CucumberFormatter
constructor
A new instance of CucumberFormatter.
-
#on_test_case_finished(event) ⇒ void
Handle test case finished event.
-
#on_test_case_started(event) ⇒ void
Handle test case started event.
-
#on_test_run_finished(_event) ⇒ void
Clean test result directory before starting run.
-
#on_test_run_started(_event) ⇒ void
Clean test result directory before starting run.
-
#on_test_step_finished(event) ⇒ void
Handle test step finished event.
-
#on_test_step_started(event) ⇒ void
Handle test step started event.
Constructor Details
#initialize(config) ⇒ CucumberFormatter
Returns a new instance of CucumberFormatter.
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/allure_cucumber/formatter.rb', line 21 def initialize(config) allure_config = AllureCucumber.configuration allure_config.results_directory = config.out_stream if config.out_stream.is_a?(String) Allure.lifecycle = @lifecycle = Allure::AllureLifecycle.new(allure_config) @cucumber_model ||= AllureCucumberModel.new(config, allure_config) names = Allure::TestPlan.test_names config.name_regexps.push(*names.map { |name| /#{name}/ }) if names config.on_event(:test_run_started) { |event| on_test_run_started(event) } config.on_event(:test_run_finished) { |event| on_test_run_finished(event) } config.on_event(:test_case_started) { |event| on_test_case_started(event) } config.on_event(:test_step_started) { |event| on_test_step_started(event) } config.on_event(:test_step_finished) { |event| on_test_step_finished(event) } config.on_event(:test_case_finished) { |event| on_test_case_finished(event) } end |
Instance Method Details
#on_test_case_finished(event) ⇒ void
This method returns an undefined value.
Handle test case finished event
86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/allure_cucumber/formatter.rb', line 86 def on_test_case_finished(event) failure_details = cucumber_model.failure_details(event.result) status = ALLURE_STATUS.fetch(event.result.to_sym, Allure::Status::BROKEN) lifecycle.update_test_case do |test_case| test_case.stage = Allure::Stage::FINISHED test_case.status = event.result.failed? ? Allure::ResultUtils.status(event.result&.exception) : status test_case.status_details.flaky = event.result.flaky? test_case.status_details. = failure_details[:message] test_case.status_details.trace = failure_details[:trace] end lifecycle.stop_test_case lifecycle.stop_test_container end |
#on_test_case_started(event) ⇒ void
This method returns an undefined value.
Handle test case started event
58 59 60 61 |
# File 'lib/allure_cucumber/formatter.rb', line 58 def on_test_case_started(event) lifecycle.start_test_container(Allure::TestResultContainer.new(name: event.test_case.name)) lifecycle.start_test_case(cucumber_model.test_result(event.test_case)) end |
#on_test_run_finished(_event) ⇒ void
This method returns an undefined value.
Clean test result directory before starting run
51 52 53 |
# File 'lib/allure_cucumber/formatter.rb', line 51 def on_test_run_finished(_event) lifecycle.write_environment end |
#on_test_run_started(_event) ⇒ void
This method returns an undefined value.
Clean test result directory before starting run
43 44 45 46 |
# File 'lib/allure_cucumber/formatter.rb', line 43 def on_test_run_started(_event) lifecycle.clean_results_dir lifecycle.write_categories end |
#on_test_step_finished(event) ⇒ void
This method returns an undefined value.
Handle test step finished event
73 74 75 76 77 78 79 80 81 |
# File 'lib/allure_cucumber/formatter.rb', line 73 def on_test_step_finished(event) status = ALLURE_STATUS.fetch(event.result.to_sym, Allure::Status::BROKEN) update_block = proc do |step| step.stage = Allure::Stage::FINISHED step.status = event.result.failed? ? Allure::ResultUtils.status(event.result&.exception) : status end event.test_step.hook? ? handle_hook_finished(event.test_step, update_block) : handle_step_finished(update_block) end |
#on_test_step_started(event) ⇒ void
This method returns an undefined value.
Handle test step started event
66 67 68 |
# File 'lib/allure_cucumber/formatter.rb', line 66 def on_test_step_started(event) event.test_step.hook? ? handle_hook_started(event.test_step) : handle_step_started(event.test_step) end |