3
This question告訴我如何測試來自RSpec模型和控制器規格的記錄器語句。不幸的是,它似乎沒有從一個功能規範工作。有了這個代碼:如何從Rspec功能規格測試Rails日誌?
# controller.rb
def action
logger.info 'foobar'
end
# spec.rb
scenario 'logging should work' do
expect(Rails.logger).to receive(:info).with('foobar')
visit action_path
end
我得到的錯誤:
Failure/Error: visit action_path
#<ActiveSupport::Logger:0x007ff45b6e5ad0> received :info with unexpected arguments
expected: ("foobar")
got: (no args)
的test.log
文件不包含foobar
,因此它似乎在測試立即失敗,控制器動作有機會完成之前。
有什麼方法可以在功能規格中使用這種expect(Rails.logger)
語法?
任何答案嗎? – mooreds
這個答案可能有用:http://stackoverflow.com/questions/11770552/how-to-get-rails-logger-printing-to-the-console-stdout-when-running-rspec/32628272#32628272 – mooreds