Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

kabir k
PLUS
kabir k
Courses Plus Student 18,036 Points

Got a different error message after running `bin/rake` command in the terminal

I got the following error message after running bin/rake command in the terminal, which is different from what Jason has on the Using has_secure_password video at 2:47

Can someone figure out what the problem is and how to fix it, thanks.

treehouse:~/projects/odot (master *) $ bin/rake /home/treehouse/.rbenv/versions/2.0.0-p353/bin/ruby -I/home/treehouse/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/rspec-core-3.0.4/lib:/home/treehouse/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/rspec-support-3.0.4/lib -S /home/treehouse/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/rspec-core-3.0.4/exe/rspec ./spec/controllers/todo_items_controller_spec.rb ./spec/controllers/todo_lists_controller_spec.rb ./spec/controllers/users_controller_spec.rb ./spec/features/todo_items/complete_spec.rb ./spec/features/todo_items/create_spec.rb ./spec/features/todo_items/delete_spec.rb ./spec/features/todo_items/edit_spec.rb ./spec/features/todo_items/index_spec.rb ./spec/features/todo_lists/create_spec.rb ./spec/features/todo_lists/destroy_spec.rb ./spec/features/todo_lists/edit_spec.rb ./spec/helpers/todo_items_helper_spec.rb ./spec/helpers/todo_lists_helper_spec.rb ./spec/helpers/users_helper_spec.rb ./spec/models/todo_item_spec.rb ./spec/models/todo_list_spec.rb ./spec/models/user_spec.rb ./spec/requests/todo_lists_spec.rb ./spec/routing/todo_lists_routing_spec.rb ./spec/routing/users_routing_spec.rb ./spec/views/todo_items/index.html.erb_spec.rb ./spec/views/todo_lists/edit.html.erb_spec.rb ./spec/views/todo_lists/index.html.erb_spec.rb ./spec/views/todo_lists/new.html.erb_spec.rb ./spec/views/todo_lists/show.html.erb_spec.rb ./spec/views/users/edit.html.erb_spec.rb ./spec/views/users/new.html.erb_spec.rb ./spec/views/users/show.html.erb_spec.rb /home/treehouse/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:229:in require': cannot load such file -- rails_helper (LoadError) from /home/treehouse/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:229:inblock in require' from /home/treehouse/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:214:in load_dependency' from /home/treehouse/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:229:inrequire' from /home/treehouse/projects/odot/spec/controllers/users_controller_spec.rb:1:in <top (required)>' from /home/treehouse/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:223:inload' from /home/treehouse/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:223:in block in load' from /home/treehouse/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:214:inload_dependency' from /home/treehouse/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/activesupport-4.0.1/lib/active_support/dependencies.rb:223:in load' from /home/treehouse/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/rspec-core-3.0.4/lib/rspec/core/configuration.rb:1058:inblock in load_spec_files' from /home/treehouse/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/rspec-core-3.0.4/lib/rspec/core/configuration.rb:1058:in each' from /home/treehouse/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/rspec-core-3.0.4/lib/rspec/core/configuration.rb:1058:inload_spec_files' from /home/treehouse/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:97:in setup' from /home/treehouse/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:85:inrun' from /home/treehouse/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:70:in run' from /home/treehouse/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/rspec-core-3.0.4/lib/rspec/core/runner.rb:38:ininvoke' from /home/treehouse/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/rspec-core-3.0.4/exe/rspec:4:in `<main>' /home/treehouse/.rbenv/versions/2.0.0-p353/bin/ruby -I/home/treehouse/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/rspec-core-3.0.4/lib:/home/treehouse/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/rspec-support-3.0.4/lib -S /home/treehouse/.rbenv/versions/2.0.0-p353/lib/ruby/gems/2.0.0/gems/rspec-core-3.0.4/exe/rspec ./spec/controllers/todo_items_controller_spec.rb ./spec/controllers/todo_lists_controller_spec.rb ./spec/controllers/users_controller_spec.rb ./spec/features/todo_items/complete_spec.rb ./spec/features/todo_items/create_spec.rb ./spec/features/todo_items/delete_spec.rb ./spec/features/todo_items/edit_spec.rb ./spec/features/todo_items/index_spec.rb ./spec/features/todo_lists/create_spec.rb ./spec/features/todo_lists/destroy_spec.rb ./spec/features/todo_lists/edit_spec.rb ./spec/helpers/todo_items_helper_spec.rb ./spec/helpers/todo_lists_helper_spec.rb ./spec/helpers/users_helper_spec.rb ./spec/models/todo_item_spec.rb ./spec/models/todo_list_spec.rb ./spec/models/user_spec.rb ./spec/requests/todo_lists_spec.rb ./spec/routing/todo_lists_routing_spec.rb ./spec/routing/users_routing_spec.rb ./spec/views/todo_items/index.html.erb_spec.rb ./spec/views/todo_lists/edit.html.erb_spec.rb ./spec/views/todo_lists/index.html.erb_spec.rb ./spec/views/todo_lists/new.html.erb_spec.rb ./spec/views/todo_lists/show.html.erb_spec.rb ./spec/views/users/edit.html.erb_spec.rb ./spec/views/users/new.html.erb_spec.rb ./spec/views/users/show.html.erb_spec.rb failed treehouse:~/projects/odot (master *) $

1 Answer

Seth Reece
Seth Reece
32,867 Points

Hi Kabir,

The error you are getting is "cannot load such file -- rails_helper". What version of rspec are you using in your gem file? If you are using rspec 3, you want to require rails_helper instead of spec_helper in all you spec files. All custom configuration also goes into rails_helper instead of spec_helper. If you are using rspec 2, then there is only a spec_helper, and no rails_helper. In this case make sure all your spec files require spec_helper and not rails_helper.

kabir k
kabir k
Courses Plus Student 18,036 Points

Hi Seth,

Thanks for your response. I believe I'm using version 3. Here's my Gemfile:

source 'https://rubygems.org'

gem 'rails', '4.0.1'
gem 'bcrypt-ruby', '~> 3.1.2'
gem 'sqlite3'
gem 'sass-rails', '~> 4.0.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.0.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 1.2'



group :doc do
  # bundle exec rake doc:rails generates the API under doc/api.
  gem 'sdoc', require: false
end

group :development, :test do
    gem 'rspec-rails', '~> 3.0.0' 
    gem 'rspec-expectations', '~> 3.0.0'
    # Support for stubbing model in view specs:
    gem 'rspec-activemodel-mocks', '~> 1.0.1'
end

group :test do
    gem 'capybara', '~> 2.3.0'
    gem 'shoulda-matchers', '~> 2.8.0'
end

Do I have to manually require rails_helper instead of spec_helper in all my spec files or there's an automated way to do that. And when I'm done with the changes do I run bundle install as well?

Also, what do you mean by "All custom configuration also goes into rails_helper instead of spec_helper"?

Seth Reece
Seth Reece
32,867 Points

If you don't have 'rails_helper.rb' in your spec folder, try changing the rspec-rails gem to 2.0, then bundle. (This would be the easiest option.) If you want to use 3.0, see if running rails generate rspec:install creates a rails_helper in your spec folder. If it does, then you will want to put require 'rails_helper' at the top of all your spec files. If you have any requires in spec_helper, like require 'rspec-rails' you will want them in rails_helper.

kabir k
kabir k
Courses Plus Student 18,036 Points

Hey Seth, thanks a lot. I see I have two options now and sorry to be such a pain but I don't really get the last sentence of your response. Can you give me an example of what to do here?

Also, after changing to 2.0, do I just run bundle or bundle install?

Seth Reece
Seth Reece
32,867 Points

Bundle should work. If not you might need to edit you Gemfile.lock to remove rspec from it and rebundle. (Or delete Gemfile.lock and run bundle. As an example of putting configuration files in rails helper...

 # spec_helper.rb

RSpec.configure do |config|
  config.expect_with :rspec do |expectations|
    expectations.include_chain_clauses_in_custom_matcher_descriptions = true
  end

  config.mock_with :rspec do |mocks|
    mocks.verify_partial_doubles = true
  end
end
# rails_helper.rb

ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
abort("The Rails environment is running in production mode!") if Rails.env.production?
require 'spec_helper' # requires spec_helper her so requiring rails_helper includes spec_helper
require 'rspec/rails' # requires rails version on rspec
ActiveRecord::Migration.maintain_test_schema!

RSpec.configure do |config|
  config.fixture_path = "#{::Rails.root}/spec/fixtures"
  config.use_transactional_fixtures = true
  config.infer_spec_type_from_file_location!
end

# If you we're using the most recent shoulda-matchers gem,
# you would need to add this section to rails_helper in rspec 3,
# or add it to spec_helper in rspec 2

Shoulda::Matchers.configure do |config|
  config.integrate do |with|
    # Choose a test framework:
    with.test_framework :rspec
    # with.test_framework :minitest
    # with.test_framework :minitest_4
    # with.test_framework :test_unit

    # Choose one or more libraries:
    # with.library :active_record
    # with.library :active_model
    # with.library :action_controller
    # Or, choose the following (which implies all of the above):
    with.library :rails
  end
end

Hope that makes sense.

kabir k
kabir k
Courses Plus Student 18,036 Points

I ran bundle after making the changes to spec_helper which was successful. Here's my spec_helper.rb file (which looks a lot like the rails_helper.rb that you showed me)

# This file is copied to spec/ when you run 'rails generate rspec:install'
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'capybara/rspec'

# Requires supporting ruby files with custom matchers and macros, etc, in
# spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
# run as spec files by default. This means that files in spec/support that end
# in _spec.rb will both be required and run as specs, causing the specs to be
# run twice. It is recommended that you do not name files matching this glob to
# end with _spec.rb. You can configure this pattern with with the --pattern
# option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }

# Checks for pending migrations before tests are run.
# If you are not using ActiveRecord, you can remove this line.
ActiveRecord::Migration.check_pending! if defined?(ActiveRecord::Migration)

RSpec.configure do |config|
  config.include TodoListHelpers, type: :feature
  config.include RailsDomIdHelper, type: :feature

  config.expose_current_running_example_as :example
  # ## Mock Framework
  #
  # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
  #
  # config.mock_with :mocha
  # config.mock_with :flexmock
  # config.mock_with :rr

  # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
  config.fixture_path = "#{::Rails.root}/spec/fixtures"

  # If you're not using ActiveRecord, or you'd prefer not to run each of your
  # examples within a transaction, remove the following line or assign false
  # instead of true.
  config.use_transactional_fixtures = true

  # If true, the base class of anonymous controllers will be inferred
  # automatically. This will be the default behavior in future versions of
  # rspec-rails.
  config.infer_base_class_for_anonymous_controllers = false

  # Run specs in random order to surface order dependencies. If you find an
  # order dependency and want to debug it, you can fix the order by providing
  # the seed, which is printed after each run.
  #     --seed 1234
  config.order = "random"

  # RSpec Rails can automatically mix in different behaviours to your tests
  # based on their file location, for example enabling you to call `get` and
  # `post` in specs under `spec/controllers`.
  #
  # You can disable this behaviour by removing the line below, and instead
  # explictly tag your specs with their type, e.g.:
  #
  #     describe UsersController, :type => :controller do
  #       # ...
  #     end
  #
  # The different available types are documented in the features, such as in
  # https://relishapp.com/rspec/rspec-rails/v/3-0/docs
  config.infer_spec_type_from_file_location!

  config.raise_errors_for_deprecations!

  config.mock_with :rspec do |c|
    c.syntax = [:should, :expect]
  end
  config.expect_with :rspec do |c|
    c.syntax = [:should, :expect]
  end

end
Seth Reece
Seth Reece
32,867 Points

Yea, it appears that you probably started with rspec 2 and then later changed to rspec 3 in your gem file. I would stick with rspec 2 for the course, but would encourage you to create an app afterwards using rspec 3.

kabir k
kabir k
Courses Plus Student 18,036 Points

I give up. It's not working. I changed to rspec 3 because at the beginning of the new course, they suggested using the newer version for Installing a Ruby Development Environment which messed up my whole odot project. It's just super confusing and annoying.

The videos themselves use rspec 2, shouldn't they make a separate set of videos for rspec 3 that uses this newer version from beginning to the end? Instead of including rspec 3 midway and suggesting including this newer version which ended up not matching the rspec 2 videos.

Seth Reece
Seth Reece
32,867 Points

It's a bit confusing at first. At the rate of speed that Ruby on Rails changes, it's not a bad idea to learn older stuff. Take a look at the version history. You might find yourself having to work on an older project. It's important to lock in gem versions so that anyone, at anytime can run an app. Then look at any changes in gems if they want to upgrade. I would suggest going with rspec 2 since that's what Jason used, then look at his workshop on upgrading an app.

kabir k
kabir k
Courses Plus Student 18,036 Points

The problem is, I can't even go back to rspec 2 anymore as my whole odot project now is messed up because they included rspec 3 in User Authentication part of the project as if to suggest we should upgrade midway in the project instead of separating the 2 versions since they are not compatible or show steps to make them work together if possible. I can't continue with it anymore. I have wasted time and money trying to figure it out on my own and make it work to no avail.

It took me forever to get to this point in the odot project, I'm not about to start all over again.

But thanks anyway, for your effort.

Seth Reece
Seth Reece
32,867 Points

Make a backup copy of spec_helper.rb.

If you have a rails_helper.rb file, delete it.

Change your gem to:

gem 'rspec-rails', '~> 2.0'

Then in your console type:

bundle install

then in your console type:

rails generate rspec:install

You will get a conflict message for .rspec. Choose Y. You will get a conflict message for spec_helper.rb. Choose Y

In the newly created spec_helper.rb add the line:

require 'capybara/rspec'

Right below:

require 'rspec/rails'

I believe "./spec/views/users/show.html.erb_spec.rb" is the only file you have with "require 'rails_helper'. Change that to spec_helper.

You should be good to go. If there are any other configurations that you need for spec_helper.rb, you made a backup to compare to.

kabir k
kabir k
Courses Plus Student 18,036 Points

Thanks, Seth. I really appreciate your taking the time to provide the steps to solve this problem. I will have to find time to come back and do it again to see if it works.