Check for and allow expected exits

This commit is contained in:
Michael Miller 2021-07-10 19:27:01 -06:00
parent 35cb0b527e
commit e47ae613a5
No known key found for this signature in database
GPG key ID: FB9F12F7C646A4AD
2 changed files with 9 additions and 0 deletions

View file

@ -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

View file

@ -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