在这里完成初学者。我一直在研究Hartl Rails教程 - 目前正在进行的#34;高级测试设置"对于第3章中的可选练习。尽管测试运行得很顺利,但在运行" rake test"时,我收到以下错误。或"警卫":
LoadError: cannot load such file --
/home/ubuntu/workspace/sample_app/test/config/environment
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `require'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `block in require'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:240:in `load_dependency'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `require'
/home/ubuntu/workspace/sample_app/test/controllers/static_pages_controller_test.rb:10:in `<class:StaticPagesControllerTest>'
/home/ubuntu/workspace/sample_app/test/controllers/static_pages_controller_test.rb:3:in `<top (required)>'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `require'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `block in require'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:240:in `load_dependency'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:274:in `require'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/railties-4.2.0/lib/rails/test_unit/sub_test_task.rb:114:in `block (3 levels) in define'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/railties-4.2.0/lib/rails/test_unit/sub_test_task.rb:114:in `each'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/railties-4.2.0/lib/rails/test_unit/sub_test_task.rb:114:in `block (2 levels) in define'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/railties-4.2.0/lib/rails/test_unit/sub_test_task.rb:113:in `each'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/railties-4.2.0/lib/rails/test_unit/sub_test_task.rb:113:in `block in define'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/railties-4.2.0/lib/rails/test_unit/sub_test_task.rb:31:in `create_and_run_single_test'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/railties-4.2.0/lib/rails/test_unit/sub_test_task.rb:17:in `invoke_rake_task'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/railties-4.2.0/lib/rails/test_unit/testing.rake:8:in `block in <top (required)>'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `load'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `block in load'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:240:in `load_dependency'
/usr/local/rvm/gems/ruby-2.1.5@rails4/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `load'
-e:1:in `<main>'
Tasks: TOP => test:single
(See full trace by running task with --trace)
我使用教程中的标准Gems文件:
source 'https://rubygems.org'
gem 'rails', '4.2.0'
gem 'sass-rails', '5.0.1'
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 :(得分:3)
正如Joel所提到的那样,你似乎遇到了require语句的问题。一定要在'guard-minitest'之前安装一个'后卫'。
将gem'guard'添加到您的宝石文件&amp;运行捆绑安装。我希望它能解决这个问题。
答案 1 :(得分:0)
您的require
声明似乎有误。
您是否在test_helper
文件中添加了以下代码? (从https://www.railstutorial.org/book/static_pages#sec-advanced_testing_setup复制)
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
特别注意这一行:
require File.expand_path('../../config/environment', __FILE__)
答案 2 :(得分:-1)
把这个你的宝石文件:
gem 'guard', '~> 2.13'