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