Remove DependenciesTestHelpers

This commit is contained in:
Xavier Noria 2021-04-03 19:09:47 +02:00
parent 5f70349b05
commit af27a25f19
4 changed files with 32 additions and 1032 deletions

@ -1,6 +1,6 @@
# frozen_string_literal: true
require_relative "dependencies_test_helpers"
require_relative "constantize_test_helpers"
module Ace
module Base
@ -27,7 +27,7 @@ class Dice
end
module ConstantizeTestCases
include DependenciesTestHelpers
include ConstantizeTestHelpers
def run_constantize_tests_on
assert_equal Ace::Base::Case, yield("Ace::Base::Case")
@ -75,11 +75,6 @@ def run_constantize_tests_on
yield("RaisesNoMethodError")
end
end
with_autoloading_fixtures do
yield("Prepend::SubClassConflict")
assert_equal "constant", defined?(Prepend::SubClassConflict)
end
end
def run_safe_constantize_tests_on
@ -112,10 +107,6 @@ def run_safe_constantize_tests_on
assert_nil yield("A::Object::B")
assert_nil yield("A::Object::Object::Object::B")
with_autoloading_fixtures do
assert_nil yield("Em")
end
assert_raises(LoadError) do
with_autoloading_fixtures do
yield("RaisesLoadError")

@ -0,0 +1,30 @@
# frozen_string_literal: true
module ConstantizeTestHelpers
ROOT_DIR = File.realpath("#{__dir__}/autoloading_fixtures")
AUTOLOADS = {
"RaisesLoadError" => "#{ROOT_DIR}/raises_load_error",
"RaisesNameError" => "#{ROOT_DIR}/raises_name_error",
"RaisesNoMethodError" => "#{ROOT_DIR}/raises_no_method_error"
}
def with_autoloading_fixtures
define_autoloads
yield
ensure
remove_autoloads
end
def define_autoloads
AUTOLOADS.each do |constant, realpath|
Object.autoload(constant, realpath)
end
end
def remove_autoloads
AUTOLOADS.each do |constant, realpath|
Object.send(:remove_const, constant) if Object.const_defined?(constant)
$LOADED_FEATURES.delete(realpath)
end
end
end

File diff suppressed because it is too large Load Diff

@ -1,30 +0,0 @@
# frozen_string_literal: true
module DependenciesTestHelpers
def with_loading(*from)
old_mechanism, ActiveSupport::Dependencies.mechanism = ActiveSupport::Dependencies.mechanism, :load
this_dir = __dir__
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 = []
ActiveSupport::Dependencies.clear
end
def with_autoloading_fixtures(&block)
with_loading "autoloading_fixtures", &block
end
def remove_constants(*constants)
constants.each do |constant|
Object.send(:remove_const, constant) if Object.const_defined?(constant)
end
end
end