From a76a91c49120f17c6e919eb5216eaba3e621feb7 Mon Sep 17 00:00:00 2001 From: Herwin Date: Sat, 8 Jun 2024 14:33:28 +0200 Subject: [PATCH] Add test for rescue with safe navigator setter on nil There was a test with the safe navigator setter, but only in the case where the target is not nil. --- language/rescue_spec.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/language/rescue_spec.rb b/language/rescue_spec.rb index a3ee4807a..4dc25a5b4 100644 --- a/language/rescue_spec.rb +++ b/language/rescue_spec.rb @@ -52,6 +52,16 @@ class ArbitraryException < StandardError RescueSpecs::SafeNavigationSetterCaptor.should_capture_exception end + it 'using a safely navigated setter method on a nil target' do + target = nil + begin + raise SpecificExampleException, "Raising this to be handled below" + rescue SpecificExampleException => target&.captured_error + :caught + end.should == :caught + target.should be_nil + end + it 'using a setter method' do RescueSpecs::SetterCaptor.should_capture_exception end