Skip to content

Commit

Permalink
patch DotnetSdk::Requirement
Browse files Browse the repository at this point in the history
  • Loading branch information
JamieMagee authored and randhircs committed Dec 6, 2024
1 parent ed1f9e9 commit e7a0dc2
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
11 changes: 11 additions & 0 deletions dotnet_sdk/lib/dependabot/dotnet_sdk/requirement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,17 @@ class Requirement < Dependabot::Requirement
def self.requirements_array(requirement_string)
[new(requirement_string)]
end

# Patches Gem::Requirement to make it accept requirement strings like
# "~> 4.2.5, >= 4.2.5.1" without first needing to split them.
sig { params(requirements: T.nilable(String)).void }
def initialize(*requirements)
requirements = requirements.flatten.flat_map do |req_string|
req_string&.split(",")&.map(&:strip)
end.compact

super(requirements)
end
end
end
end
Expand Down
21 changes: 21 additions & 0 deletions dotnet_sdk/spec/dependabot/dotnet_sdk/requirement_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# typed: false
# frozen_string_literal: true

require "spec_helper"
require "dependabot/dotnet_sdk/requirement"

RSpec.describe Dependabot::DotnetSdk::Requirement do
subject(:requirement) { described_class.new(requirement_string) }

let(:requirement_string) { ">=9.0.100" }

describe ".new" do
it { is_expected.to be_a(described_class) }

context "with a comma-separated string" do
let(:requirement_string) { ">= 9.1.a, < 10" }

it { is_expected.to eq(Gem::Requirement.new(">= 9.1.a", "< 10")) }
end
end
end

0 comments on commit e7a0dc2

Please sign in to comment.