How to blacklist directory loading in Rails?

activeadmin, dependencies, ruby, ruby-on-rails, rubygems

Solution

# config/environments/test.rb

path_rejector = lambda { |s| s.include?("app/admin") }

# Remove the path from being loaded when Rails starts:
config.eager_load_paths = config.eager_load_paths.reject(&path_rejector)

# Remove the path from being lazily loaded
ActiveSupport::Dependencies.autoload_paths.reject!(&path_rejector)

Problem

I want to disable ActiveAdmin when running the tests. So I add `require: false` to the Gemfile and checking `if defined?(ActiveAdmin)` in routes and initializer. But Rails still loads the models form `app/admin` thus I am getting error similar to `/app/admin/admin_user.rb:1:in`': uninitialized constant ActiveAdmin (NameError)` What is the best way to "blacklist" the `app/admin` directory from being loaded?

Original source