mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Enable Mocks for tests
This commit is contained in:
parent
48a8408930
commit
678f85eac1
2 changed files with 12 additions and 5 deletions
|
@ -68,8 +68,11 @@ module Spectator
|
||||||
# Silence default logger.
|
# Silence default logger.
|
||||||
::Log.setup_from_env(default_level: :none)
|
::Log.setup_from_env(default_level: :none)
|
||||||
|
|
||||||
# Build the spec and run it.
|
# Build the spec.
|
||||||
spec = DSL::Builder.build
|
spec = DSL::Builder.build
|
||||||
|
|
||||||
|
# Run the spec with mocks enabled.
|
||||||
|
Mocks.enable
|
||||||
spec.run
|
spec.run
|
||||||
rescue ex
|
rescue ex
|
||||||
# Re-enable logger for fatal error.
|
# Re-enable logger for fatal error.
|
||||||
|
@ -82,6 +85,8 @@ module Spectator
|
||||||
# So we display a helpful error that could be reported and return non-zero.
|
# So we display a helpful error that could be reported and return non-zero.
|
||||||
Log.fatal(exception: ex) { "Spectator encountered an unexpected error" }
|
Log.fatal(exception: ex) { "Spectator encountered an unexpected error" }
|
||||||
false
|
false
|
||||||
|
ensure
|
||||||
|
Mocks.disable
|
||||||
end
|
end
|
||||||
|
|
||||||
# Global configuration used by Spectator for running tests.
|
# Global configuration used by Spectator for running tests.
|
||||||
|
|
|
@ -136,12 +136,14 @@ module Spectator
|
||||||
# Yields to run the test code and returns information about the outcome.
|
# Yields to run the test code and returns information about the outcome.
|
||||||
# Returns a tuple with the elapsed time and an error if one occurred (otherwise nil).
|
# Returns a tuple with the elapsed time and an error if one occurred (otherwise nil).
|
||||||
private def capture(&) : Tuple(Time::Span, Exception?)
|
private def capture(&) : Tuple(Time::Span, Exception?)
|
||||||
|
Mocks::Scope.push do
|
||||||
error = nil
|
error = nil
|
||||||
elapsed = Time.measure do
|
elapsed = Time.measure do
|
||||||
error = catch { yield }
|
error = catch { yield }
|
||||||
end
|
end
|
||||||
{elapsed, error}
|
{elapsed, error}
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# Yields to run a block of code and captures exceptions.
|
# Yields to run a block of code and captures exceptions.
|
||||||
# If the block of code raises an error, the error is caught and returned.
|
# If the block of code raises an error, the error is caught and returned.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue