你好,我是铁路新手。我正在关注Michael Hartl的railstutorial.org。我陷入了清单4.5的第4章:
当我点击$ 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
的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
请指导我如何摆脱错误。
答案 0 :(得分:5)
您似乎正在使用RubyDep,这是一种可以帮助您避免不安全的Ruby版本的工具。 RubyDep在第一行告诉你:
RubyDep:警告:您的Ruby存在安全漏洞!请升级! (...)
查看堆栈跟踪的其他行的路径(.../.rbenv/versions/2.2.3/...
),看起来您正在使用随rbenv一起安装的Ruby版本2.2.3。
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...`
最后一步是重新安装宝石:
gem install bundler
bundler install
更新是否成功?
bundle exec rake test
答案 1 :(得分:1)
试试这个
ref.child('users').child(authData.uid).child('documents/passport').on('value'...
如果不起作用,请尝试安装较旧版本的Guard或Minitest。
export RUBY_DEP_GEM_SILENCE_WARNINGS=1
使用gem list Minitest
*** LOCAL GEMS ***
minitest (5.8.4, 5.7.0, 5.6.1, 4.7.5)
查看如何安装与最新版本不同的版本。
有时新版本会出现错误,并且与旧的Ruby或Rails版本不兼容。
答案 2 :(得分:1)
看起来你的实际问题是你的minitest记者的版本。通过最小的守卫来源和最小的记者,看起来像minitest-reporter用于在所有使用的最小插件上调用方法io
和add_defaults
。从它的外观来看,minitest本身从未在任何记者身上定义过add_defaults
方法。看起来像minitest-reporter gem本身定义了一堆定制记者add_defaults
定义了它们,但它似乎炸毁了任何直接从最小的宝石本身继承的东西作为守卫minitest。
幸运的是,看起来minitest-reporter gem实际上已将此修复为一个bug而没有说明任何内容,特别是在this提交中。请注意第47行上对respond_to?
的调用,该调用应修复您正在获取的特定堆栈跟踪。
这意味着你应该升级你的minitest-reporter版本。看起来第一个有这个问题的版本是minitest-reporter 1.1.2。所以你应该修改你的Gemfile至少使用那个版本。
作为一般的ruby练习,尤其是像测试这样的东西,你真的没有理由将你的版本固定在你的Gemfile中。我要做的只是从Gemfile中删除minitest-reporter的版本并检查你的Gemfile.lock以依赖特定的安装版本。它可以更轻松地更新您的依赖项。
很抱歉,看起来我对此修复的位置略显错误。找到真正的提交,它在这里:
https://github.com/kern/minitest-reporters/commit/8e3a8e0a195e31d97a35e4d8b7d1f05cb833ce93
看起来引入的版本是1.0.11。所以你的Gemfile至少需要使用它,如:
gem 'minitest-reporters', '1.0.11'
答案 3 :(得分:1)
在你的Gemfile中,只需删除minitest_reporters gem旁边的特定版本并运行bundle install - minitest_reporters在1.0.5以后的版本中添加了修复程序。