2018 年 09 月 13 日 09:28:53(最新)
这个问题是由于 gem 包版本所导致,是一个不是问题的问题,建议直接查看 22 楼
我怎么总碰到这种奇葩事情
我是根据《Ruby on Rails 教程 第 4 版》([美] 迈克尔·哈特尔(Michael, Hartl))自学 Rails
现在看到3.3 开始测试
的章节
在编写一个失败测试(测试一个没有的页面)时出现了无法正确得到测试结果的问题
如果我写了 100 个测试,其中有 10 个失败了,那么我也只能得到其中的一个失败
rails test 应该有总结性的语句告诉我我跑了 100 个测试,失败了 10 个,但是并没有
rails test 应该有总结性的语句告诉我我跑了 100 个测试,失败了 10 个,但是并没有
rails test 应该有总结性的语句告诉我我跑了 100 个测试,失败了 10 个,但是并没有
它现在只告诉我“你这个页面没写”,不会告诉我另外 9 个错误的事情
目前在重现问题的时候发现似乎是 gem 包的问题,在 16 楼有具体过程重现
rails _5.1.2_ new sample_app
创建一个新项目source 'https://rubygems.org'
gem 'rails', '5.1.2'
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.0.8'
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.13.0'
gem 'guard-minitest', '2.4.4'
end
group :production do
gem 'pg', '0.20.0'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
rails generate controller StaticPages home help
生成控制器,并运行 rails db:migrate这时运行 rails test 可以得到教程中给出的信息
$ rails test
2 tests, 2 assertions, 0 failures, 0 errors, 0 skips
test/controllers/static_pages_controller_test.rb
test 'should get nothing' do
get static_pages_about_url
assert_response :success
end
教程中给出的结果是
$ rails test
3 tests, 2 assertions, 0 failures, 1 errors, 0 skips
但是我实际只得到了错误信息,并且无法像教程中给出的那种结论式的信息
Running via Spring preloader in process 9911
Run options: --seed 22370
# Running:
.E
Error:
StaticPagesControllerTest#test_should_get_about:
NameError: undefined local variable or method `static_pages_about_url' for #<StaticPagesControllerTest:0x0000000006e2fcb0>
test/controllers/static_pages_controller_test.rb:15:in `block in <class:StaticPagesControllerTest>'
/home/sws/.rvm/gems/ruby-2.4.4/gems/railties-5.1.2/lib/rails/test_unit/reporter.rb:70:in `method': undefined method `test_should_get_about' for class `Minitest::Result' (NameError)
from /home/sws/.rvm/gems/ruby-2.4.4/gems/railties-5.1.2/lib/rails/test_unit/reporter.rb:70:in `format_rerun_snippet'
from /home/sws/.rvm/gems/ruby-2.4.4/gems/railties-5.1.2/lib/rails/test_unit/reporter.rb:23:in `record'
from /home/sws/.rvm/gems/ruby-2.4.4/gems/minitest-reporters-1.1.14/lib/minitest/minitest_reporter_plugin.rb:21:in `block in record'
from /home/sws/.rvm/gems/ruby-2.4.4/gems/minitest-reporters-1.1.14/lib/minitest/minitest_reporter_plugin.rb:20:in `each'
from /home/sws/.rvm/gems/ruby-2.4.4/gems/minitest-reporters-1.1.14/lib/minitest/minitest_reporter_plugin.rb:20:in `record'
from /home/sws/.rvm/gems/ruby-2.4.4/gems/minitest-5.11.3/lib/minitest.rb:803:in `block in record'
from /home/sws/.rvm/gems/ruby-2.4.4/gems/minitest-5.11.3/lib/minitest.rb:802:in `each'
from /home/sws/.rvm/gems/ruby-2.4.4/gems/minitest-5.11.3/lib/minitest.rb:802:in `record'
from /home/sws/.rvm/gems/ruby-2.4.4/gems/minitest-5.11.3/lib/minitest.rb:334:in `run_one_method'
from /home/sws/.rvm/gems/ruby-2.4.4/gems/minitest-5.11.3/lib/minitest.rb:321:in `block (2 levels) in run'
from /home/sws/.rvm/gems/ruby-2.4.4/gems/minitest-5.11.3/lib/minitest.rb:320:in `each'
from /home/sws/.rvm/gems/ruby-2.4.4/gems/minitest-5.11.3/lib/minitest.rb:320:in `block in run'
from /home/sws/.rvm/gems/ruby-2.4.4/gems/minitest-5.11.3/lib/minitest.rb:360:in `on_signal'
from /home/sws/.rvm/gems/ruby-2.4.4/gems/minitest-5.11.3/lib/minitest.rb:347:in `with_info_handler'
from /home/sws/.rvm/gems/ruby-2.4.4/gems/minitest-5.11.3/lib/minitest.rb:319:in `run'
from /home/sws/.rvm/gems/ruby-2.4.4/gems/railties-5.1.2/lib/rails/test_unit/line_filtering.rb:11:in `run'
from /home/sws/.rvm/gems/ruby-2.4.4/gems/minitest-5.11.3/lib/minitest.rb:159:in `block in __run'
from /home/sws/.rvm/gems/ruby-2.4.4/gems/minitest-5.11.3/lib/minitest.rb:159:in `map'
from /home/sws/.rvm/gems/ruby-2.4.4/gems/minitest-5.11.3/lib/minitest.rb:159:in `__run'
from /home/sws/.rvm/gems/ruby-2.4.4/gems/minitest-5.11.3/lib/minitest.rb:136:in `run'
from /home/sws/.rvm/gems/ruby-2.4.4/gems/railties-5.1.2/lib/rails/test_unit/minitest_plugin.rb:77:in `run'
from /home/sws/.rvm/gems/ruby-2.4.4/gems/minitest-5.11.3/lib/minitest.rb:63:in `block in autorun'
from /home/sws/.rvm/gems/ruby-2.4.4/gems/spring-2.0.2/lib/spring/application.rb:171:in `fork'
from /home/sws/.rvm/gems/ruby-2.4.4/gems/spring-2.0.2/lib/spring/application.rb:171:in `serve'
from /home/sws/.rvm/gems/ruby-2.4.4/gems/spring-2.0.2/lib/spring/application.rb:141:in `block in run'
from /home/sws/.rvm/gems/ruby-2.4.4/gems/spring-2.0.2/lib/spring/application.rb:135:in `loop'
from /home/sws/.rvm/gems/ruby-2.4.4/gems/spring-2.0.2/lib/spring/application.rb:135:in `run'
from /home/sws/.rvm/gems/ruby-2.4.4/gems/spring-2.0.2/lib/spring/application/boot.rb:19:in `<top (required)>'
from /home/sws/.rvm/rubies/ruby-2.4.4/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:59:in `require'
from /home/sws/.rvm/rubies/ruby-2.4.4/lib/ruby/site_ruby/2.4.0/rubygems/core_ext/kernel_require.rb:59:in `require'
from -e:1:in `<main>'
并且当我再添加一个额外的失败测试时,也无法测到第二个失败
也就是说,它这个测试在测试 about 页面时就出错然后就没有然后了
如果后面还有其它失败也不能正常测试