brew/Library/Homebrew/test/rubocops/deprecate_spec.rb

104 lines
2.8 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
require "rubocops/deprecate"
2020-08-28 20:47:52 -04:00
describe RuboCop::Cop::FormulaAudit::DeprecateDate do
subject(:cop) { described_class.new }
2020-08-28 20:47:52 -04:00
context "When auditing formula for deprecate! date:" do
it "deprecation date is not ISO 8601 compliant" do
expect_offense(<<~RUBY)
class Foo < Formula
url 'https://brew.sh/foo-1.0.tgz'
2020-08-28 20:47:52 -04:00
deprecate! date: "June 25, 2020"
^^^^^^^^^^^^^^^ Use `2020-06-25` to comply with ISO 8601
end
RUBY
end
it "deprecation date is not ISO 8601 compliant with reason" do
expect_offense(<<~RUBY)
class Foo < Formula
url 'https://brew.sh/foo-1.0.tgz'
deprecate! because: "is broken", date: "June 25, 2020"
^^^^^^^^^^^^^^^ Use `2020-06-25` to comply with ISO 8601
end
RUBY
end
it "deprecation date is ISO 8601 compliant" do
expect_no_offenses(<<~RUBY)
class Foo < Formula
url 'https://brew.sh/foo-1.0.tgz'
2020-08-28 20:47:52 -04:00
deprecate! date: "2020-06-25"
end
RUBY
end
it "deprecation date is ISO 8601 compliant with reason" do
expect_no_offenses(<<~RUBY)
class Foo < Formula
url 'https://brew.sh/foo-1.0.tgz'
deprecate! because: "is broken", date: "2020-06-25"
end
RUBY
end
it "no deprecation date" do
expect_no_offenses(<<~RUBY)
class Foo < Formula
url 'https://brew.sh/foo-1.0.tgz'
deprecate!
end
RUBY
end
2020-08-28 20:47:52 -04:00
it "no deprecation date with reason" do
expect_no_offenses(<<~RUBY)
class Foo < Formula
url 'https://brew.sh/foo-1.0.tgz'
deprecate! because: "is broken"
end
RUBY
end
it "auto corrects to ISO 8601 format" do
source = <<~RUBY
class Foo < Formula
url 'https://brew.sh/foo-1.0.tgz'
2020-08-28 20:47:52 -04:00
deprecate! date: "June 25, 2020"
end
RUBY
corrected_source = <<~RUBY
class Foo < Formula
url 'https://brew.sh/foo-1.0.tgz'
deprecate! date: "2020-06-25"
end
RUBY
new_source = autocorrect_source(source)
expect(new_source).to eq(corrected_source)
end
it "auto corrects to ISO 8601 format with reason" do
source = <<~RUBY
class Foo < Formula
url 'https://brew.sh/foo-1.0.tgz'
deprecate! because: "is broken", date: "June 25, 2020"
end
RUBY
corrected_source = <<~RUBY
class Foo < Formula
url 'https://brew.sh/foo-1.0.tgz'
2020-08-28 20:47:52 -04:00
deprecate! because: "is broken", date: "2020-06-25"
end
RUBY
new_source = autocorrect_source(source)
expect(new_source).to eq(corrected_source)
end
end
end