Skip to content

Commit

Permalink
Additional tests and some tests from the old version
Browse files Browse the repository at this point in the history
  • Loading branch information
amazimbe committed Sep 18, 2024
1 parent 0d76657 commit 85b1508
Showing 1 changed file with 60 additions and 1 deletion.
61 changes: 60 additions & 1 deletion maven/spec/dependabot/maven/version_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@
it { is_expected.to be(false) }
end

context "with an empty version" do
let(:version_string) { "" }

it { is_expected.to be(false) }
end

context "with a malformed version string" do
let(:version_string) { "-" }

Expand Down Expand Up @@ -82,7 +88,7 @@
it { is_expected.to eq("1.0.0_pre1") }
end

context "with a blank version" do
context "with a nil version" do
let(:version_string) { nil }
let(:err_msg) { "Malformed version string - string is nil" }

Expand All @@ -91,6 +97,15 @@
end
end

context "with an empty version" do
let(:version_string) { "" }
let(:err_msg) { "Malformed version string - string is empty" }

it "raises an exception" do
expect { version }.to raise_error(Dependabot::BadRequirementError, err_msg)
end
end

context "with a malformed version string" do
let(:version_string) { "-" }
let(:err_msg) { "Malformed version string - #{version_string}" }
Expand Down Expand Up @@ -158,6 +173,26 @@
describe "#<=>" do
subject { version.send(:<=>, other_version) }

context "when comparing to a Gem::Version" do
context "when lower" do
let(:other_version) { Gem::Version.new("0.9.0") }

it { is_expected.to eq(1) }
end

context "when equal" do
let(:other_version) { Gem::Version.new("1.0.0") }

it { is_expected.to eq(0) }
end

context "when greater" do
let(:other_version) { Gem::Version.new("1.1.0") }

it { is_expected.to eq(-1) }
end
end

context "with semantic versions" do
let(:versions) do
[
Expand Down Expand Up @@ -491,4 +526,28 @@
end
end
end

describe "compatibility with Gem::Requirement" do
subject { requirement.satisfied_by?(version) }

let(:requirement) { Gem::Requirement.new(">= 1.0.0") }

context "with a valid version" do
let(:version_string) { "1.0.0" }

it { is_expected.to be(true) }
end

context "with an invalid version" do
let(:version_string) { "0.9.0" }

it { is_expected.to be(false) }
end

context "with a valid dash-separated version" do
let(:version_string) { "1.1.0-pre" }

it { is_expected.to be(true) }
end
end
end

0 comments on commit 85b1508

Please sign in to comment.