mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Provide default stub for Process.exit
Prevent terminating the process from within a test.
This commit is contained in:
parent
294bd61a25
commit
5f61a24656
2 changed files with 16 additions and 0 deletions
|
@ -1,4 +1,5 @@
|
|||
require "./mocks/*"
|
||||
require "./system_exit"
|
||||
|
||||
module Spectator
|
||||
# Functionality for mocking existing types.
|
||||
|
@ -11,3 +12,13 @@ module Spectator
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Add default stub to `exit` method.
|
||||
# This captures *most* (technically not all) attempts to exit the process.
|
||||
# This stub only takes effect in example code.
|
||||
# It intercepts `exit` calls and raises `Spectator::SystemExit` to prevent killing the test.
|
||||
class ::Process
|
||||
include ::Spectator::Mocks::Stubs
|
||||
|
||||
stub self.exit(code) { raise ::Spectator::SystemExit.new }
|
||||
end
|
||||
|
|
5
src/spectator/system_exit.cr
Normal file
5
src/spectator/system_exit.cr
Normal file
|
@ -0,0 +1,5 @@
|
|||
module Spectator
|
||||
# Exception raised when `exit` is called and intercepted from a stub.
|
||||
class SystemExit < Exception
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue