Class: AllureRspec::RSpecFormatter

Inherits:
RSpec::Core::Formatters::BaseFormatter
  • Object
show all
Includes:
Utils
Defined in:
allure-rspec/lib/allure_rspec/formatter.rb

Overview

Main rspec formatter class translating rspec events to allure lifecycle

Constant Summary collapse

ALLURE_STATUS =

Returns allure statuses mapping.

Returns:

  • (Hash)

    allure statuses mapping

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

Instance Method Summary collapse

Methods included from Utils

#strip_relative

Constructor Details

#initialize(output) ⇒ RSpecFormatter

Returns a new instance of RSpecFormatter.



37
38
39
40
41
42
# File 'allure-rspec/lib/allure_rspec/formatter.rb', line 37

def initialize(output)
  super

  @allure_config = AllureRspec.configuration
  Allure.lifecycle = @lifecycle = Allure::AllureLifecycle.new(@allure_config)
end

Instance Method Details

#example_finished(example_notification) ⇒ void

This method returns an undefined value.

Finishes example

Parameters:

  • example_notification (RSpec::Core::Notifications::ExampleNotification)


83
84
85
86
# File 'allure-rspec/lib/allure_rspec/formatter.rb', line 83

def example_finished(example_notification)
  lifecycle.update_test_case(&update_test_proc(example_notification.example.execution_result))
  lifecycle.stop_test_case
end

#example_group_finished(_example_group_notification) ⇒ void

This method returns an undefined value.

Starts example group

Parameters:

  • _example_group_notification (RSpec::Core::Notifications::GroupNotification)


91
92
93
# File 'allure-rspec/lib/allure_rspec/formatter.rb', line 91

def example_group_finished(_example_group_notification)
  lifecycle.stop_test_container
end

#example_group_started(example_group_notification) ⇒ void

This method returns an undefined value.

Starts example group

Parameters:

  • example_group_notification (RSpec::Core::Notifications::GroupNotification)


66
67
68
69
70
71
# File 'allure-rspec/lib/allure_rspec/formatter.rb', line 66

def example_group_started(example_group_notification)
  description = example_group_notification.group.description.then do |desc|
    desc.empty? ? "Anonymous" : desc
  end
  lifecycle.start_test_container(Allure::TestResultContainer.new(name: description))
end

#example_started(example_notification) ⇒ void

This method returns an undefined value.

Starts example

Parameters:

  • example_notification (RSpec::Core::Notifications::ExampleNotification)


76
77
78
# File 'allure-rspec/lib/allure_rspec/formatter.rb', line 76

def example_started(example_notification)
  lifecycle.start_test_case(test_result(example_notification.example))
end

#start(_start_notification) ⇒ void

This method returns an undefined value.

Start test run

Parameters:

  • _start_notification (RSpec::Core::Notifications::StartNotification)


47
48
49
50
51
52
53
54
# File 'allure-rspec/lib/allure_rspec/formatter.rb', line 47

def start(_start_notification)
  lifecycle.clean_results_dir
  lifecycle.write_categories

  RSpec::Core::Example.class_eval do
    include Allure
  end
end

#stop(_stop_notification) ⇒ void

This method returns an undefined value.

Start test run

Parameters:

  • _stop_notification (RSpec::Core::Notifications::StopNotification)


59
60
61
# File 'allure-rspec/lib/allure_rspec/formatter.rb', line 59

def stop(_stop_notification)
  lifecycle.write_environment
end