mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Check for and allow expected exits
This commit is contained in:
parent
35cb0b527e
commit
e47ae613a5
2 changed files with 9 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue