Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class LockfileUpdater
require_relative "gemspec_updater"
require_relative "gemspec_sanitizer"
require_relative "gemspec_dependency_name_finder"
require_relative "ruby_requirement_setter"

LOCKFILE_ENDING =
/(?<ending>\s*(?:RUBY VERSION|BUNDLED WITH).*)/m.freeze
Expand Down Expand Up @@ -82,7 +83,7 @@ def build_updated_lockfile
end

def write_temporary_dependency_files
File.write(gemfile.name, updated_gemfile_content(gemfile))
File.write(gemfile.name, prepared_gemfile_content(gemfile))
File.write(lockfile.name, sanitized_lockfile_body)

top_level_gemspecs.each do |gemspec|
Expand Down Expand Up @@ -222,6 +223,16 @@ def replacement_version_for_gemspec(gemspec_content)
end
# rubocop:enable Metrics/PerceivedComplexity

def prepared_gemfile_content(file)
content = updated_gemfile_content(file)

top_level_gemspecs.each do |gs|
content = RubyRequirementSetter.new(gemspec: gs).rewrite(content)
end

content
end

def updated_gemfile_content(file)
GemfileUpdater.new(
dependencies: dependencies,
Expand Down
21 changes: 21 additions & 0 deletions bundler/spec/dependabot/bundler/file_updater_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,27 @@
end
end

context "with an imported gemspec that specifies a minimum Ruby version not satisfied by the running Ruby" do
let(:dependency_files) { bundler_project_dependency_files("unsatisfied_required_ruby_version") }

before do
require "dependabot/bundler/file_updater/ruby_requirement_setter"

stub_const(
"#{described_class}::RubyRequirementSetter::RUBY_VERSIONS",
described_class::RubyRequirementSetter::RUBY_VERSIONS + ["99.0.0"]
)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could've used >= 3.1 in the fixture gemspec, and that would've worked, but once Dependabot upgrades to Ruby 3.1, the test would stop covering this fix. So this is my attempt to make the test independent from the Ruby version being run.

end

it "locks the updated gem to the latest version" do
expect(file.content).to include("business (1.5.0)")
end

it "doesn't add in a RUBY VERSION" do
expect(file.content).not_to include("RUBY VERSION")
end
end

context "when the Gemfile specifies a Ruby version" do
let(:dependency_files) { bundler_project_dependency_files("explicit_ruby_in_lockfile") }

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source "https://rubygems.org"

gemspec

gem "business", "~> 1.4.0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
GEM
remote: https://rubygems.org/
specs:
business (1.4.0)

PLATFORMS
ruby

DEPENDENCIES
business (~> 1.4.0)

BUNDLED WITH
1.17.3
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true
Gem::Specification.new do |spec|
spec.name = "example"
spec.version = "0.9.3"
spec.summary = "Automated dependency management"
spec.description = "Core logic for updating a GitHub repos dependencies"

spec.author = "Dependabot"
spec.email = "support@dependabot.com"
spec.homepage = "https://github.com/hmarr/example"
spec.license = "MIT"

spec.require_path = "lib"
spec.files = Dir["CHANGELOG.md", "LICENSE.txt", "README.md",
"lib/**/*", "helpers/**/*"]

spec.required_ruby_version = ">= 99.0.0"
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
source "https://rubygems.org"

gemspec

gem "business", "~> 1.4.0"
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
GEM
remote: https://rubygems.org/
specs:
business (1.4.0)

PLATFORMS
ruby

DEPENDENCIES
business (~> 1.4.0)

BUNDLED WITH
2.2.10
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true
Gem::Specification.new do |spec|
spec.name = "example"
spec.version = "0.9.3"
spec.summary = "Automated dependency management"
spec.description = "Core logic for updating a GitHub repos dependencies"

spec.author = "Dependabot"
spec.email = "support@dependabot.com"
spec.homepage = "https://github.com/hmarr/example"
spec.license = "MIT"

spec.require_path = "lib"
spec.files = Dir["CHANGELOG.md", "LICENSE.txt", "README.md",
"lib/**/*", "helpers/**/*"]

spec.required_ruby_version = ">= 99.0.0"
end