Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove test::unit

I forgot to create my application with the -T argument and now it's installed with test::unit. How do I remove test::unit and stop it from creating tests for each controller / model generated, after I have already created the application? Thank you

like image 886
user715697 Avatar asked May 15 '11 14:05

user715697


5 Answers

In your config/application.rb try

config.generators do |g|
  g.test_framework :rspec #=> or whatever
end

In response to comment

Try

config.generators do |g|
  g.test_framework nil
end

May not be the "most appropriate" or Rails-ish way, but it works

Update

I was reading the Rails Initialization Guide today and realized that the most likely reason Test::Unit is still being included is this line:

require 'rails/all'

Which could be replaced with:

require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "active_resource/railtie"

This should take care of the issue. If you're using Rails 3.1.x you'd also include

require "sprockets/railtie"

if you're planning on using the asset pipeline.

Update 2

For Rails 3.2 you should use this:

config.app_generators do |c|
  c.test_framework :rspec, :fixture => true,
                           :fixture_replacement => nil

  c.integration_tool :rspec
  c.performance_tool :rspec
end
like image 176
dogenpunk Avatar answered Nov 09 '22 18:11

dogenpunk


To remove Test:Unit in Rails 4:

Replace the following line from config/application.rb:

require 'rails/all'

With:

require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "sprockets/railtie"

You can safely remove the test directory as well.

like image 45
korebantic Avatar answered Nov 09 '22 19:11

korebantic


Build a new application with rails new APP_NAME --skip-test-unit in Rails 4 results in:

require "rails"
# Pick the frameworks you want:
require "active_model/railtie"
require "active_job/railtie"
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_view/railtie"
require "sprockets/railtie"
# require "rails/test_unit/railtie"
like image 7
mtrolle Avatar answered Nov 09 '22 19:11

mtrolle


On Rails 5.1 and Rails 5.2

in config/application.rb

remove or comment out

require 'rails/all'

and then include

require "rails"
# Pick the frameworks you want:
require "active_model/railtie"
require "active_job/railtie"
require "active_record/railtie"
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_view/railtie"
require "action_cable/engine"
require "sprockets/railtie"
# require "rails/test_unit/railtie"

Also if you do not wish to generate system test files add the following:

# Don't generate system test files.
config.generators.system_tests = nil

Once this is done, you can delete the test directory

like image 7
Sujeev Avatar answered Nov 09 '22 18:11

Sujeev


On Rails 6 in config/application.rb replace

require 'rails/all'

For:

require "rails"
# Pick the frameworks you want:
require "active_model/railtie"
require "active_job/railtie"
require "active_record/railtie"
require "active_storage/engine"
require "action_controller/railtie"
require "action_mailer/railtie"
require "action_mailbox/engine"
require "action_text/engine"
require "action_view/railtie"
require "action_cable/engine"
require "sprockets/railtie"
# require "rails/test_unit/railtie"

Add config.generators.system_tests = nil to the Application block like this:

module YourApp
  class Application < Rails::Application
    ...
    ...

    # Don't generate system test files.
    config.generators.system_tests = nil
  end
end
like image 5
Pedro Paiva Avatar answered Nov 09 '22 17:11

Pedro Paiva