From e36db3dd253423d5722fc3723b2b57718a7835a5 Mon Sep 17 00:00:00 2001 From: Cody Cutrer Date: Thu, 25 Apr 2024 13:38:54 -0600 Subject: [PATCH] fix error when lockfiles are not defined, but ruby version is (#39) --- lib/bundler/multilock/ext/dsl.rb | 3 ++- spec/bundler/multilock_spec.rb | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/bundler/multilock/ext/dsl.rb b/lib/bundler/multilock/ext/dsl.rb index c83a231..b29ce60 100644 --- a/lib/bundler/multilock/ext/dsl.rb +++ b/lib/bundler/multilock/ext/dsl.rb @@ -20,7 +20,8 @@ def evaluate(gemfile, lockfile, unlock) builder = new builder.eval_gemfile(gemfile, &Multilock.prepare_block) if Multilock.prepare_block builder.eval_gemfile(gemfile) - if (ruby_version_requirement = builder.instance_variable_get(:@ruby_version)) + if (ruby_version_requirement = builder.instance_variable_get(:@ruby_version)) && + Multilock.lockfile_definitions[lockfile] Multilock.lockfile_definitions[lockfile][:ruby_version_requirement] = ruby_version_requirement elsif (parent_lockfile = Multilock.lockfile_definitions.dig(lockfile, :parent)) && (parent_lockfile_definition = Multilock.lockfile_definitions[parent_lockfile]) && diff --git a/spec/bundler/multilock_spec.rb b/spec/bundler/multilock_spec.rb index 774c4d5..1d104b1 100644 --- a/spec/bundler/multilock_spec.rb +++ b/spec/bundler/multilock_spec.rb @@ -934,6 +934,16 @@ end end + it "doesn't error when no lockfiles are defined but ruby version is set" do + with_gemfile(<<~RUBY) do + gem "nokogiri" + + ruby ">= 2.1" + RUBY + invoke_bundler("install") + end + end + private def create_local_gem(name, content = "", subdirectory: true)