[英]bundle exec rake test throwing error
Hello there I am new to rail. 你好,我是铁路新手。 I am following railstutorial.org by Michael Hartl.
我正在关注Michael Hartl的railstutorial.org。 I am stuck in chapter 4, Listing 4.5: when i hit
$ bundle exec rake test
it showing some different result than it supposed to show as per tutorial. 我陷入了清单4.5的第4章:当我点击
$ bundle exec rake test
它显示了一些不同于它应该按照教程显示的结果。 Note :I am using Ubuntu 15.10 as a platform. 注意:我使用Ubuntu 15.10作为平台。
Result when i hit $ bundle exec rake test
当我点击
$ 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 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 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 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 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
Gemfile 的Gemfile
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
Please guide me how can i get rid of the error. 请指导我如何摆脱错误。
It seems like you are using RubyDep , a tool that helps you to avoid insecure Ruby versions. 看起来你正在使用RubyDep ,这是一个可以帮助你避免不安全的Ruby版本的工具。 RubyDep tells you in the first line:
RubyDep在第一行告诉你:
RubyDep: WARNING: your Ruby has security vulnerabilities!
RubyDep:警告:您的Ruby存在安全漏洞! Please upgrade!
请升级! (...)
(......)
Looking at the path ( .../.rbenv/versions/2.2.3/...
) of the other lines of the stacktrace it looks like you are using Ruby version 2.2.3, installed with rbenv . 查看
.../.rbenv/versions/2.2.3/...
的其他行的路径( .../.rbenv/versions/2.2.3/...
),看起来您正在使用随rbenv一起安装的Ruby 2.2.3版。
And RubyDep is right: There is a known vulnerability in Ruby 2.2.3
. RubyDep是对的: Ruby
2.2.3
存在一个已知漏洞 。
There are newer versions of Ruby available. 有更新版本的Ruby可用。 You could upgrade to the latest
2.2.x
version (or the latest 2.3.x
). 您可以升级到最新的
2.2.x
版本(或最新的2.3.x
)。 I suggest to upgrade to 2.2.5
, because I'm do not know if the tutorial is compatible with 2.3.x
. 我建议升级到
2.2.5
,因为我不知道该教程是否与2.3.x
兼容。
To upgrade Ruby to a newer version with rbenv
follow this steps (I suppose you used brew
to install rbenv
): 要使用
rbenv
将Ruby升级到更新版本, rbenv
按照以下步骤操作(我假设您使用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
Set 2.2.5 to you default Ruby version: 将2.2.5设置为默认的Ruby版本:
rbenv global 2.2.5
Update your Rails application to use this Ruby version. 更新您的Rails应用程序以使用此Ruby版本。 To do so check the following files (if they exist, they might be hidden) and change the Ruby version in that files:
为此,请检查以下文件(如果存在,可能会隐藏它们)并更改该文件中的Ruby版本:
.ruby-version
Gemfile
You might want to check in your applications root that you are using the updated version of Ruby: 您可能想要在应用程序根目录中检查您使用的是Ruby的更新版本:
ruby -v # should return `ruby 2.2.5p...`
Last step is to reinstall gems: 最后一步是重新安装宝石:
gem install bundler
bundler install
Was the update successful? 更新是否成功?
bundle exec rake test
Try this 尝试这个
export RUBY_DEP_GEM_SILENCE_WARNINGS=1
If that doesn't work, try to install an older version of Guard or Minitest. 如果这不起作用,请尝试安装较旧版本的Guard或Minitest。
gem list Minitest
*** LOCAL GEMS ***
minitest (5.8.4, 5.7.0, 5.6.1, 4.7.5)
Use gem help install
to see how to install a different version than the latest. 使用
gem help install
查看如何安装与最新版本不同的版本。
Sometimes a new version has bugs and is incompatible with an old Ruby or Rails version. 有时新版本存在错误,并且与旧的Ruby或Rails版本不兼容。
It looks like your actual problem is your version of minitest-reporters. 看起来你的实际问题是你的minitest-reporter的版本。 Digging through both the guard-minitest source and minitest-reporters, it looks like minitest-reporters used to invoke methods
io
and add_defaults
on all of the minitest plugins that were being used. 通过最小的守卫来源和最小的记者来看,它看起来像minitest-reporter用于在所有使用的最小插件上调用方法
io
和add_defaults
。 From the looks of it, minitest itself never actually defined an add_defaults
method on any of their Reporters. 从它的外观来看,minitest本身从未在任何Reporters上实际定义过
add_defaults
方法。 It looks like the minitest-reporters gem itself defines a bunch of custom reporters that have add_defaults
defined on them, but it seems to blow up on anything that inherits directly from the minitest gem itself as guard-minitest does. 看起来像minitest-reporter gem本身定义了一堆自定义了
add_defaults
的自定义记者,但它似乎炸掉了任何直接从minitest gem本身继承的东西,就像guard-minitest那样。
Fortunately, it looks like the minitest-reporters gem actually fixed this as a bug without saying anything about it, specifically in this commit. 幸运的是,看起来像minitest-reporter gem实际上已经将其修改为一个bug而没有说出任何关于它的信息,特别是在这个提交中。 Notice the call to
respond_to?
注意对
respond_to?
的调用respond_to?
on line 47, that should fix this particular stacktrace you're getting. 在第47行,这应该修复你正在获得的这个特定的堆栈跟踪。
What this means is that you should upgrade your version of minitest-reporters. 这意味着你应该升级你的minitest-reporter版本。 It looks like the first version that has this fix in it is minitest-reporters 1.1.2.
看起来第一个有这个问题的版本是minitest-reporter 1.1.2。 So you should modify your Gemfile to use at least that version.
所以你应该修改你的Gemfile至少使用那个版本。
As general ruby practice though, especially with things like testing, there's really no reason to pin your versions in your Gemfile. 作为一般的ruby练习,尤其是像测试这样的东西,没有理由在你的Gemfile中固定你的版本。 What I would do is just remove the version for minitest-reporters from the Gemfile altogether and check in your Gemfile.lock to rely on particular installed versions.
我要做的只是从Gemfile中删除minitest-reporter的版本并检查你的Gemfile.lock以依赖特定的安装版本。 It'll make updating your dependencies easier.
它将使您更新您的依赖项更容易。
Sorry, looks like I was slightly wrong about where this was fixed. 对不起,看起来我对此修复的位置略显错误。 Found the real commit, it's here:
找到真正的提交,它在这里:
https://github.com/kern/minitest-reporters/commit/8e3a8e0a195e31d97a35e4d8b7d1f05cb833ce93 https://github.com/kern/minitest-reporters/commit/8e3a8e0a195e31d97a35e4d8b7d1f05cb833ce93
It looks like the version this was introduced in was 1.0.11. 看起来这个版本的引入版本是1.0.11。 So your Gemfile just needs to use at least that instead, as in:
所以你的Gemfile至少需要使用它,如:
gem 'minitest-reporters', '1.0.11'
在你的Gemfile中,只需删除minitest_reporters gem旁边的特定版本并运行bundle install - minitest_reporters在1.0.5以后的版本中添加了修复程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.