.
And if you could could go ahead and get a can of pesticide and take care
of the roach problem we’ve been having that would be great.
While as a general rule testing log output can make tests brittle because logs are free text and can change easily, there are certainly cases where testing them makes sense.
Our application was missing some really important business flow logging that we discovered was needed when we attempted to troubleshoot a production issue. We had to spend a significant amount of time hunting something down that would have been trivial to find in a well formatted info log message. I added that logging to the application and then wanted to make sure these business level log messages were being emitted at the right places in the application.
To test log messages in Padrino, I added the following helper to our spec/support/spec_helpers.rb file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
|
Now in your tests you can run test code and capture any log messages that happened during the code run!
1 2 3 4 5 6 7 |
|
Happy log testing!