bundle exec rake 测试抛出错误
bundle exec rake test throwing error
你好,我是铁路新手。我正在关注 Michael Hartl 的 railstutorial.org。我卡在了第 4 章的清单 4.5 中:
当我点击 $ bundle exec rake test
时,它显示的结果与按照教程应该显示的结果不同。
注意:我使用 Ubuntu 15.10 作为平台。
我点击 $ bundle exec rake test
时的结果
/home/shyambhimani/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/minitest-reporters-1.0.5/lib/minitest/minitest_reporter_plugin.rb:8:in `block in plugin_minitest_reporter_init': undefined method `add_defaults' for #<Guard::Minitest::Reporter:0x005580a1496930> (NoMethodError)
from /home/shyambhimani/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/minitest-reporters-1.0.5/lib/minitest/minitest_reporter_plugin.rb:6:in `each'
from /home/shyambhimani/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/minitest-reporters-1.0.5/lib/minitest/minitest_reporter_plugin.rb:6:in `plugin_minitest_reporter_init'
from /home/shyambhimani/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/minitest-5.8.4/lib/minitest.rb:74:in `block in init_plugins'
from /home/shyambhimani/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/minitest-5.8.4/lib/minitest.rb:72:in `each'
from /home/shyambhimani/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/minitest-5.8.4/lib/minitest.rb:72:in `init_plugins'
from /home/shyambhimani/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/minitest-5.8.4/lib/minitest.rb:123:in `run'
from /home/shyambhimani/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/minitest-5.8.4/lib/minitest.rb:56:in `block in autorun'
application.html.erb
<!DOCTYPE html>
<html>
<head>
<title><%= full_title(yield(:title)) %></title>
<%= stylesheet_link_tag 'application', media: 'all',
'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
</head>
<body>
<%= yield %>
</body>
</html>
application_helper.rb
module ApplicationHelper
# Returns the full title on a per-page basis.
def full_title(page_title = '')
base_title = "Ruby on Rails Tutorial Sample App"
if page_title.empty?
base_title
else
page_title + " | " + base_title
end
end
end
static_pages_controller_test.rb
require 'test_helper'
class StaticPagesControllerTest < ActionController::TestCase
test "should get home" do
get :home
assert_response :success
assert_select "title", "Ruby on Rails Tutorial Sample App"
end
test "should get help" do
get :help
assert_response :success
assert_select "title", "Help | Ruby on Rails Tutorial Sample App"
end
test "should get about" do
get :about
assert_response :success
assert_select "title", "About | Ruby on Rails Tutorial Sample App"
end
end
test_helper.rb
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
require "minitest/reporters"
Minitest::Reporters.use!
class ActiveSupport::TestCase
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical
# order.
fixtures :all
# Add more helper methods to be used by all tests here...
end
宝石文件
source 'https://rubygems.org'
gem 'rails', '4.2.6'
gem 'sass-rails', '5.0.2'
gem 'uglifier', '2.5.3'
gem 'coffee-rails', '4.1.0'
gem 'jquery-rails', '4.0.3'
gem 'turbolinks', '2.3.0'
gem 'jbuilder', '2.2.3'
gem 'sdoc', '0.4.0', group: :doc
group :development, :test do
gem 'sqlite3', '1.3.9'
gem 'byebug', '3.4.0'
gem 'web-console', '2.0.0.beta3'
gem 'spring', '1.1.3'
end
group :test do
gem 'minitest-reporters', '1.0.5'
gem 'mini_backtrace', '0.1.3'
gem 'guard-minitest', '2.3.1'
end
group :production do
gem 'pg', '0.17.1'
gem 'rails_12factor', '0.0.2'
end
请指导我如何摆脱错误。
试试这个
export RUBY_DEP_GEM_SILENCE_WARNINGS=1
如果这不起作用,请尝试安装旧版本的 Guard 或 Minitest。
gem list Minitest
*** LOCAL GEMS ***
minitest (5.8.4, 5.7.0, 5.6.1, 4.7.5)
使用 gem help install
查看如何安装与最新版本不同的版本。
有时新版本有错误并且与旧的 Ruby 或 Rails 版本不兼容。
您似乎在使用 RubyDep,这是一种可以帮助您避免使用不安全的 Ruby 版本的工具。 RubyDep 在第一行告诉你:
RubyDep: WARNING: your Ruby has security vulnerabilities! Please upgrade! (...)
查看堆栈跟踪其他行的路径 (.../.rbenv/versions/2.2.3/...
),您似乎正在使用 Ruby 版本 2.2.3,与 rbenv.[=31 一起安装=]
而RubyDep是对的:有一个known vulnerability in Ruby 2.2.3
。
有 newer versions of Ruby 个可用。您可以升级到最新的 2.2.x
版本(或最新的 2.3.x
)。我建议升级到2.2.5
,因为我不知道教程是否兼容2.3.x
。
要使用 rbenv
将 Ruby 升级到较新的版本,请按照以下步骤操作(我想您使用 brew
安装 rbenv
):
brew update # update to the latest brew version
brew upgrade ruby-build # update Ruby version library
brew upgrade rbenv # update rbenv
rbenv install 2.2.5 # install Ruby 2.2.5
将 2.2.5 设置为默认 Ruby 版本:
rbenv global 2.2.5
更新您的 Rails 应用程序以使用此 Ruby 版本。为此,请检查以下文件(如果它们存在,它们可能被隐藏)并更改该文件中的 Ruby 版本:
.ruby-version
Gemfile
您可能想在您的应用程序根目录中检查您正在使用 Ruby 的更新版本:
ruby -v # should return `ruby 2.2.5p...`
最后一步是重新安装 gems:
gem install bundler
bundler install
更新成功了吗?
bundle exec rake test
问题
看来您的实际问题是您的 minitest-reporters 版本。通过挖掘 guard-minitest 源代码和 minitest-reporters,看起来 minitest-reporters 用于在所有正在使用的 minitest 插件上调用方法 io
和 add_defaults
。从表面上看,minitest 本身从未真正在其任何 Reporters 上定义 add_defaults
方法。看起来 minitest-reporters gem 本身定义了一堆定义了 add_defaults
的自定义报告器,但它似乎在任何直接从 minitest gem 本身继承的东西上爆炸了正如 guard-minitest 所做的那样。
解决方案
幸运的是,看起来 minitest-reporters gem 实际上将此作为一个 bug 修复了,没有任何说明,特别是在 this 提交中。请注意第 47 行对 respond_to?
的调用,这应该会修复您得到的这个特定堆栈跟踪。
这意味着你应该升级你的 minitest-reporters 版本。看起来第一个有这个修复的版本是 minitest-reporters 1.1.2。所以你应该修改你的 Gemfile 以至少使用那个版本。
一些建议
虽然一般 ruby 实践,尤其是在测试之类的事情上,确实没有理由将您的版本固定在 Gemfile 中。我要做的就是从 Gemfile 中完全删除 minitest-reporters 的版本,并检查你的 Gemfile.lock 以依赖特定安装的版本。它将使您的依赖项更新更容易。
编辑
抱歉,看来我对这个问题的修复位置有点错误。找到真正的提交,它在这里:
https://github.com/kern/minitest-reporters/commit/8e3a8e0a195e31d97a35e4d8b7d1f05cb833ce93
好像是1.0.11引入的版本。所以你的 Gemfile 只需要至少使用它,如:
gem 'minitest-reporters', '1.0.11'
在您的 Gemfile 中,只需删除 minitest_reporters gem 和 运行 捆绑安装旁边的特定版本 - minitest_reporters 在比 1.0 更高的版本中添加了修复。 5.
你好,我是铁路新手。我正在关注 Michael Hartl 的 railstutorial.org。我卡在了第 4 章的清单 4.5 中:
当我点击 $ bundle exec rake test
时,它显示的结果与按照教程应该显示的结果不同。
注意:我使用 Ubuntu 15.10 作为平台。
我点击 $ bundle exec rake test
/home/shyambhimani/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/minitest-reporters-1.0.5/lib/minitest/minitest_reporter_plugin.rb:8:in `block in plugin_minitest_reporter_init': undefined method `add_defaults' for #<Guard::Minitest::Reporter:0x005580a1496930> (NoMethodError)
from /home/shyambhimani/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/minitest-reporters-1.0.5/lib/minitest/minitest_reporter_plugin.rb:6:in `each'
from /home/shyambhimani/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/minitest-reporters-1.0.5/lib/minitest/minitest_reporter_plugin.rb:6:in `plugin_minitest_reporter_init'
from /home/shyambhimani/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/minitest-5.8.4/lib/minitest.rb:74:in `block in init_plugins'
from /home/shyambhimani/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/minitest-5.8.4/lib/minitest.rb:72:in `each'
from /home/shyambhimani/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/minitest-5.8.4/lib/minitest.rb:72:in `init_plugins'
from /home/shyambhimani/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/minitest-5.8.4/lib/minitest.rb:123:in `run'
from /home/shyambhimani/.rbenv/versions/2.2.3/lib/ruby/gems/2.2.0/gems/minitest-5.8.4/lib/minitest.rb:56:in `block in autorun'
application.html.erb
<!DOCTYPE html>
<html>
<head>
<title><%= full_title(yield(:title)) %></title>
<%= stylesheet_link_tag 'application', media: 'all',
'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
</head>
<body>
<%= yield %>
</body>
</html>
application_helper.rb
module ApplicationHelper
# Returns the full title on a per-page basis.
def full_title(page_title = '')
base_title = "Ruby on Rails Tutorial Sample App"
if page_title.empty?
base_title
else
page_title + " | " + base_title
end
end
end
static_pages_controller_test.rb
require 'test_helper'
class StaticPagesControllerTest < ActionController::TestCase
test "should get home" do
get :home
assert_response :success
assert_select "title", "Ruby on Rails Tutorial Sample App"
end
test "should get help" do
get :help
assert_response :success
assert_select "title", "Help | Ruby on Rails Tutorial Sample App"
end
test "should get about" do
get :about
assert_response :success
assert_select "title", "About | Ruby on Rails Tutorial Sample App"
end
end
test_helper.rb
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'
require "minitest/reporters"
Minitest::Reporters.use!
class ActiveSupport::TestCase
# Setup all fixtures in test/fixtures/*.yml for all tests in alphabetical
# order.
fixtures :all
# Add more helper methods to be used by all tests here...
end
宝石文件
source 'https://rubygems.org'
gem 'rails', '4.2.6'
gem 'sass-rails', '5.0.2'
gem 'uglifier', '2.5.3'
gem 'coffee-rails', '4.1.0'
gem 'jquery-rails', '4.0.3'
gem 'turbolinks', '2.3.0'
gem 'jbuilder', '2.2.3'
gem 'sdoc', '0.4.0', group: :doc
group :development, :test do
gem 'sqlite3', '1.3.9'
gem 'byebug', '3.4.0'
gem 'web-console', '2.0.0.beta3'
gem 'spring', '1.1.3'
end
group :test do
gem 'minitest-reporters', '1.0.5'
gem 'mini_backtrace', '0.1.3'
gem 'guard-minitest', '2.3.1'
end
group :production do
gem 'pg', '0.17.1'
gem 'rails_12factor', '0.0.2'
end
请指导我如何摆脱错误。
试试这个
export RUBY_DEP_GEM_SILENCE_WARNINGS=1
如果这不起作用,请尝试安装旧版本的 Guard 或 Minitest。
gem list Minitest
*** LOCAL GEMS ***
minitest (5.8.4, 5.7.0, 5.6.1, 4.7.5)
使用 gem help install
查看如何安装与最新版本不同的版本。
有时新版本有错误并且与旧的 Ruby 或 Rails 版本不兼容。
您似乎在使用 RubyDep,这是一种可以帮助您避免使用不安全的 Ruby 版本的工具。 RubyDep 在第一行告诉你:
RubyDep: WARNING: your Ruby has security vulnerabilities! Please upgrade! (...)
查看堆栈跟踪其他行的路径 (.../.rbenv/versions/2.2.3/...
),您似乎正在使用 Ruby 版本 2.2.3,与 rbenv.[=31 一起安装=]
而RubyDep是对的:有一个known vulnerability in Ruby 2.2.3
。
有 newer versions of Ruby 个可用。您可以升级到最新的 2.2.x
版本(或最新的 2.3.x
)。我建议升级到2.2.5
,因为我不知道教程是否兼容2.3.x
。
要使用 rbenv
将 Ruby 升级到较新的版本,请按照以下步骤操作(我想您使用 brew
安装 rbenv
):
brew update # update to the latest brew version
brew upgrade ruby-build # update Ruby version library
brew upgrade rbenv # update rbenv
rbenv install 2.2.5 # install Ruby 2.2.5
将 2.2.5 设置为默认 Ruby 版本:
rbenv global 2.2.5
更新您的 Rails 应用程序以使用此 Ruby 版本。为此,请检查以下文件(如果它们存在,它们可能被隐藏)并更改该文件中的 Ruby 版本:
.ruby-version
Gemfile
您可能想在您的应用程序根目录中检查您正在使用 Ruby 的更新版本:
ruby -v # should return `ruby 2.2.5p...`
最后一步是重新安装 gems:
gem install bundler
bundler install
更新成功了吗?
bundle exec rake test
问题
看来您的实际问题是您的 minitest-reporters 版本。通过挖掘 guard-minitest 源代码和 minitest-reporters,看起来 minitest-reporters 用于在所有正在使用的 minitest 插件上调用方法 io
和 add_defaults
。从表面上看,minitest 本身从未真正在其任何 Reporters 上定义 add_defaults
方法。看起来 minitest-reporters gem 本身定义了一堆定义了 add_defaults
的自定义报告器,但它似乎在任何直接从 minitest gem 本身继承的东西上爆炸了正如 guard-minitest 所做的那样。
解决方案
幸运的是,看起来 minitest-reporters gem 实际上将此作为一个 bug 修复了,没有任何说明,特别是在 this 提交中。请注意第 47 行对 respond_to?
的调用,这应该会修复您得到的这个特定堆栈跟踪。
这意味着你应该升级你的 minitest-reporters 版本。看起来第一个有这个修复的版本是 minitest-reporters 1.1.2。所以你应该修改你的 Gemfile 以至少使用那个版本。
一些建议
虽然一般 ruby 实践,尤其是在测试之类的事情上,确实没有理由将您的版本固定在 Gemfile 中。我要做的就是从 Gemfile 中完全删除 minitest-reporters 的版本,并检查你的 Gemfile.lock 以依赖特定安装的版本。它将使您的依赖项更新更容易。
编辑
抱歉,看来我对这个问题的修复位置有点错误。找到真正的提交,它在这里:
https://github.com/kern/minitest-reporters/commit/8e3a8e0a195e31d97a35e4d8b7d1f05cb833ce93
好像是1.0.11引入的版本。所以你的 Gemfile 只需要至少使用它,如:
gem 'minitest-reporters', '1.0.11'
在您的 Gemfile 中,只需删除 minitest_reporters gem 和 运行 捆绑安装旁边的特定版本 - minitest_reporters 在比 1.0 更高的版本中添加了修复。 5.