@@ -2053,4 +2053,105 @@ def install
20532053 expect ( f . class . preserve_rpath? ) . to be ( false )
20542054 end
20552055 end
2056+
2057+ describe "#deprecate! and #disable!" do
2058+ let ( :deprecation_date ) { "2020-01-01" }
2059+ let ( :disable_date ) { "2021-01-01" }
2060+
2061+ context "with both dates provided in correct order" do
2062+ let ( :f ) do
2063+ deprecation_date_ = deprecation_date
2064+ disable_date_ = disable_date
2065+ formula "foo" do
2066+ url "foo-1.0"
2067+ deprecate! date : deprecation_date_ . to_s , because : :unmaintained
2068+ disable! date : disable_date_ . to_s , because : :unsupported
2069+ end
2070+ end
2071+
2072+ it "is not deprecated before deprecation date" do
2073+ allow ( Date ) . to receive ( :today ) . and_return ( Date . parse ( deprecation_date ) - 1 )
2074+ expect ( f . deprecated? ) . to be ( false )
2075+ expect ( f . deprecation_reason ) . to be_nil
2076+ expect ( f . disabled? ) . to be ( false )
2077+ expect ( f . disable_reason ) . to be_nil
2078+ end
2079+
2080+ it "is deprecated on deprecation date" do
2081+ allow ( Date ) . to receive ( :today ) . and_return ( Date . parse ( deprecation_date ) )
2082+ expect ( f . deprecated? ) . to be ( true )
2083+ expect ( f . deprecation_reason ) . to be ( :unmaintained )
2084+ expect ( f . disabled? ) . to be ( false )
2085+ expect ( f . disable_reason ) . to be_nil
2086+ end
2087+
2088+ it "is disabled on disable date" do
2089+ allow ( Date ) . to receive ( :today ) . and_return ( Date . parse ( disable_date ) )
2090+ expect ( f . deprecated? ) . to be ( true )
2091+ expect ( f . deprecation_reason ) . to be ( :unmaintained )
2092+ expect ( f . disabled? ) . to be ( true )
2093+ expect ( f . disable_reason ) . to be ( :unsupported )
2094+ end
2095+ end
2096+
2097+ context "with both dates provided in incorrect order" do
2098+ let ( :f ) do
2099+ deprecation_date_ = deprecation_date
2100+ disable_date_ = disable_date
2101+ formula "foo" do
2102+ url "foo-1.0"
2103+ disable! date : disable_date_ . to_s , because : :unsupported
2104+ deprecate! date : deprecation_date_ . to_s , because : :unmaintained
2105+ end
2106+ end
2107+
2108+ it "is not deprecated before deprecation date" do
2109+ allow ( Date ) . to receive ( :today ) . and_return ( Date . parse ( deprecation_date ) - 1 )
2110+ expect ( f . deprecated? ) . to be ( false )
2111+ expect ( f . deprecation_reason ) . to be_nil
2112+ expect ( f . disabled? ) . to be ( false )
2113+ expect ( f . disable_reason ) . to be_nil
2114+ end
2115+
2116+ it "is deprecated on deprecation date" do
2117+ allow ( Date ) . to receive ( :today ) . and_return ( Date . parse ( deprecation_date ) )
2118+ expect ( f . deprecated? ) . to be ( true )
2119+ expect ( f . deprecation_reason ) . to be ( :unmaintained )
2120+ expect ( f . disabled? ) . to be ( false )
2121+ expect ( f . disable_reason ) . to be_nil
2122+ end
2123+
2124+ it "is disabled on disable date" do
2125+ allow ( Date ) . to receive ( :today ) . and_return ( Date . parse ( disable_date ) )
2126+ expect ( f . deprecated? ) . to be ( true )
2127+ expect ( f . deprecation_reason ) . to be ( :unmaintained )
2128+ expect ( f . disabled? ) . to be ( true )
2129+ expect ( f . disable_reason ) . to be ( :unsupported )
2130+ end
2131+ end
2132+
2133+ context "with only disable date" do
2134+ let ( :f ) do
2135+ disable_date_ = disable_date
2136+ formula "foo" do
2137+ url "foo-1.0"
2138+ disable! date : disable_date_ . to_s , because : :unsupported
2139+ end
2140+ end
2141+
2142+ it "is deprecated before disable date" do
2143+ allow ( Date ) . to receive ( :today ) . and_return ( Date . parse ( disable_date ) << 12 )
2144+ expect ( f . deprecated? ) . to be ( true )
2145+ expect ( f . deprecation_reason ) . to be ( :unsupported )
2146+ expect ( f . disabled? ) . to be ( false )
2147+ expect ( f . disable_reason ) . to be_nil
2148+ end
2149+
2150+ it "is disabled on disable date" do
2151+ allow ( Date ) . to receive ( :today ) . and_return ( Date . parse ( disable_date ) )
2152+ expect ( f . disabled? ) . to be ( true )
2153+ expect ( f . disable_reason ) . to be ( :unsupported )
2154+ end
2155+ end
2156+ end
20562157end
0 commit comments