Skip to content
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

Bundler req replacer not equal #3344

Merged
merged 3 commits into from
Mar 25, 2021
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 @@ -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