Search code examples
ruby-on-railsrspecminitest

How to remove Minitest from existing Rails 6 app?


I want to achieve exactly the opposite to this question. I have already included rspec and it is working well but when running rake I get:

WARN: Unresolved or ambiguous specs during Gem::Specification.reset:                                                                                                                                                              
      minitest (~> 5.1)                                                                                                                                                                                                           
      Available/installed versions of this gem:                                                                                                                                                                                   
      - 5.14.4                                                                                                                                                                                                                    
      - 5.13.0                                                                                                                                                                                                                    
WARN: Clearing out unresolved specs. Try 'gem cleanup <gem>'                                                                                                                                                                      
Please report a bug if this causes problems. 

I'm aware of removing one of the ministest versions will stop warnings but I'm not concerned about warnings at all. My key point here is to remove some suite I'm not using within my project. Any clue how to do it ?


Solution

  • What I would do is create one test installation of rails with unit tests and one without:

    rails new tester
    

    and

    rails new tester --skip-test
    

    you would have to do this in separate folders so the they wouldn't collide.

    You could then do a diff between the two folders to find what you need to change in your installation.

    Visual studio code has a plugin called "Compare Folders" which should do the trick.

    --- After doing the above ---

    It looks like the only things you need to do are:

    • Remove the test section in your Gemfile

    • run bundle

    then change the config/application.rb file as follows:

    from

        require_relative "boot"
    
        require "rails/all"
    
        # Require the gems listed in Gemfile, including any gems
        # you've limited to :test, :development, or :production.
        Bundler.require(*Rails.groups)
    
        module Tester
          class Application < Rails::Application
            # Initialize configuration defaults for originally generated Rails version.
            config.load_defaults 6.1
    
            # Configuration for the application, engines, and railties goes here.
            #
            # These settings can be overridden in specific environments using the files
            # in config/environments, which are processed later.
            #
            # config.time_zone = "Central Time (US & Canada)"
            # config.eager_load_paths << Rails.root.join("extras")
          end
        end
    

    to

        require_relative "boot"
    
        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"
    
        # Require the gems listed in Gemfile, including any gems
        # you've limited to :test, :development, or :production.
        Bundler.require(*Rails.groups)
    
        module Tester
          class Application < Rails::Application
            # Initialize configuration defaults for originally generated Rails version.
            config.load_defaults 6.1
    
            # Configuration for the application, engines, and railties goes here.
            #
            # These settings can be overridden in specific environments using the files
            # in config/environments, which are processed later.
            #
            # config.time_zone = "Central Time (US & Canada)"
            # config.eager_load_paths << Rails.root.join("extras")
    
            # Don't generate system test files.
            config.generators.system_tests = nil
          end
        end
    

    This was using Rails 6.1.3.