I am trying to test that the Rails logger receives messages in some of my specs. I am using the Logging gem.
Let\'s say that I have a class like this:
If your goal is to test logging functionality you may also consider verifying the output to standard streams.
This will spare you the mocking process and test whether messages will actually end up where they supposed to (STDOUT/STDERR).
With RSpec's output matcher (introduced in 3.0) you can do the following:
expect { my_method }.to output("my message").to_stdout
expect { my_method }.to output("my error").to_stderr
In case of libraries such as Logger or Logging you may have to use output.to_<>_from_any_process.