Skip to content

Commit 2376421

Browse files
committed
Do not allow code to be reloaded while tests are running
1 parent f7393cb commit 2376421

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

lib/rails_console_commands/test_environment.rb

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class << self
88
def fork
99
Environment.fork do
1010
setup_for_test
11-
yield
11+
disable_reloading { yield }
1212
end
1313

1414
reset_active_record
@@ -21,9 +21,19 @@ def setup_for_test
2121
add_test_dir_to_load_path
2222
end
2323

24+
# Code should not be reloaded while tests are running, as this tends
25+
# to cause Active Record connection errors, and causes unreliable test runs.
26+
# `reload_classes` will ensure that the code is reloaded before tests commence.
27+
def disable_reloading
28+
was = Rails.application.reloader.check
29+
Rails.application.reloader.check = lambda { false }
30+
31+
yield
32+
ensure
33+
Rails.application.reloader.check = was
34+
end
35+
2436
def reload_classes
25-
# Overwrite the default config.cache_classes = true,
26-
# so we can change classes in the test session.
2737
if ActiveSupport::Dependencies.respond_to?(:mechanism=) # Rails < 7
2838
ActiveSupport::Dependencies.mechanism = :load
2939
end

0 commit comments

Comments
 (0)