2017-07-09 08:06:36 -04:00
|
|
|
# frozen_string_literal: true
|
2017-07-10 09:39:13 -04:00
|
|
|
|
2013-03-12 01:03:32 -04:00
|
|
|
module DependenciesTestHelpers
|
2012-11-16 19:05:53 -05:00
|
|
|
def with_loading(*from)
|
|
|
|
old_mechanism, ActiveSupport::Dependencies.mechanism = ActiveSupport::Dependencies.mechanism, :load
|
2017-05-15 10:17:28 -04:00
|
|
|
this_dir = __dir__
|
2012-11-16 19:05:53 -05:00
|
|
|
parent_dir = File.dirname(this_dir)
|
|
|
|
path_copy = $LOAD_PATH.dup
|
|
|
|
$LOAD_PATH.unshift(parent_dir) unless $LOAD_PATH.include?(parent_dir)
|
|
|
|
prior_autoload_paths = ActiveSupport::Dependencies.autoload_paths
|
|
|
|
ActiveSupport::Dependencies.autoload_paths = from.collect { |f| "#{this_dir}/#{f}" }
|
|
|
|
yield
|
|
|
|
ensure
|
|
|
|
$LOAD_PATH.replace(path_copy)
|
|
|
|
ActiveSupport::Dependencies.autoload_paths = prior_autoload_paths
|
|
|
|
ActiveSupport::Dependencies.mechanism = old_mechanism
|
|
|
|
ActiveSupport::Dependencies.explicitly_unloadable_constants = []
|
2014-10-25 07:50:42 -04:00
|
|
|
ActiveSupport::Dependencies.clear
|
2012-11-16 19:05:53 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def with_autoloading_fixtures(&block)
|
2016-08-06 12:03:25 -04:00
|
|
|
with_loading "autoloading_fixtures", &block
|
2012-11-16 19:05:53 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def remove_constants(*constants)
|
|
|
|
constants.each do |constant|
|
|
|
|
Object.send(:remove_const, constant) if Object.const_defined?(constant)
|
|
|
|
end
|
|
|
|
end
|
2016-08-06 13:55:02 -04:00
|
|
|
end
|