Skip to content

Commit

Permalink
Merge pull request #3344 from dependabot/bundler-req-replacer-not-equal
Browse files Browse the repository at this point in the history
Bundler req replacer not equal
  • Loading branch information
thepwagner authored Mar 25, 2021
2 parents 11e5cbe + b785401 commit 0cfe6c8
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ def space_after_specifier?(requirement_nodes)
req_string.include?(" ")
end

EQUALITY_OPERATOR = /(?<![<>!])=/.freeze

def use_equality_operator?(requirement_nodes)
return true if requirement_nodes.none?

Expand All @@ -178,7 +180,7 @@ def use_equality_operator?(requirement_nodes)
requirement_nodes.first.children.first.loc.expression.source
end

req_string.match?(/(?<![<>])=/)
req_string.match?(EQUALITY_OPERATOR)
end

def new_requirement_string(quote_characters:,
Expand All @@ -203,7 +205,7 @@ def serialized_req(req, use_equality_operator)
# Gem::Requirement serializes exact matches as a string starting
# with `=`. We may need to remove that equality operator if it
# wasn't used originally.
tmp_req = tmp_req.gsub(/(?<![<>])=/, "") unless use_equality_operator
tmp_req = tmp_req.gsub(EQUALITY_OPERATOR, "") unless use_equality_operator

tmp_req.strip
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ def widened_requirements(req)
req
end
when "<", "<=" then [update_greatest_version(req, latest_version)]
when "~>" then convert_twidle_to_range(req, latest_version)
when "~>" then convert_twiddle_to_range(req, latest_version)
when "!=" then []
when ">", ">=" then raise UnfixableRequirement
else raise "Unexpected operation for requirement: #{op}"
Expand All @@ -214,7 +214,7 @@ def bumped_requirements(req)
end
end

def convert_twidle_to_range(requirement, version_to_be_permitted)
def convert_twiddle_to_range(requirement, version_to_be_permitted)
version = requirement.requirements.first.last
version = version.release if version.prerelease?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,16 @@
end
end

context "with inequality matchers" do
let(:previous_requirement) { ">= 2.0.0, != 2.0.3, != 2.0.4" }
let(:updated_requirement) { "~> 2.0.1, != 2.0.3, != 2.0.4" }
let(:content) do
%(s.add_runtime_dependency("business", "~> 2.0.1", "!= 2.0.3", "!= 2.0.4"))
end

it { is_expected.to eq(content) }
end

context "when declared with `add_development_dependency`" do
let(:dependency_name) { "rspec" }
it { is_expected.to include(%(ent_dependency "rspec", "~> 1.5.0"\n)) }
Expand Down

0 comments on commit 0cfe6c8

Please sign in to comment.