summaryrefslogtreecommitdiff
path: root/spec/ruby/fixtures/code_loading.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/fixtures/code_loading.rb')
-rw-r--r--spec/ruby/fixtures/code_loading.rb15
1 files changed, 15 insertions, 0 deletions
diff --git a/spec/ruby/fixtures/code_loading.rb b/spec/ruby/fixtures/code_loading.rb
index d6cf0edb47..decd56a358 100644
--- a/spec/ruby/fixtures/code_loading.rb
+++ b/spec/ruby/fixtures/code_loading.rb
@@ -12,7 +12,22 @@ module CodeLoadingSpecs
end
end
+ def self.preload_rubygems
+ # Require RubyGems eagerly, to ensure #require is already the RubyGems
+ # version and RubyGems is only loaded once, before starting #require/#autoload specs
+ # which snapshot $LOADED_FEATURES and could cause RubyGems to load twice.
+ # #require specs also snapshot #require, and could end up redefining #require as the original core Kernel#require.
+ @rubygems ||= begin
+ require "rubygems"
+ true
+ rescue LoadError
+ true
+ end
+ end
+
def self.spec_setup
+ preload_rubygems
+
@saved_loaded_features = $LOADED_FEATURES.clone
@saved_load_path = $LOAD_PATH.clone
ScratchPad.record []