em09ya
Last Updated: February 25, 2016
·
886
· dpaluy
3129de6b479cc965513311f1ddcc268a

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
Say Thanks
Respond