2 ways to test Rails log messages with RSpec
13-Aug-2020 1738
One thing about writing about Rails for as long as I have is, sometimes I search online to see how to do something, and a post I wrote about it shows up in the first few results! Yet another reason to blog what you learn–you might forget it someday.Testing log messages is one of those things I don’t do on a regular basis, and always have to root around to find the answer. Which codebase was it again? Which test? And on top of that, there are two (that I know of) ways to do this!In this article, I’d like to share two approaches to this, along with a little exploration on how the two solutions differ. For the sake of simplicity, I’ll use an RSpec system spec–though in reality, I seldom test log messages unless there’s no other interface to test. In practice, this may be more useful for testing code used in a background job, for example, than in a web interface or API response.
2 ways to test Rails log messages with RSpec #ruby #rubydeveloper #rubyonrails #Rails #messages #RSpec #rspec #test https://rubyonrails.ba/link/2-ways-to-test-rails-log-messages-with-rspec