-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Add ignore_ruby_upper_bounds and ignore_rubygems_upper_bounds settings
#9454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
0bc96a3
a06adbf
b75e643
7f19b83
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| RSpec.describe Bundler::MatchMetadata do | ||
| let(:klass) do | ||
| Class.new do | ||
| include Bundler::MatchMetadata | ||
|
|
||
| attr_accessor :required_ruby_version, :required_rubygems_version, :dependencies | ||
|
|
||
| def initialize(ruby_version, rubygems_version) | ||
| @required_ruby_version = ruby_version | ||
| @required_rubygems_version = rubygems_version | ||
| @dependencies = [] | ||
| end | ||
|
|
||
| alias_method :runtime_dependencies, :dependencies | ||
| end | ||
| end | ||
|
|
||
| describe "#matches_current_ruby?" do | ||
| context "when the ruby version has an upper bound that excludes the current ruby" do | ||
| let(:spec) { klass.new(Gem::Requirement.new(">= 3.0", "< 3.1"), Gem::Requirement.default) } | ||
|
|
||
| it "returns false by default" do | ||
| expect(spec.matches_current_ruby?).to be false | ||
| end | ||
|
|
||
| it "returns true when ignore_ruby_upper_bounds is set" do | ||
| bundle "config set ignore_ruby_upper_bounds true" | ||
| expect(spec.matches_current_ruby?).to be true | ||
| end | ||
|
Comment on lines
+28
to
+31
|
||
| end | ||
|
|
||
| context "when the ruby version has only a lower bound" do | ||
| let(:spec) { klass.new(Gem::Requirement.new(">= 2.0"), Gem::Requirement.default) } | ||
|
|
||
| it "returns true regardless of setting" do | ||
| expect(spec.matches_current_ruby?).to be true | ||
|
|
||
| bundle "config set ignore_ruby_upper_bounds true" | ||
| expect(spec.matches_current_ruby?).to be true | ||
| end | ||
| end | ||
|
|
||
| context "when the ruby version has only an upper bound" do | ||
| let(:spec) { klass.new(Gem::Requirement.new("< 3.1"), Gem::Requirement.default) } | ||
|
|
||
| it "returns false by default" do | ||
| expect(spec.matches_current_ruby?).to be false | ||
| end | ||
|
|
||
| it "returns true when ignore_ruby_upper_bounds is set (upper bound removed, defaults to >= 0)" do | ||
| bundle "config set ignore_ruby_upper_bounds true" | ||
| expect(spec.matches_current_ruby?).to be true | ||
| end | ||
| end | ||
| end | ||
|
|
||
| describe "#matches_current_rubygems?" do | ||
| context "when the rubygems version has an upper bound that excludes the current rubygems" do | ||
| let(:spec) { klass.new(Gem::Requirement.default, Gem::Requirement.new(">= 3.0", "< 3.1")) } | ||
|
|
||
| it "returns false by default" do | ||
| expect(spec.matches_current_rubygems?).to be false | ||
| end | ||
|
|
||
| it "returns true when ignore_rubygems_upper_bounds is set" do | ||
| bundle "config set ignore_rubygems_upper_bounds true" | ||
| expect(spec.matches_current_rubygems?).to be true | ||
| end | ||
| end | ||
|
|
||
| context "when the rubygems version has only a lower bound" do | ||
| let(:spec) { klass.new(Gem::Requirement.default, Gem::Requirement.new(">= 2.0")) } | ||
|
|
||
| it "returns true regardless of setting" do | ||
| expect(spec.matches_current_rubygems?).to be true | ||
|
|
||
| bundle "config set ignore_rubygems_upper_bounds true" | ||
| expect(spec.matches_current_rubygems?).to be true | ||
| end | ||
| end | ||
|
Comment on lines
+59
to
+82
|
||
| end | ||
|
|
||
| describe "#metadata_dependency" do | ||
| context "when ignore_ruby_upper_bounds is set" do | ||
| before { bundle "config set ignore_ruby_upper_bounds true" } | ||
|
|
||
| it "removes upper bounds from Ruby dependency" do | ||
| spec = klass.new(Gem::Requirement.new(">= 3.0", "< 3.1"), Gem::Requirement.default) | ||
| dep = spec.send(:metadata_dependency, "Ruby", spec.required_ruby_version) | ||
| expect(dep.requirement).to eq(Gem::Requirement.new(">= 3.0")) | ||
| end | ||
|
|
||
| it "returns nil when only upper bounds exist" do | ||
| spec = klass.new(Gem::Requirement.new("< 3.1"), Gem::Requirement.default) | ||
| dep = spec.send(:metadata_dependency, "Ruby", spec.required_ruby_version) | ||
| expect(dep).to be_nil | ||
| end | ||
|
|
||
| it "does not affect RubyGems dependency" do | ||
| spec = klass.new(Gem::Requirement.default, Gem::Requirement.new(">= 3.0", "< 4.0")) | ||
| dep = spec.send(:metadata_dependency, "RubyGems", spec.required_rubygems_version) | ||
| expect(dep.requirement).to eq(Gem::Requirement.new(">= 3.0", "< 4.0")) | ||
| end | ||
| end | ||
|
|
||
| context "when ignore_rubygems_upper_bounds is set" do | ||
| before { bundle "config set ignore_rubygems_upper_bounds true" } | ||
|
|
||
| it "removes upper bounds from RubyGems dependency" do | ||
| spec = klass.new(Gem::Requirement.default, Gem::Requirement.new(">= 3.0", "< 4.0")) | ||
| dep = spec.send(:metadata_dependency, "RubyGems", spec.required_rubygems_version) | ||
| expect(dep.requirement).to eq(Gem::Requirement.new(">= 3.0")) | ||
| end | ||
|
|
||
| it "does not affect Ruby dependency" do | ||
| spec = klass.new(Gem::Requirement.new(">= 3.0", "< 3.1"), Gem::Requirement.default) | ||
| dep = spec.send(:metadata_dependency, "Ruby", spec.required_ruby_version) | ||
| expect(dep.requirement).to eq(Gem::Requirement.new(">= 3.0", "< 3.1")) | ||
| end | ||
| end | ||
| end | ||
| end | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove_upper_boundsalways allocates (reject array + new requirement) even when the requirement has no</<=constraints. Since this method can run on hot paths (metadata checks + expanded deps), consider fast-pathing by returning the originalrequirementwhen no upper-bound operators are present, and avoid allocating the['<','<=']array on every call (e.g., a frozen constant or simpleop == '<' || op == '<=').