Last Updated: February 25, 2016
·
1.809K
· dpaluy

Stub Rails Logger

If you use Rails logger for production, you should do the following to make your test work:

let(:logger_mock) { double("Rails.logger").as_null_object }

it  "should ..." do
      Rails.stub_chain(:logger, :info).and_return(logger_mock)
      # code to be mocked
      #
      Rails.unstub(:logger)
end