Rspec Error

I added the following to the application.rb file

config.generators do |g|
    g.test_framework :rspec,

        :fixtures => true,
        :view_specs => false,
        :helper_specs => false,
        :routing_specs => false,
        :controller_specs => true,
        :request_specs => true

    g.fixture_replacement :factory_girl, :dir => "spec/factories"
end

Then I generated a controller with

$rails g controller home index

This created a spec in spec / controllers / home_controller_spec.rb that looks like

describe HomeController do

  describe "GET 'index'" do
    it "returns http success" do
      get 'index'
      response.should be_success
    end
  end

end

This is the default code generated by rSpec. I see the page when I visit

http://localhost:3000/home/index 

in my browser

Then when I started

$bundle exec rspec

I get this error

/Applications/MAMP/htdocs/2012/myapp/spec/controllers/home_controller_spec.rb:3:in `<top (required)>': uninitialized constant HomeController (NameError)
from /Users/bobwood/.rvm/gems/ruby-1.9.3-p194@myapp/gems/rspec-core-2.10.1/lib/rspec/core/configuration.rb:746:in `load'
from /Users/bobwood/.rvm/gems/ruby-1.9.3-p194@myapp/gems/rspec-core-2.10.1/lib/rspec/core/configuration.rb:746:in `block in load_spec_files'
from /Users/bobwood/.rvm/gems/ruby-1.9.3-p194@myapp/gems/rspec-core-2.10.1/lib/rspec/core/configuration.rb:746:in `map'
from /Users/bobwood/.rvm/gems/ruby-1.9.3-p194@myapp/gems/rspec-core-2.10.1/lib/rspec/core/configuration.rb:746:in `load_spec_files'
from /Users/bobwood/.rvm/gems/ruby-1.9.3-p194@myapp/gems/rspec-core-2.10.1/lib/rspec/core/command_line.rb:22:in `run'
from /Users/bobwood/.rvm/gems/ruby-1.9.3-p194@myapp/gems/rspec-core-2.10.1/lib/rspec/core/runner.rb:69:in `run'
from /Users/bobwood/.rvm/gems/ruby-1.9.3-p194@myapp/gems/rspec-core-2.10.1/lib/rspec/core/runner.rb:10:in `block in autorun'

What does this error mean and how to fix it?

EDIT: routes.rb has one line in it

get "home/index"
0
source share
1 answer

This error means that the spec executable does not know about your class HomeController- it is not included.

, RSpec Rails. - rspec-rails. , , , rspec_helper.rb, rspec-rails. , Rails, .

rspec-rails , , Gemfile :

rails generate rspec:install

+1

All Articles