diff --git a/lib/app_profiler.rb b/lib/app_profiler.rb index 655ac17..92383d4 100644 --- a/lib/app_profiler.rb +++ b/lib/app_profiler.rb @@ -100,6 +100,7 @@ def run(*args, backend: nil, **kwargs, &block) ) end yield + nil # no profile result ensure self.backend = original_backend if backend ProfileId::Current.reset diff --git a/test/app_profiler/run_test.rb b/test/app_profiler/run_test.rb index e4fde45..09f42ac 100644 --- a/test/app_profiler/run_test.rb +++ b/test/app_profiler/run_test.rb @@ -35,6 +35,17 @@ class RunTest < TestCase assert_operator profile.duration, :>=, 0.1 end + test ".run runs the block but does not return its result when the backend raises" do + ran = false + result = AppProfiler.run(backend: "not a real backend") do + ran = true + :block_value + end + + assert(ran) + assert_nil(result) + end + test ".run sets the backend then returns to the previous value" do orig_backend = AppProfiler.backend skip("Vernier not supported") unless AppProfiler.vernier_supported?