class AllureRspec::RSpecFormatter
Main rspec formatter class translating rspec events to allure lifecycle
Constants
- ALLURE_STATUS
@return [Hash] allure statuses mapping
Attributes
Public Class Methods
# File lib/allure_rspec/formatter.rb, line 37 def initialize(output) super @allure_config = AllureRspec.configuration Allure.lifecycle = @lifecycle = Allure::AllureLifecycle.new(@allure_config) end
Public Instance Methods
Finishes example @param [RSpec::Core::Notifications::ExampleNotification] example_notification @return [void]
# File 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
Starts example group @param [RSpec::Core::Notifications::GroupNotification] _example_group_notification @return [void]
# File lib/allure_rspec/formatter.rb, line 91 def example_group_finished(_example_group_notification) lifecycle.stop_test_container end
Starts example group @param [RSpec::Core::Notifications::GroupNotification] example_group_notification @return [void]
# File lib/allure_rspec/formatter.rb, line 66 def example_group_started(example_group_notification) description = example_group_notification.group.description.yield_self do |desc| desc.empty? ? "Anonymous" : desc end lifecycle.start_test_container(Allure::TestResultContainer.new(name: description)) end
Starts example @param [RSpec::Core::Notifications::ExampleNotification] example_notification @return [void]
# File lib/allure_rspec/formatter.rb, line 76 def example_started(example_notification) lifecycle.start_test_case(test_result(example_notification.example)) end
Start test run @param [RSpec::Core::Notifications::StartNotification] _start_notification @return [void]
# File 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
Start test run @param [RSpec::Core::Notifications::StopNotification] _stop_notification @return [void]
# File lib/allure_rspec/formatter.rb, line 59 def stop(_stop_notification) lifecycle.write_environment end
Private Instance Methods
Get allure status from result @param [RSpec::Core::Example::ExecutionResult] result @return [Symbol]
# File lib/allure_rspec/formatter.rb, line 135 def status(result) return Allure::ResultUtils.status(result.exception) if result.status == :failed ALLURE_STATUS[result.status] end
Transform example to <Allure::TestResult> @param [RSpec::Core::Example] example @return [Allure::TestResult]
# File lib/allure_rspec/formatter.rb, line 102 def test_result(example) parser = RspecMetadataParser.new(example, allure_config) Allure::TestResult.new( name: example.description, description: "Location - #{strip_relative(example.location)}", description_html: "Location - #{strip_relative(example.location)}", history_id: example.id, full_name: example.full_description, labels: parser.labels, links: parser.links, status_details: parser.status_details, environment: allure_config.environment ) end
Update test status on finish @param [RSpec::Core::Example::ExecutionResult] result @return [Proc]
# File lib/allure_rspec/formatter.rb, line 121 def update_test_proc(result) Allure::ResultUtils.status_details(result.exception).yield_self do |status_detail| proc do |test_case| test_case.stage = Allure::Stage::FINISHED test_case.status = status(result) test_case.status_details.message = status_detail.message test_case.status_details.trace = status_detail.trace end end end