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 Build a Todo List Application with Rails 4 Build a Todo List Application with Rails 4 Write Our First Tests

Alex Lowe
Alex Lowe
15,147 Points

load error after rspec ../create_spec.rb

I'm getting this error message:

/home/alex/.rbenv/versions/2.1.5/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- spec_helper (LoadError)
    from /home/alex/.rbenv/versions/2.1.5/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from /home/alex/projects/odot/spec/features/todo_lists/create_spec.rb:1:in `<top (required)>'
    from /home/alex/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.1/lib/rspec/core/configuration.rb:1226:in `load'
    from /home/alex/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.1/lib/rspec/core/configuration.rb:1226:in `block in load_spec_files'
    from /home/alex/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.1/lib/rspec/core/configuration.rb:1224:in `each'
    from /home/alex/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.1/lib/rspec/core/configuration.rb:1224:in `load_spec_files'
    from /home/alex/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.1/lib/rspec/core/runner.rb:97:in `setup'
    from /home/alex/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.1/lib/rspec/core/runner.rb:85:in `run'
    from /home/alex/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.1/lib/rspec/core/runner.rb:70:in `run'
    from /home/alex/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.1/lib/rspec/core/runner.rb:38:in `invoke'
    from /home/alex/.rbenv/versions/2.1.5/lib/ruby/gems/2.1.0/gems/rspec-core-3.2.1/exe/rspec:4:in `<top (required)>'
    from /home/alex/.rbenv/versions/2.1.5/bin/rspec:23:in `load'
    from /home/alex/.rbenv/versions/2.1.5/bin/rspec:23:in `<main>'

I'm using Linux. Does anyone know what's wrong, or what I could do to fix it? Any help would be appreciated , but I think I'm going to end up starting from scratch with the Treehouse VM on my Windows PC.

4 Answers

Alex Lowe
Alex Lowe
15,147 Points

Ok, so I finally got it working.

in the Gemfile I changed the rspec gem to this:

gem 'rspec-rails', '< 3.0.0'

then in the terminal I ran:

bundle

then:

rails generate rspec:install

And I'm not sure if this is required but I ran this:

bundle binstubs rspec-core --force

And now rspec works, but it needs to have bundle exec prepended to the command, like this:

bundle exec rspec spec/features/todo_lists/create_spec.rb
Alex Lowe
Alex Lowe
15,147 Points

I think this might have also changed my spec_helper.rb file, so just check and put " require 'capybara/rspec' " in there if it's missing.

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

Yeah, if you just write rspec, it will execute the version that is installed on your system, which is 3.x. Bundle exec will use the specific version from the Gemfile.

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

You are using RSpec 3.2 and the videos use the old RSpec 2.x. So your test code will have to look a little bit different unless you downgrade your rspec gem.

Alex Lowe
Alex Lowe
15,147 Points

I found someting similar on StackOverflow. Would it work like this:

gem "rspec", "2.0"

in my gemfile, and then run:

bundle update rspec
Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

Maybe :). You won't know until you try. Make sure you use git to reverse the changes if something breaks.

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

Perhaps this would be better, to get the last version before 3.0: gem "rspec", "< 3"

Alex Lowe
Alex Lowe
15,147 Points

So I've got this in my gemfile:

group :development, :test do
  # Call 'byebug' anywhere in the code to stop execution and get a debugger console
  gem 'byebug'

  # Access an IRB console on exception pages or by using <%= console %> in views
  gem 'web-console', '~> 2.0'

  # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
  gem 'spring'

  gem 'rspec', '< 3.0.0'
end

And I saved. But I'm not sure what to do in the terminal. I've tried bundle update rspec, and got a message that said "could not find rspec", then I tried just bundle, which did...something. I'm getting the same error message as before though when I try rspec ../create_spec.rb and when I do rspec -v, it says 3.2.1.

Maciej Czuchnowski
Maciej Czuchnowski
36,441 Points

Oh, sorry, use rspec-rails. So:

gem 'rspec-rails', '< 3'

And then do the whole whole bundle install.

Ian Holl
Ian Holl
4,883 Points

I am getting this problem a the same point anyone get ideas?

/Users/Ian/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/rspec-core-2.99.2/lib/rspec/core/configuration.rb:1065:in load': /Users/Ian/treehouse/projects/odot/spec/features/todo_lists/create_spec.rb:34: syntax error, unexpected keyword_end, expecting end-of-input (SyntaxError) from /Users/Ian/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/rspec-core-2.99.2/lib/rspec/core/configuration.rb:1065:inblock in load_spec_files' from /Users/Ian/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/rspec-core-2.99.2/lib/rspec/core/configuration.rb:1065:in each' from /Users/Ian/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/rspec-core-2.99.2/lib/rspec/core/configuration.rb:1065:inload_spec_files' from /Users/Ian/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/rspec-core-2.99.2/lib/rspec/core/command_line.rb:18:in run' from /Users/Ian/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/rspec-core-2.99.2/lib/rspec/core/runner.rb:103:inrun' from /Users/Ian/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/rspec-core-2.99.2/lib/rspec/core/runner.rb:17:in `block in autorun'

Alex Lowe
Alex Lowe
15,147 Points

The Best answer worked for me

Ian Holl
Ian Holl
4,883 Points

I added: gem 'rspec-rails', '< 3.0.0'.

ran bundle ran rails generate rspec:install ran bundle binstubs rspec-core --force ran bundle exec rspec spec/features/todo_lists/create_spec.rb

but I get the same answer when I enter bin/rspec spec/features/todo_lists/create_spec.rb

I get the same thing

Alex Lowe
Alex Lowe
15,147 Points

It's got to be: bundle exec rspec spec/features/todo_lists/create_spec.rb

bundle exec makes it use the older version that you installed. I'm not sure if you need the "bin/" before rspec, I do not.