3

I'm following through the "Learn Rails by Example" book, and I'm trying to run the tests. For some reason I can't get rspec to work properly.

If I run the rspec spec/ command as he instructs, I get the following error:

$ rspec spec/
/home/desktop/.rvm/gems/ruby-1.9.2-p136/gems/bundler-1.0.21/lib/bundler/runtime.rb:31:in `block in setup': 
You have already activated rspec-core 2.7.1, but your Gemfile requires rspec-core 2.6.4. 
Using bundle exec may solve this. (Gem::LoadError)

The odd thing is my Gemfile doesn't specify version--

group :development do
  gem 'rspec-rails'
end

group :test do
  gem 'rspec'
  gem 'webrat'
end

If I follow the advice from the error message and use bundle exec rspec spec/ then the first two tests pass-- but the new "about" page we built in the tutorial fails with the following error, even though as far as I can tell the page I'd built (and controller actions etc.) are exactly as they should be:

Failures:

  1) PagesController GET 'about' should be successful
     Failure/Error: response.should_be_success
     NoMethodError:
       undefined method `should_be_success' for #<ActionController::TestResponse:0x00000003539438>
     # ./spec/controllers/pages_controller_spec.rb:23:in `block (3 levels) in <top (required)>'

Finished in 0.10861 seconds
3 examples, 1 failure

Failed examples:

rspec ./spec/controllers/pages_controller_spec.rb:21 # PagesController GET 'about' should be successful

I'm a pretty experienced programmer but I've run into endless issues with conflicting gem versions and a hundred different ways to accomplish all the different tasks using Rails (eg. "use RVM", "Don't use RVM", "install gems using sudo", "don't install gems using sudo" etc.)

My dev machine is running ubuntu linux.

Thanks for any help-- please explain if you would what I'm doing wrong in Ruby noob language!

julio
  • 6,630
  • 15
  • 60
  • 82

1 Answers1

6

Running bundle exec is correct, and is needed because you have a newer version of that gem installed that gets loaded instead of the one specified in your Gemfile.lock. Using bundle exec overrides the load path, causing only the gems specified in your Gemfile.lock to be loaded. (You may find it handy to alias bundle exec to something shorter.)

The answer to the second problem is right in the error messages:

undefined method `should_be_success'

it should be should be_success.

Andrew Marshall
  • 95,083
  • 20
  • 220
  • 214
  • thanks Andrew! I missed that error. Now all seems to be working. Is there a way to update the Gemfile.lock so that the "proper" rspec gem gets installed? – julio Oct 22 '11 at 16:23
  • Running `bundle update` will update all gems to the newest possible version given the dependency tree, and `bundle update rspec` will do so for just the specified gem. You should never update the lock file manually. – Andrew Marshall Oct 22 '11 at 16:27