diff --git a/src/spectator/mocks/registry.cr b/src/spectator/mocks/registry.cr index 37af7ca..686fb98 100644 --- a/src/spectator/mocks/registry.cr +++ b/src/spectator/mocks/registry.cr @@ -70,6 +70,14 @@ module Spectator::Mocks fetch_type(object.class).expected.any?(&.callable?(call)) end + def exit_handled? : Bool + # Lazily check if an `exit` method was called and it was expected. + # This is okay since an `expect().to receive(:exit)` should check the details of the call. + (@entries.any? { |_key, entry| entry.expected.any? { |stub| stub.name == :exit } } || + @all_instances.any? { |_key, entry| entry.expected.any? { |stub| stub.name == :exit } }) && + @entries.any? { |_key, entry| entry.calls.any? { |call| call.name == :exit } } + end + def expect(object, stub : MethodStub) : Nil fetch_instance(object).expected.add(stub) end diff --git a/src/spectator/runnable_example.cr b/src/spectator/runnable_example.cr index be35c8f..43f4018 100644 --- a/src/spectator/runnable_example.cr +++ b/src/spectator/runnable_example.cr @@ -21,6 +21,7 @@ module Spectator run_example(result) @finished = true context.run_after_hooks(self) + result.error = nil if result.error.is_a?(SystemExit) && Harness.current.mocks.exit_handled? run_deferred(result) unless result.error end end