Ruby on Rails: switching from test_unit to rspec

I go through a tutorial that suggested using rspec , but I already went through a lot of default settings. I really don't want 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 not. The tutorial seems to have rails calling rspec instead of test_unit without doing anything extra. How to get rails for using rspec using the test integrator generator command?

+57
ruby-on-rails gem rspec testunit
Mar 27 2018-12-12T00:
source share
9 answers

In your config/application.rb file:

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

Now, when you run the generators, you get the rspec test files. Do not forget to restart the server. For more information about generators see:

RailsCasts # 216 Generators in Rails 3

If you really want to use the Integration_test generator:

 rails g integration_test named --integration-tool=rspec 
+86
Mar 27 '12 at 5:59
source share

Work with Rails 3.2.8 and rspec-rails 2.11.4 . I found that my problem was in my gemfile. I have rspec-rails in group :test , but not in group :development . Since Rails works by default in design mode (including when starting generation), rspec-rails must be in your group :development so that it connects to generators. As soon as I had it in place, everything worked fine.

+63
Nov 02
source share

As of Rails 3.2.12, do the following:

 rails new app_name --skip-test-unit 

Add rspec-rails to your Gemfile in the development, testing team

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

Run bundle install

Start the generator

 rails generate rspec:install 

... and clear the existing test directory:

 rm -Rf $RAILS_ROOT/test 
+21
Apr 15 '13 at 5:15
source share

To use RSpec instead of the standard Test :: Unit, first run the following command

 $ rails generate rspec:install 

This command will create the following folders / files

 create .rspec create spec create spec/spec_helper.rb 

Now that you have used the generator to create rail components such as a controller, model, etc., it will create the corresponding RSpec.

+8
Mar 28 '12 at 12:17
source share

Passed this question today. application.rb needs to be updated:

 config.generators do |g| g.test_framework :rspec g.integration_tool :rspec end 
+7
Jul 19 '12 at 8:20
source share

1. When creating a new rails application, skip the TestUnit frame or create the 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 the code below to your Gemfile:

group :test, :development do gem 'rspec-rails' end save it and run bundle install to install rspec gem

4. Initialize the spec / directory

rails generate rspec:install

see below for more details: https://github.com/rspec/rspec-rails

+2
Aug 23 '14 at 13:38 on
source share

What I found, what I did, that some of the other methods still work, was to check my spelling. I had the fact that @tovodeverett grouped rspec-rails with: development and: test, but misspelled the development. This fixed my problem, but I generated tests using test_unit instead of rspec.

+1
Dec 19
source share

In config / application add this code

  config.generators do |g| g.test_framework :rspec g.integration_tool :rspec end 
+1
Jul 18 '13 at 9:13
source share
 $ rails g model Account invoke active_record create db/migrate/20140205052617_create_accounts.rb create app/models/account.rb invoke test_unit create test/models/account_test.rb create test/fixtures/accounts.yml $ rails d model Account 

Running script / rails generate rspec: install does not add rspec as the default frame. Added command below in config / application.rb and then it works

 config.generators do |g| g.test_framework :rspec end $ rails g model Account invoke active_record create db/migrate/20140205052957_create_accounts.rb create app/models/account.rb invoke rspec create spec/models/account_spec.rb $ rails -v Rails 4.0.2 
+1
Feb 05 '14 at 5:51
source share



All Articles