rspec-rails-2 generators and rake tasks
July 11th, 2010
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


July 11th, 2010 at 1:34 pm
Can you expound a bit on the reason behind the change?
July 11th, 2010 at 2:10 pm
@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
July 11th, 2010 at 2:19 pm
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!
July 11th, 2010 at 2:37 pm
David, just noticed that when I delete lib/tasks/rspec.rake, “rake spec” no longer runs my specs. Any known issue around that?
July 11th, 2010 at 3:55 pm
@Marcelo - did you add rspec-rails to the :development group?
July 11th, 2010 at 3:56 pm
@Marcelo - I updated the post to say “rspec_generator.rb” - thx.
July 11th, 2010 at 4:49 pm
@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!
July 11th, 2010 at 10:42 pm
@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