I'm going through a tutorial that has suggested using rspec
, but I have already gone through a lot of default rails installation. I really don't want to have to redo the installation at all. Anyway, when I run
$ rails g integration_test named
I get
invoke test_unit
create test/integration/named_test.rb
When I run bundle
, various rspec
gems are listed, but test_unit
is not. The tutorial seems to have rails invoke rspec
instead of test_unit
without doing anything additional. How do I get rails to use rspec
with the integration test generator command?
Working with Rails 3.2.8 and rspec-rails 2.11.4, I discovered that my problem was in my Gemfile. I had
rspec-rails
in the:test
group but not the:development
group. Since Rails defaults to running in development mode (including when you're running generate),rspec-rails
has to be in your:development
group for it to hook into the generators. Once I had that in place, everything worked fine.To use RSpec instead of default Test::Unit, run following command first
This command will create following folder/files
Now whenever you used generator to generate rails components like controller, model etc, it will create corresponding RSpecs.
As of Rails 3.2.12, follow these steps in order
Add rspec-rails to your Gemfile in the development, test group
Run
bundle install
Run the generator
... and cleanup your existing test directory:
Came across this issue today. application.rb has to be updated with:
1. when create new rails app, skip TestUnit framework, or it will generate test_unit directory.
$rails new your_app --skip-test-unit
2. add below code to your_app/config/application.rb file:
config.generators do |g| g.test_framework :rspec end
3. add below code to your_app's Gemfile:
group :test, :development do gem 'rspec-rails' end
save it, and runbundle install
to install rspec gem4. Initialize the spec/ directory
rails generate rspec:install
more details, please refer: https://github.com/rspec/rspec-rails
Running script/rails generate rspec:install does not add rspec as default framework. Added below command in config/application.rb and then it works