module ActiveSupport::Testing::ConstantStubbing

def stub_const(mod, constant, new_value)

divergent stubbing will trample on each other.
(like separate test suites running in parallel) that all depend on the same constant, it's possible
Note: Stubbing a const will stub it across all threads. So if you have concurrent threads

warnings from being thrown, and ensures that the old value is returned after the test has completed.
Using this method rather than forcing World::List::Import::LARGE_IMPORT_THRESHOLD = 5000 prevents

assert_equal 5000, World::List::Import::LARGE_IMPORT_THRESHOLD

end
assert_equal 1, World::List::Import::LARGE_IMPORT_THRESHOLD
stub_const(World::List::Import, :LARGE_IMPORT_THRESHOLD, 1) do
# World::List::Import::LARGE_IMPORT_THRESHOLD = 5000

Changes the value of a constant for the duration of a block. Example:
def stub_const(mod, constant, new_value)
  old_value = mod.const_get(constant, false)
  mod.send(:remove_const, constant)
  mod.const_set(constant, new_value)
  yield
ensure
  mod.send(:remove_const, constant)
  mod.const_set(constant, old_value)
end