summaryrefslogtreecommitdiff
path: root/spec/bundler/bundler/ruby_version_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/bundler/bundler/ruby_version_spec.rb')
-rw-r--r--spec/bundler/bundler/ruby_version_spec.rb20
1 files changed, 14 insertions, 6 deletions
diff --git a/spec/bundler/bundler/ruby_version_spec.rb b/spec/bundler/bundler/ruby_version_spec.rb
index 868d81088d..8c6c071d7f 100644
--- a/spec/bundler/bundler/ruby_version_spec.rb
+++ b/spec/bundler/bundler/ruby_version_spec.rb
@@ -400,12 +400,20 @@ RSpec.describe "Bundler::RubyVersion and its subclasses" do
let(:bundler_system_ruby_version) { subject }
around do |example|
- begin
- old_ruby_version = Bundler::RubyVersion.instance_variable_get("@ruby_version")
- Bundler::RubyVersion.instance_variable_set("@ruby_version", nil)
- example.run
- ensure
- Bundler::RubyVersion.instance_variable_set("@ruby_version", old_ruby_version)
+ if Bundler::RubyVersion.instance_variable_defined?("@ruby_version")
+ begin
+ old_ruby_version = Bundler::RubyVersion.instance_variable_get("@ruby_version")
+ Bundler::RubyVersion.remove_instance_variable("@ruby_version")
+ example.run
+ ensure
+ Bundler::RubyVersion.instance_variable_set("@ruby_version", old_ruby_version)
+ end
+ else
+ begin
+ example.run
+ ensure
+ Bundler::RubyVersion.remove_instance_variable("@ruby_version")
+ end
end
end