簡體   English   中英

捆綁exec rake測試投擲錯誤

[英]bundle exec rake test throwing error

你好,我是鐵路新手。 我正在關注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

請指導我如何擺脫錯誤。

看起來你正在使用RubyDep ,這是一個可以幫助你避免不安全的Ruby版本的工具。 RubyDep在第一行告訴你:

RubyDep:警告:您的Ruby存在安全漏洞! 請升級! (......)

查看.../.rbenv/versions/2.2.3/...的其他行的路徑( .../.rbenv/versions/2.2.3/... ),看起來您正在使用隨rbenv一起安裝的Ruby 2.2.3版。

RubyDep是對的: Ruby 2.2.3存在一個已知漏洞

更新版本的Ruby可用。 您可以升級到最新的2.2.x版本(或最新的2.3.x )。 我建議升級到2.2.5 ,因為我不知道該教程是否與2.3.x兼容。

要使用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

將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

嘗試這個

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版本不兼容。

問題

看起來你的實際問題是你的minitest-reporter的版本。 通過最小的守衛來源和最小的記者來看,它看起來像minitest-reporter用於在所有使用的最小插件上調用方法ioadd_defaults 從它的外觀來看,minitest本身從未在任何Reporters上實際定義過add_defaults方法。 看起來像minitest-reporter gem本身定義了一堆自定義了add_defaults的自定義記者,但它似乎炸掉了任何直接從minitest gem本身繼承的東西,就像guard-minitest那樣。

解決方案

幸運的是,看起來像minitest-reporter gem實際上已經將其修改為一個bug而沒有說出任何關於它的信息,特別是在這個提交中。 注意對respond_to?的調用respond_to? 在第47行,這應該修復你正在獲得的這個特定的堆棧跟蹤。

這意味着你應該升級你的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'

在你的Gemfile中,只需刪除minitest_reporters gem旁邊的特定版本並運行bundle install - minitest_reporters在1.0.5以后的版本中添加了修復程序。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM