Ontic-stackoverflow
Ontic-stackoverflow

Reputation: 33

Rails Tutorial: Testing Error (Cannot Load Such File)

Complete beginner here. I've been working through the Hartl Rails tutorial--currently the "Advanced Testing Setup" for the optional exercises in Chapter 3. Though testing was running smoothly beforehand, I'm getting the following error upon running either "rake test" or "guard":

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)

I'm using the standard Gems file from the tutorial:

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

I'm sure this is not a difficult fix, but thought I might as well ask. Thanks so much!

Upvotes: 3

Views: 4575

Answers (3)

moch bili
moch bili

Reputation: 1

put this you your gemfile:

gem 'guard', '~> 2.13'

Upvotes: -1

Ammad Baig
Ammad Baig

Reputation: 43

It seems that you have a problem with the require statement as Joel mentioned. Be sure to have a 'guard' installed before 'guard-minitest'.

Add gem 'guard' to to your gem file & run bundle install. I hope it will fix the problem.

Upvotes: 3

Joel Brewer
Joel Brewer

Reputation: 1652

Looks like you have an error with your require statement.

have you added the following code to your test_helper file? (Copied from 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

Pay specific attention to this line:

require File.expand_path('../../config/environment', __FILE__)

Upvotes: 0

Related Questions