Class: AllureCucumber::CucumberFormatter

Inherits:
Object
  • Object
show all
Includes:
AllureCucumberModel
Defined in:
allure-cucumber/lib/allure_cucumber/formatter.rb

Overview

Main formatter class. Translates cucumber event to allure lifecycle

Constant Summary collapse

HOOK_HANDLERS =

Returns hook handler methods.

Returns:

  • (Hash)

    hook handler methods

{
  "Before hook" => :start_prepare_fixture,
  "After hook" => :start_tear_down_fixture,
}.freeze
ALLURE_STATUS =

Returns allure statuses mapping.

Returns:

  • (Hash)

    allure statuses mapping

{
  failed: Allure::Status::FAILED,
  skipped: Allure::Status::SKIPPED,
  passed: Allure::Status::PASSED,
}.freeze

Instance Method Summary collapse

Methods included from AllureCucumberModel

#failure_details, #fixture_result, #lifecycle, #step_result, #test_result

Methods included from TagParser

#issue_links, #severity, #status_detail_tags, #tag_labels, #tms_links

Methods included from AstTransformer

#example_row, #multiline_arg, #scenario, #step

Constructor Details

#initialize(config) ⇒ CucumberFormatter

Returns a new instance of CucumberFormatter.

Parameters:

  • config (Cucumber::Configuration)

23
24
25
26
27
28
29
30
31
32
33
# File 'allure-cucumber/lib/allure_cucumber/formatter.rb', line 23

def initialize(config)
  Allure.configure do |c|
    c.results_directory = config.out_stream if config.out_stream.is_a?(String)
  end

  config.on_event(:test_run_started, &method(:on_test_run_started))
  config.on_event(:test_case_started, &method(:on_test_case_started))
  config.on_event(:test_step_started, &method(:on_test_step_started))
  config.on_event(:test_step_finished, &method(:on_test_step_finished))
  config.on_event(:test_case_finished, &method(:on_test_case_finished))
end

Instance Method Details

#on_test_case_finished(event) ⇒ void

This method returns an undefined value.

Handle test case finished event

Parameters:

  • event (Cucumber::Core::Events::TestCaseFinished)

76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'allure-cucumber/lib/allure_cucumber/formatter.rb', line 76

def on_test_case_finished(event)
  failure_details = 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.message = 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

Parameters:

  • event (Cucumber::Core::Events::TestCaseStarted)

45
46
47
48
# File 'allure-cucumber/lib/allure_cucumber/formatter.rb', line 45

def on_test_case_started(event)
  lifecycle.start_test_container(Allure::TestResultContainer.new(name: event.test_case.name))
  lifecycle.start_test_case(test_result(event.test_case))
end

#on_test_run_started(_event) ⇒ void

This method returns an undefined value.

Clean test result directory before starting run

Parameters:

  • _event (Cucumber::Events::TestRunStarted<Type>)

38
39
40
# File 'allure-cucumber/lib/allure_cucumber/formatter.rb', line 38

def on_test_run_started(_event)
  lifecycle.clean_results_dir
end

#on_test_step_finished(event) ⇒ void

This method returns an undefined value.

Handle test step finished event

Parameters:

  • event (Cucumber::Core::Events::TestStepFinished)

60
61
62
63
64
65
66
67
68
69
70
71
# File 'allure-cucumber/lib/allure_cucumber/formatter.rb', line 60

def on_test_step_finished(event)
  return if prepare_world_hook?(event.test_step)

  update_block = proc do |step|
    step.stage = Allure::Stage::FINISHED
    step.status = ALLURE_STATUS.fetch(event.result.to_sym, Allure::Status::BROKEN)
  end
  step_type = hook?(event.test_step) ? "fixture" : "test_step"

  lifecycle.public_send("update_#{step_type}", &update_block)
  lifecycle.public_send("stop_#{step_type}")
end

#on_test_step_started(event) ⇒ void

This method returns an undefined value.

Handle test step started event

Parameters:

  • event (Cucumber::Core::Events::TestStepStarted)

53
54
55
# File 'allure-cucumber/lib/allure_cucumber/formatter.rb', line 53

def on_test_step_started(event)
  hook?(event.test_step) ? handle_hook_started(event.test_step) : handle_step_started(event.test_step)
end