diff --git a/lib/bundler/definition.rb b/lib/bundler/definition.rb index 75eb5ffa1b..e7e6c49e6c 100644 --- a/lib/bundler/definition.rb +++ b/lib/bundler/definition.rb @@ -317,7 +317,7 @@ module Bundler def lock(file_or_preserve_unknown_sections = false, preserve_unknown_sections_or_unused = false) if [true, false, nil].include?(file_or_preserve_unknown_sections) - target_lockfile = lockfile || Bundler.default_lockfile + target_lockfile = lockfile preserve_unknown_sections = file_or_preserve_unknown_sections else target_lockfile = file_or_preserve_unknown_sections diff --git a/spec/bundler/runtime/inline_spec.rb b/spec/bundler/runtime/inline_spec.rb index 2deda75509..5ff555ab0d 100644 --- a/spec/bundler/runtime/inline_spec.rb +++ b/spec/bundler/runtime/inline_spec.rb @@ -656,6 +656,20 @@ RSpec.describe "bundler/inline#gemfile" do expect(out).to include("after: [\"Test_Variable\"]") end + it "does not create a lockfile" do + script <<-RUBY + require 'bundler/inline' + + gemfile do + source "https://gem.repo1" + end + + puts Dir.glob("Gemfile.lock") + RUBY + + expect(out).to be_empty + end + it "does not load specified version of psych and stringio", :ruby_repo do build_repo4 do build_gem "psych", "999" @@ -678,4 +692,25 @@ RSpec.describe "bundler/inline#gemfile" do expect(out).to include("The psych gem was resolved to 999") expect(out).to include("The stringio gem was resolved to 999") end + + it "leaves a lockfile in the same directory as the inline script alone" do + install_gemfile <<~G + source "https://gem.repo1" + gem "foo" + G + + original_lockfile = lockfile + + script <<-RUBY, env: { "BUNDLER_SPEC_GEM_REPO" => gem_repo1.to_s } + require "bundler/inline" + + gemfile(true) do + source "https://gem.repo1" + + gem "myrack" + end + RUBY + + expect(lockfile).to eq(original_lockfile) + end end