我正在使用Rails 4.1和Ruby 2.0.0。我正在嘗試使用minitest-rails
進行測試,我遇到了這個奇怪的錯誤。當我包括:NameError:未初始化的常量Minitest :: VERSION
require 'minitest/spec'
在我的「spec_helper」文件,它給我一個NameError:未初始化不斷MINITEST ::版本錯誤。當我評論這條線時,一切似乎都很好。奇怪的是,'minitest/autorun'也在那裏,並沒有造成任何問題。也許你們可以對這裏發生的事情有所瞭解。
spec_helper.rb
:
ENV["RAILS_ENV"] ||= "test"
require File.expand_path('../../config/environment', __FILE__)
require 'minitest/spec'
require 'minitest/autorun'
require 'minitest-rails'
require 'minitest-rails-capybara'
Rakefile
:
require File.expand_path('../config/application', __FILE__)
Pinteresting::Application.load_tasks
namespace :test do
task :run do
ENV["RACK_ENV"] = "test"
$LOAD_PATH.unshift("lib", "spec")
if ARGV[1]
require_relative ARGV[1]
else
Dir.glob("./spec/**/*_spec.rb").each { |file| require file }
end
end
end
.spec
:
require "spec_helper"
describe "Test" do
describe "When two is equal to two" do
it "asserts true" do
assert_equal(2, 2)
end
end
end
堆棧跟蹤:
nbp-93-202:pinteresting Frank$ rake test:run
rake aborted!
NameError: uninitialized constant Minitest::VERSION
/usr/local/rvm/gems/ruby-2.0.0-p481/gems/minitest-5.3.4/lib/minitest/unit.rb:22:in `<class:Unit>'
/usr/local/rvm/gems/ruby-2.0.0-p481/gems/minitest-5.3.4/lib/minitest/unit.rb:21:in `<module:Minitest>'
/usr/local/rvm/gems/ruby-2.0.0-p481/gems/minitest-5.3.4/lib/minitest/unit.rb:20:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.0.0-p481/gems/minitest-5.3.4/lib/minitest/spec.rb:1:in `<top (required)>'
/Users/Frank/Desktop/pinteresting/spec/spec_helper.rb:4:in `<top (required)>'
/Users/Frank/Desktop/pinteresting/spec/diagnostic_spec.rb:1:in `<top (required)>'
/Users/Frank/Desktop/pinteresting/Rakefile:12:in `block (3 levels) in <top (required)>'
/Users/Frank/Desktop/pinteresting/Rakefile:12:in `each'
/Users/Frank/Desktop/pinteresting/Rakefile:12:in `block (2 levels) in <top (required)>'
Tasks: TOP => test:run
運行'bundle install'時你看到這個錯誤嗎?包括堆棧跟蹤將有助於 –
我添加了堆棧跟蹤 – Idyllize
如果更改需求中的順序,即首先需要'minitest/autorun'然後'minitest/spec',那麼錯誤是否仍然會出現? – eduardo