You are writing a test.
It raises a well-known exception, and you check for it.
Suddenly, there’s log output, since you are working with some concurrent task. Your mood sinks. What’s the way to disable this library’s logging? In this case, I was kindly helped by the library’s author.
Quiet a Console.logger
in an RSpec test. Use an around
hook:
around do |example|
level = Console.logger.level
Console.logger.off!
example.run
Console.logger.level = level
end
First, store the existing level, in order to restore it after the test (aka example) has run.
Then, disable the logger and run the example.
Finally, restore the logger’s previous level.
The Console gem is amazing, and comes bundled with the Async gem. Well thought-out gems.
maybe use an ensure block to reset the log level?
That’s an excellent idea, Emil!