BumpVersionParser: expand tests

This expands test coverage for `BumpVersionParser`, bringing line
coverage to 100% and branch coverage to 95.45%. This is the best we
can do for branch coverage, as Sorbet will catch an invalid argument
type before the method is executed, so we can't exercise the method
in a test to get 100% coverage.
This commit is contained in:
Sam Ford 2024-11-24 10:10:43 -05:00
parent a89457fcb9
commit 918206e1fd
No known key found for this signature in database
GPG Key ID: 7AF5CBEE1DD6F76D

View File

@ -11,26 +11,12 @@ RSpec.describe Homebrew::BumpVersionParser do
it "raises a usage error" do
expect do
described_class.new
end.to raise_error(UsageError, "Invalid usage: `--version` must not be empty.")
end.to raise_error(UsageError,
"Invalid usage: `--version` must not be empty.")
end
end
context "when initializing with valid versions" do
let(:new_version) { described_class.new(general: general_version, arm: arm_version, intel: intel_version) }
it "correctly parses general version" do
expect(new_version.general).to eq(Cask::DSL::Version.new(general_version.to_s))
end
it "correctly parses arm version" do
expect(new_version.arm).to eq(Cask::DSL::Version.new(arm_version.to_s))
end
it "correctly parses intel version" do
expect(new_version.intel).to eq(Cask::DSL::Version.new(intel_version.to_s))
end
context "when only the intel version is provided" do
context "when initializing with only an intel version" do
it "raises a UsageError" do
expect do
described_class.new(intel: intel_version)
@ -39,7 +25,7 @@ RSpec.describe Homebrew::BumpVersionParser do
end
end
context "when only the arm version is provided" do
context "when initializing with only an arm version" do
it "raises a UsageError" do
expect do
described_class.new(arm: arm_version)
@ -48,6 +34,40 @@ RSpec.describe Homebrew::BumpVersionParser do
end
end
context "when initializing with arm and intel versions" do
let(:new_version_arm_intel) { described_class.new(arm: arm_version, intel: intel_version) }
it "correctly parses arm and intel versions" do
expect(new_version_arm_intel.arm).to eq(Cask::DSL::Version.new(arm_version.to_s))
expect(new_version_arm_intel.intel).to eq(Cask::DSL::Version.new(intel_version.to_s))
end
end
context "when initializing with all versions" do
let(:new_version) { described_class.new(general: general_version, arm: arm_version, intel: intel_version) }
let(:new_version_version) do
described_class.new(
general: Version.new(general_version),
arm: Version.new(arm_version),
intel: Version.new(intel_version),
)
end
it "correctly parses general version" do
expect(new_version.general).to eq(Cask::DSL::Version.new(general_version.to_s))
expect(new_version_version.general).to eq(Cask::DSL::Version.new(general_version.to_s))
end
it "correctly parses arm version" do
expect(new_version.arm).to eq(Cask::DSL::Version.new(arm_version.to_s))
expect(new_version_version.arm).to eq(Cask::DSL::Version.new(arm_version.to_s))
end
it "correctly parses intel version" do
expect(new_version.intel).to eq(Cask::DSL::Version.new(intel_version.to_s))
expect(new_version_version.intel).to eq(Cask::DSL::Version.new(intel_version.to_s))
end
context "when the version is latest" do
it "returns a version object for latest" do
new_version = described_class.new(general: "latest")