Test Rails log messages with RSpec
Have you wondered how to test your Rails log messages?
Try this:
it "logs a message" do
allow(Rails.logger).to receive(:info)
expect(Rails.logger).to receive(:info).with("Someone read this post!")
visit root_path
expect(page).to have_content "Welcome to TIL"
end
Or this:
it "logs a message" do
allow(Rails.logger).to receive(:info)
visit root_path
expect(page).to have_content "Welcome to TIL"
expect(Rails.logger).to have_received(:info).with("Someone read this post!")
end