你好,我是铁路新手.我正在关注Michael Hartl的railstutorial.org.我陷入了清单4.5的第4章:
当我点击$bundle exec rake测试时,它会显示一些不同于它应该按照教程显示的结果.
注意:我使用Ubuntu 15.10作为平台.
当我点击$bundle exec rake测试时,它会显示一些不同于它应该按照教程显示的结果.
注意:我使用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
请指导我如何摆脱错误.
解决方法
看起来你正在使用
RubyDep,这个工具可以帮助你避免不安全的Ruby版本. RubyDep在第一行告诉你:
RubyDep: WARNING: your Ruby has security vulnerabilities! Please upgrade! (…)
查看堆栈跟踪的其他行的路径(… / .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