Rails 5.1.4 测试仅在测试失败时抛出NameError
Rails 5.1.4 test throws NameError only when testing fails
当 运行 rails 测试失败时,在 5.1.4 rails 应用程序中它会抛出以下 NameError。
Traceback (most recent call last):
27: from -e:1:in `<main>'
26: from /Users/User/.rvm/rubies/ruby-2.5.0/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
25: from /Users/User/.rvm/rubies/ruby-2.5.0/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
24: from /Users/User/.rvm/gems/ruby-2.5.0/gems/spring-2.0.2/lib/spring/application/boot.rb:19:in `<top (required)>'
23: from /Users/User/.rvm/gems/ruby-2.5.0/gems/spring-2.0.2/lib/spring/application.rb:135:in `run'
22: from /Users/User/.rvm/gems/ruby-2.5.0/gems/spring-2.0.2/lib/spring/application.rb:135:in `loop'
21: from /Users/User/.rvm/gems/ruby-2.5.0/gems/spring-2.0.2/lib/spring/application.rb:141:in `block in run'
20: from /Users/User/.rvm/gems/ruby-2.5.0/gems/spring-2.0.2/lib/spring/application.rb:171:in `serve'
19: from /Users/User/.rvm/gems/ruby-2.5.0/gems/spring-2.0.2/lib/spring/application.rb:171:in `fork'
18: from /Users/User/.rvm/gems/ruby-2.5.0/gems/minitest-5.11.1/lib/minitest.rb:63:in `block in autorun'
17: from /Users/User/.rvm/gems/ruby-2.5.0/gems/minitest-5.11.1/lib/minitest.rb:136:in `run'
16: from /Users/User/.rvm/gems/ruby-2.5.0/gems/minitest-5.11.1/lib/minitest.rb:159:in `__run'
15: from /Users/User/.rvm/gems/ruby-2.5.0/gems/minitest-5.11.1/lib/minitest.rb:159:in `map'
14: from /Users/User/.rvm/gems/ruby-2.5.0/gems/minitest-5.11.1/lib/minitest.rb:159:in `block in __run'
13: from /Users/User/.rvm/gems/ruby-2.5.0/gems/railties-5.1.4/lib/rails/test_unit/line_filtering.rb:9:in `run'
12: from /Users/User/.rvm/gems/ruby-2.5.0/gems/minitest-5.11.1/lib/minitest.rb:319:in `run'
11: from /Users/User/.rvm/gems/ruby-2.5.0/gems/minitest-5.11.1/lib/minitest.rb:347:in `with_info_handler'
10: from /Users/User/.rvm/gems/ruby-2.5.0/gems/minitest-5.11.1/lib/minitest.rb:360:in `on_signal'
9: from /Users/User/.rvm/gems/ruby-2.5.0/gems/minitest-5.11.1/lib/minitest.rb:320:in `block in run'
8: from /Users/User/.rvm/gems/ruby-2.5.0/gems/minitest-5.11.1/lib/minitest.rb:320:in `each'
7: from /Users/User/.rvm/gems/ruby-2.5.0/gems/minitest-5.11.1/lib/minitest.rb:321:in `block (2 levels) in run'
6: from /Users/User/.rvm/gems/ruby-2.5.0/gems/minitest-5.11.1/lib/minitest.rb:334:in `run_one_method'
5: from /Users/User/.rvm/gems/ruby-2.5.0/gems/minitest-5.11.1/lib/minitest.rb:785:in `record'
4: from /Users/v/.rvm/gems/ruby-2.5.0/gems/minitest-5.11.1/lib/minitest.rb:785:in `each'
3: from /Users/User/.rvm/gems/ruby-2.5.0/gems/minitest-5.11.1/lib/minitest.rb:786:in `block in record'
2: from /Users/User/.rvm/gems/ruby-2.5.0/gems/railties-5.1.4/lib/rails/test_unit/reporter.rb:23:in `record'
1: from /Users/User/.rvm/gems/ruby-2.5.0/gems/railties-5.1.4/lib/rails/test_unit/reporter.rb:70:in `format_rerun_snippet'
/Users/User/.rvm/gems/ruby-2.5.0/gems/railties-5.1.4/lib/rails/test_unit/reporter.rb:70:in `method': undefined method `test_should_get_help' for class `Minitest::Result' (NameError)
但是,如果测试通过,则显示的最小测试报告根本没有错误消息。
我尝试删除 minitest-reporters gem,但 NameError 消息并没有消失。似乎与 spring 服务器有关。
我还尝试关闭所有 spring ps。
关于 `test_should_get_help' 是一个简单的测试,尽管删除了它,但错误总是将最后一个笔试放在它的位置。
这是 Gemfile
source 'https://rubygems.org'
gem 'rails', '5.1.4'
gem 'bcrypt', '3.1.11'
gem 'faker', '1.7.3'
gem 'carrierwave', '1.2.2'
gem 'mini_magick', '4.7.0'
gem 'will_paginate', '3.1.6'
gem 'bootstrap-will_paginate', '1.0.0'
gem 'bootstrap-sass', '3.3.7'
gem 'puma', '3.9.1'
gem 'sass-rails', '5.0.6'
gem 'uglifier', '3.2.0'
gem 'coffee-rails', '4.2.2'
gem 'jquery-rails', '4.3.1'
gem 'turbolinks', '5.0.1'
gem 'jbuilder', '2.7.0'
group :development, :test do
gem 'sqlite3', '1.3.13'
gem 'byebug', '9.0.6', platform: :mri
end
group :development do
gem 'web-console', '3.5.1'
gem 'listen', '3.1.5'
gem 'spring', '2.0.2'
gem 'spring-watcher-listen', '2.0.1'
end
group :test do
gem 'rails-controller-testing', '1.0.2'
gem 'minitest-reporters', '1.1.14'
gem 'guard', '2.14.1'
gem 'guard-minitest', '2.4.6'
end
group :production do
gem 'pg', '0.20.0'
gem 'fog', '1.42'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
我找到了这个线程:https://github.com/seattlerb/minitest/issues/730,它承诺修复 MiniTest。该修复程序将在未来的 Rails 更新中提供,或现在通过 Edge Rails.
我在 Gemfile
中添加了一个临时条目以将 MiniTest 恢复到以前的稳定版本,
# temporary fix to minitest 5.11.1 issue
gem 'minitest', '~>5.10.3'
然后 运行
bundle update minitest
它似乎有效(但我的测试仍然失败)。
YMMV
多亏了这个
,我找到了一个临时修复方法
我明确地包括了 minitest gem 并删除了 minitest-reporters gem(尚未验证问题是否仍然存在,包括 reporters)
gem 'minitest', '5.10.3'
如果您在开发中使用 pg,这可能会带来其他错误。该线程还建议从 git 中提取 rails gem(在 gem 文件中),这将避免降级任何 gem.
当 运行 rails 测试失败时,在 5.1.4 rails 应用程序中它会抛出以下 NameError。
Traceback (most recent call last):
27: from -e:1:in `<main>'
26: from /Users/User/.rvm/rubies/ruby-2.5.0/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
25: from /Users/User/.rvm/rubies/ruby-2.5.0/lib/ruby/site_ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
24: from /Users/User/.rvm/gems/ruby-2.5.0/gems/spring-2.0.2/lib/spring/application/boot.rb:19:in `<top (required)>'
23: from /Users/User/.rvm/gems/ruby-2.5.0/gems/spring-2.0.2/lib/spring/application.rb:135:in `run'
22: from /Users/User/.rvm/gems/ruby-2.5.0/gems/spring-2.0.2/lib/spring/application.rb:135:in `loop'
21: from /Users/User/.rvm/gems/ruby-2.5.0/gems/spring-2.0.2/lib/spring/application.rb:141:in `block in run'
20: from /Users/User/.rvm/gems/ruby-2.5.0/gems/spring-2.0.2/lib/spring/application.rb:171:in `serve'
19: from /Users/User/.rvm/gems/ruby-2.5.0/gems/spring-2.0.2/lib/spring/application.rb:171:in `fork'
18: from /Users/User/.rvm/gems/ruby-2.5.0/gems/minitest-5.11.1/lib/minitest.rb:63:in `block in autorun'
17: from /Users/User/.rvm/gems/ruby-2.5.0/gems/minitest-5.11.1/lib/minitest.rb:136:in `run'
16: from /Users/User/.rvm/gems/ruby-2.5.0/gems/minitest-5.11.1/lib/minitest.rb:159:in `__run'
15: from /Users/User/.rvm/gems/ruby-2.5.0/gems/minitest-5.11.1/lib/minitest.rb:159:in `map'
14: from /Users/User/.rvm/gems/ruby-2.5.0/gems/minitest-5.11.1/lib/minitest.rb:159:in `block in __run'
13: from /Users/User/.rvm/gems/ruby-2.5.0/gems/railties-5.1.4/lib/rails/test_unit/line_filtering.rb:9:in `run'
12: from /Users/User/.rvm/gems/ruby-2.5.0/gems/minitest-5.11.1/lib/minitest.rb:319:in `run'
11: from /Users/User/.rvm/gems/ruby-2.5.0/gems/minitest-5.11.1/lib/minitest.rb:347:in `with_info_handler'
10: from /Users/User/.rvm/gems/ruby-2.5.0/gems/minitest-5.11.1/lib/minitest.rb:360:in `on_signal'
9: from /Users/User/.rvm/gems/ruby-2.5.0/gems/minitest-5.11.1/lib/minitest.rb:320:in `block in run'
8: from /Users/User/.rvm/gems/ruby-2.5.0/gems/minitest-5.11.1/lib/minitest.rb:320:in `each'
7: from /Users/User/.rvm/gems/ruby-2.5.0/gems/minitest-5.11.1/lib/minitest.rb:321:in `block (2 levels) in run'
6: from /Users/User/.rvm/gems/ruby-2.5.0/gems/minitest-5.11.1/lib/minitest.rb:334:in `run_one_method'
5: from /Users/User/.rvm/gems/ruby-2.5.0/gems/minitest-5.11.1/lib/minitest.rb:785:in `record'
4: from /Users/v/.rvm/gems/ruby-2.5.0/gems/minitest-5.11.1/lib/minitest.rb:785:in `each'
3: from /Users/User/.rvm/gems/ruby-2.5.0/gems/minitest-5.11.1/lib/minitest.rb:786:in `block in record'
2: from /Users/User/.rvm/gems/ruby-2.5.0/gems/railties-5.1.4/lib/rails/test_unit/reporter.rb:23:in `record'
1: from /Users/User/.rvm/gems/ruby-2.5.0/gems/railties-5.1.4/lib/rails/test_unit/reporter.rb:70:in `format_rerun_snippet'
/Users/User/.rvm/gems/ruby-2.5.0/gems/railties-5.1.4/lib/rails/test_unit/reporter.rb:70:in `method': undefined method `test_should_get_help' for class `Minitest::Result' (NameError)
但是,如果测试通过,则显示的最小测试报告根本没有错误消息。 我尝试删除 minitest-reporters gem,但 NameError 消息并没有消失。似乎与 spring 服务器有关。 我还尝试关闭所有 spring ps。 关于 `test_should_get_help' 是一个简单的测试,尽管删除了它,但错误总是将最后一个笔试放在它的位置。
这是 Gemfile
source 'https://rubygems.org'
gem 'rails', '5.1.4'
gem 'bcrypt', '3.1.11'
gem 'faker', '1.7.3'
gem 'carrierwave', '1.2.2'
gem 'mini_magick', '4.7.0'
gem 'will_paginate', '3.1.6'
gem 'bootstrap-will_paginate', '1.0.0'
gem 'bootstrap-sass', '3.3.7'
gem 'puma', '3.9.1'
gem 'sass-rails', '5.0.6'
gem 'uglifier', '3.2.0'
gem 'coffee-rails', '4.2.2'
gem 'jquery-rails', '4.3.1'
gem 'turbolinks', '5.0.1'
gem 'jbuilder', '2.7.0'
group :development, :test do
gem 'sqlite3', '1.3.13'
gem 'byebug', '9.0.6', platform: :mri
end
group :development do
gem 'web-console', '3.5.1'
gem 'listen', '3.1.5'
gem 'spring', '2.0.2'
gem 'spring-watcher-listen', '2.0.1'
end
group :test do
gem 'rails-controller-testing', '1.0.2'
gem 'minitest-reporters', '1.1.14'
gem 'guard', '2.14.1'
gem 'guard-minitest', '2.4.6'
end
group :production do
gem 'pg', '0.20.0'
gem 'fog', '1.42'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
我找到了这个线程:https://github.com/seattlerb/minitest/issues/730,它承诺修复 MiniTest。该修复程序将在未来的 Rails 更新中提供,或现在通过 Edge Rails.
我在 Gemfile
中添加了一个临时条目以将 MiniTest 恢复到以前的稳定版本,
# temporary fix to minitest 5.11.1 issue
gem 'minitest', '~>5.10.3'
然后 运行
bundle update minitest
它似乎有效(但我的测试仍然失败)。
YMMV
多亏了这个
我明确地包括了 minitest gem 并删除了 minitest-reporters gem(尚未验证问题是否仍然存在,包括 reporters)
gem 'minitest', '5.10.3'
如果您在开发中使用 pg,这可能会带来其他错误。该线程还建议从 git 中提取 rails gem(在 gem 文件中),这将避免降级任何 gem.