Search code examples
ruby-on-railsrspecrspec-rails

Uninitialized constant error in Rspec with Rails 3.0.5


I'm trying to set up a Rspec test for a simple controller for pages on Rails and got the following error:

 /var/lib/gems/1.9.1/gems/rspec-core-2.0.1/lib/rspec/core/backward_compatibility.rb:20:in `const_missing': uninitialized constant Object::PagesController (NameError)
from /var/lib/gems/1.9.1/gems/rspec-expectations-2.0.1/lib/rspec/expectations/backward_compatibility.rb:6:in `const_missing'
from /media/sf_ruby/tapa-g/spec/controllers/pages_controller_spec.rb:3:in `<top (required)>'
from /var/lib/gems/1.9.1/gems/rspec-core-2.0.1/lib/rspec/core/configuration.rb:306:in `load'
from /var/lib/gems/1.9.1/gems/rspec-core-2.0.1/lib/rspec/core/configuration.rb:306:in `block in load_spec_files'
from /var/lib/gems/1.9.1/gems/rspec-core-2.0.1/lib/rspec/core/configuration.rb:306:in `map'
from /var/lib/gems/1.9.1/gems/rspec-core-2.0.1/lib/rspec/core/configuration.rb:306:in `load_spec_files'
from /var/lib/gems/1.9.1/gems/rspec-core-2.0.1/lib/rspec/core/command_line.rb:18:in `run'
from /var/lib/gems/1.9.1/gems/rspec-core-2.0.1/lib/rspec/core/runner.rb:55:in `run_in_process'
from /var/lib/gems/1.9.1/gems/rspec-core-2.0.1/lib/rspec/core/runner.rb:46:in `run'
from /var/lib/gems/1.9.1/gems/rspec-core-2.0.1/lib/rspec/core/runner.rb:10:in `block in autorun'

I get this error whatever the command line I type, i.e.:

bundle exec rspec spec/controllers/pages_controller_spec.rb 
rake spec
rspec spec/

I have the following test in the spec/controllers/pages_controller_sprec.rb file:

require 'spec_helper'

describe PagesController do
    render_views

  describe "GET 'home'" do
      it "should be successful" do
         get 'home'
         response.should be_success
      end
  end
end

And my controller in app/controllers/pages_controller.rb file look like:

class PagesController < ApplicationController
skip_authorization_check 

  def home
    @title = "Home"
  end 


end

with other actions but not relevant here.

Here are the gems in my Gemfile:

source 'http://rubygems.org'

gem 'rails', '3.0.5'
gem 'will_paginate', '3.0.pre2'
gem 'jquery-rails', '>= 1.0.12'
gem "paperclip", "2.4.5"
gem "rake", "0.8.7"
gem "devise"
gem "cancan"
gem 'aws-s3'
gem 'acts_as_tree'

group :development do
  gem 'rspec-rails', "2.0.1"
  gem 'annotate'
  gem 'faker', '0.3.1', :require => false
  gem 'populator', '1.0.0'
  gem 'ruby-debug19'
end

group :test do
  gem 'webrat', '0.7.1'
  gem "capybara"
  gem 'rspec', '2.0.1'
  gem 'factory_girl_rails', '1.0'
end

I'm under Rails 3.0.5 with ruby 1.9.2.

I don't have a clue of here to look at. I already uninstall the rspec and rspec-rails gems and reinstall them without much success. I don't have neither autotest nor Spork installed to run the tests.

Does anybody have an idea?

Many thanks!


Solution

  • Well, following various comments on similar cases, I just install rspec with apt-get uninstall rspec and re-install rspec-rails with gem install rspec-rails. Now tests are working.