As of rspec-rails-2.0.0.beta.17, generators and rake tasks are exposed through a Railtie. In order to see them when you run rails generate and rake -T, you need to include the rspec-rails gem in the :development group in your Gemfile.

group :development, :test do
  gem "rspec-rails", ">= 2.0.0.beta.17"
end

If you have a previous version of rspec-rails-2.0.0.beta installed, you should also remove these files:

lib/tasks/rspec.rake
config/initializers/rspec_generator.rb

8 Responses to “rspec-rails-2 generators and rake tasks”

  1. Mark Says:

    Can you expound a bit on the reason behind the change?

  2. David Chelimsky Says:

    @Mark - this is the recommended way forward for Rails-3 extensions that are environment-specific.

    One benefit is that less stuff gets copied to your app, which means simpler installation and upgrades.

    Another benefit is that the rake tasks are not loaded in environments they don’t belong in. This means that you don’t need to install rspec on your production boxes just to get rails to load. This was true before, but we had to do some ugly hacking to make it work, which this change allowed us to remove: http://github.com/rspec/rspec-rails/commit/4d1d66371c88add105d9ef997150393ba8196a60

  3. Marcelo Silveira Says:

    Hey David, just a heads up that my initializer file was “rspec_generator.rb” (without the S) instead of “rspec_generators.rb”.

    Amazed with the progress in each beta. Thanks a lot and congrats.

    Cheers!

  4. Marcelo Silveira Says:

    David, just noticed that when I delete lib/tasks/rspec.rake, “rake spec” no longer runs my specs. Any known issue around that?

  5. David Chelimsky Says:

    @Marcelo - did you add rspec-rails to the :development group?

  6. David Chelimsky Says:

    @Marcelo - I updated the post to say “rspec_generator.rb” - thx.

  7. Marcelo Silveira Says:

    @david, you’re right, adding it to the dev group made it work. Thanks.

    I’m a bit confuse though. I understand exposing the generators only to the dev group, but the rake tasks seems a bit confusing to me. For instance, I can now run the specs without having rspec-rails in my test group. Am I missing something?

    Cheers!

  8. David Chelimsky Says:

    @Marcelo - I followed up in a separate blog post: http://blog.davidchelimsky.net/2010/07/11/rspec-rails-2-generators-and-rake-tasks-part-ii/

    Cheers, David

Leave a Reply