ruby-on-railsruby-on-rails-3rspecrspec2rspec-rails

RSpec isn't generating spec files for my models and controllers


I have a Rails application using Rails 3.

I added rspec-rails to my Gemfile:

group :development, :test do
  gem 'rspec-rails'
end

and then I run bundle install. It shows my gem list, and all rspec gems are there (core, rails, etc.).

However, when I run

rails g rspec:install

that's what it returns:

create  .rspec
create  spec
create  spec/spec_helper.rb

Although I have models and controllers in my application, it just create those files. Why isn't Rspec creating the spec files?


Solution

  • Rspec doesn't automatically create specs for your existing models and controllers. You'll have to go create those files yourself now.

    Creating a spec file is really easy. Just make a file ending in _spec.rb and put this in it:

    require 'spec_helper';
    describe User do; 
    end 
    

    (of course replacing User with the class you are testing) and you're there.