NoMethodError:警告:模块的未定义方法“忽略”

时间:2020-08-13 15:36:37

标签: ruby testing ruby-on-rails-4

我找不到此错误的任何解释,但是在运行时: rake testbundle exec rake test我得到:

NoMethodError: undefined method `ignore' for Warning:Module
/Users/przemyslaw/projects/writefully/config/initializers/warning.rb:4:in `block in <top (required)>'
/Users/przemyslaw/projects/writefully/config/initializers/warning.rb:3:in `each'
/Users/przemyslaw/projects/writefully/config/initializers/warning.rb:3:in `<top (required)>'
/Users/przemyslaw/projects/writefully/config/environment.rb:5:in `<top (required)>'
/Users/przemyslaw/projects/writefully/test/test_helper.rb:2:in `require'
/Users/przemyslaw/projects/writefully/test/test_helper.rb:2:in `<top (required)>'
/Users/przemyslaw/projects/writefully/test/controllers/comments_controller_test.rb:1:in `require'
/Users/przemyslaw/projects/writefully/test/controllers/comments_controller_test.rb:1:in `<top (required)>'
Tasks: TOP => test:run
(See full trace by running task with --trace)

我正在关注codemy.net上的教程,并且该项目没有任何复杂或特殊之处。我只生成了一个新的Rails应用程序,几个模型和控制器,现在当我尝试运行测试时,它给了我这个错误。目前,我的测试文件中没有任何测试,因此与测试无关。似乎警告文件中的'ignore'方法存在一些问题:

config / initializers / warning.rb

# Rails will load this logic before booting up Rails server
unless Rails.env.development?
  Gem.path.each do |path|
    Warning.ignore(//, path)
  end
end

任何帮助或想法将不胜感激。我正在使用Rails 4.2.10和ruby 2.5.8。

1 个答案:

答案 0 :(得分:2)

好像您错过了安装warning gem一样。

我建议添加行

gem "warning"

转到您的Gemfile并运行bundler,然后重新启动应用程序。