From 4eb00e39777b365b0cc72d282b8b6e27e7053014 Mon Sep 17 00:00:00 2001 From: kamalakannan chockalingam Date: Tue, 16 Apr 2024 13:33:12 +0530 Subject: [PATCH] Fixing category page 404 error due to exception message being passed as nil (#546) * Adding initital commits * addressing review comment --- allure-rspec/spec/unit/formatter_example_finished_spec.rb | 2 +- allure-ruby-commons/lib/allure_ruby_commons/result_utils.rb | 2 +- allure-ruby-commons/spec/unit/result_utils_spec.rb | 6 ++++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/allure-rspec/spec/unit/formatter_example_finished_spec.rb b/allure-rspec/spec/unit/formatter_example_finished_spec.rb index cf531311..bfe2eaa6 100644 --- a/allure-rspec/spec/unit/formatter_example_finished_spec.rb +++ b/allure-rspec/spec/unit/formatter_example_finished_spec.rb @@ -36,7 +36,7 @@ aggregate_failures "Should update correct test case parameters" do expect(@test_case.stage).to eq(Allure::Stage::FINISHED) expect(@test_case.status).to eq(Allure::Status::PASSED) - expect(@test_case.status_details).to eq(Allure::StatusDetails.new) + expect(@test_case.status_details).to eq(Allure::StatusDetails.new(message: "NilClass")) end end end diff --git a/allure-ruby-commons/lib/allure_ruby_commons/result_utils.rb b/allure-ruby-commons/lib/allure_ruby_commons/result_utils.rb index be9dc961..fee8c19d 100644 --- a/allure-ruby-commons/lib/allure_ruby_commons/result_utils.rb +++ b/allure-ruby-commons/lib/allure_ruby_commons/result_utils.rb @@ -159,7 +159,7 @@ def status(exception) # @param [Exception] exception # @return [Allure::StatusDetails] def status_details(exception) - StatusDetails.new(message: exception&.message, trace: exception&.backtrace&.join("\n")) + StatusDetails.new(message: exception&.message || exception.class.name, trace: exception&.backtrace&.join("\n")) end # Allure attachment object diff --git a/allure-ruby-commons/spec/unit/result_utils_spec.rb b/allure-ruby-commons/spec/unit/result_utils_spec.rb index 6e8ff807..867ca40a 100644 --- a/allure-ruby-commons/spec/unit/result_utils_spec.rb +++ b/allure-ruby-commons/spec/unit/result_utils_spec.rb @@ -93,4 +93,10 @@ def raise_multi_error expect(status_details.message).to include("Got 2 failures from failure aggregation block") expect(status_details.trace).not_to be_empty end + + it "returns status details for nill class error" do + status_details = Allure::ResultUtils.status_details(nil) + expect(status_details.message).to eq("NilClass") + expect(status_details.instance_variable_defined?(:@trace)).to be_truthy + end end