gpt4 book ai didi

ruby-on-rails - 使用 rspec 确保记录器被调用

转载 作者:行者123 更新时间:2023-11-28 19:54:42 25 4
gpt4 key购买 nike

我正在尝试在应该引发错误并记录错误的特定条件下测试我的 Rails 应用程序中的 Controller 。我的 raise 测试运行良好,但我想确保记录器被调用,到目前为止我试过了,但它不起作用

  it 'logs the error' do
get 'edit', {:id => 'banana'}
Logger.any_instance.expects(:error)
end

ps 我用的是 Mocha

最佳答案

对于rails 4,正确的做法如下

expect(Rails.logger).to receive(:error).with("your error message")

关于ruby-on-rails - 使用 rspec 确保记录器被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7211176/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com