19

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

user715697
  • 857
  • 1
  • 10
  • 20

6 Answers6

15

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
Tombart
  • 30,520
  • 16
  • 123
  • 136
dogenpunk
  • 4,332
  • 1
  • 21
  • 29
8

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.

korebantic
  • 81
  • 1
  • 1
7

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"
mtrolle
  • 2,234
  • 20
  • 19
7

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

Sujeev
  • 276
  • 4
  • 10
6

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
Sharvy Ahmed
  • 7,247
  • 1
  • 33
  • 46
Pedro Paiva
  • 721
  • 11
  • 17
1

The cleanest way, as I mention in a similar question and answer is to do this...

For Rails 3, to remove test_unit from your application, you need to remove (or comment out) the test_unit Railtie in config/application.rb:

# require "rails/test_unit/railtie"

If you are curious about what this line of code does, check out the railties/lib/rails/test_unit/railtie.rb source which currently looks like this:

module Rails
  class TestUnitRailtie < Rails::Railtie
    config.app_generators do |c|
      c.test_framework :test_unit, :fixture => true,
                                   :fixture_replacement => nil

      c.integration_tool :test_unit
      c.performance_tool :test_unit
    end

    rake_tasks do
      load "rails/test_unit/testing.rake"
    end
  end
end
Community
  • 1
  • 1
David J.
  • 31,569
  • 22
  • 122
  • 174