Skip to content

Commit

Permalink
test/deprecate_disable_spec: increase test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
cho-m committed Dec 20, 2024
1 parent 21f3536 commit eebcd60
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions Library/Homebrew/test/deprecate_disable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,24 @@
require "deprecate_disable"

RSpec.describe DeprecateDisable do
let(:deprecate_date) { Date.parse("2020-01-01") }
let(:disable_date) { deprecate_date >> DeprecateDisable::REMOVE_DISABLED_TIME_WINDOW }
let(:deprecated_formula) do
instance_double(Formula, deprecated?: true, disabled?: false, deprecation_reason: :does_not_build,
deprecation_replacement: nil, deprecation_date: nil, disable_date: nil)
end
let(:deprecated_formula_with_date) do
instance_double(Formula, deprecated?: true, disabled?: false, deprecation_reason: :does_not_build,
deprecation_replacement: nil, deprecation_date: deprecate_date, disable_date: nil)
end
let(:disabled_formula) do
instance_double(Formula, deprecated?: false, disabled?: true, disable_reason: "is broken",
disable_replacement: nil, deprecation_date: nil, disable_date: nil)
end
let(:disabled_formula_with_date) do
instance_double(Formula, deprecated?: false, disabled?: true, disable_reason: :does_not_build,
disable_replacement: nil, deprecation_date: nil, disable_date: disable_date)
end
let(:deprecated_cask) do
instance_double(Cask::Cask, deprecated?: true, disabled?: false, deprecation_reason: :discontinued,
deprecation_replacement: nil, deprecation_date: nil, disable_date: nil)
Expand Down Expand Up @@ -39,7 +49,9 @@
before do
formulae = [
deprecated_formula,
deprecated_formula_with_date,
disabled_formula,
disabled_formula_with_date,
deprecated_formula_with_replacement,
disabled_formula_with_replacement,
]
Expand Down Expand Up @@ -86,11 +98,22 @@
.to eq "deprecated because it does not build!"
end

it "returns a deprecation message with disable date" do
allow(Date).to receive(:today).and_return(deprecate_date + 1)
expect(described_class.message(deprecated_formula_with_date))
.to eq "deprecated because it does not build! It will be disabled on #{disable_date}."
end

it "returns a disable message with a custom reason" do
expect(described_class.message(disabled_formula))
.to eq "disabled because it is broken!"
end

it "returns a disable message with disable date" do
expect(described_class.message(disabled_formula_with_date))
.to eq "disabled because it does not build! It was disabled on #{disable_date}."
end

it "returns a deprecation message with a preset cask reason" do
expect(described_class.message(deprecated_cask))
.to eq "deprecated because it is discontinued upstream!"
Expand Down

0 comments on commit eebcd60

Please sign in to comment.