macos_version: define a method instead
This commit is contained in:
parent
5ae4f254b6
commit
42dd0acdc9
@ -18,8 +18,6 @@ class MacOSVersion < Version
|
|||||||
|
|
||||||
# NOTE: When removing symbols here, ensure that they are added
|
# NOTE: When removing symbols here, ensure that they are added
|
||||||
# to `DEPRECATED_MACOS_VERSIONS` in `MacOSRequirement`.
|
# to `DEPRECATED_MACOS_VERSIONS` in `MacOSRequirement`.
|
||||||
# When adding or removing symbols here, ensure that you
|
|
||||||
# also update the KERNEL_MAJOR_VERSIONS map below.
|
|
||||||
SYMBOLS = {
|
SYMBOLS = {
|
||||||
sequoia: "15",
|
sequoia: "15",
|
||||||
sonoma: "14",
|
sonoma: "14",
|
||||||
@ -33,20 +31,16 @@ class MacOSVersion < Version
|
|||||||
el_capitan: "10.11",
|
el_capitan: "10.11",
|
||||||
}.freeze
|
}.freeze
|
||||||
|
|
||||||
# Map of macOS version strings to kernel major versions.
|
sig { params(macos_version: MacOSVersion).returns(Version) }
|
||||||
# https://en.wikipedia.org/wiki/MacOS_version_history#Releases
|
def self.kernel_major_version(macos_version)
|
||||||
KERNEL_MAJOR_VERSIONS = {
|
version_major = macos_version.major.to_i
|
||||||
"15" => "24",
|
if version_major > 10
|
||||||
"14" => "23",
|
Version.new((version_major + 9).to_s)
|
||||||
"13" => "22",
|
else
|
||||||
"12" => "21",
|
version_minor = macos_version.minor.to_i
|
||||||
"11" => "20",
|
Version.new((version_minor + 4).to_s)
|
||||||
"10.15" => "19",
|
end
|
||||||
"10.14" => "18",
|
end
|
||||||
"10.13" => "17",
|
|
||||||
"10.12" => "16",
|
|
||||||
"10.11" => "15",
|
|
||||||
}.freeze
|
|
||||||
|
|
||||||
sig { params(version: Symbol).returns(T.attached_class) }
|
sig { params(version: Symbol).returns(T.attached_class) }
|
||||||
def self.from_symbol(version)
|
def self.from_symbol(version)
|
||||||
|
@ -7,6 +7,18 @@ RSpec.describe MacOSVersion do
|
|||||||
let(:big_sur_major) { described_class.new("11.0") }
|
let(:big_sur_major) { described_class.new("11.0") }
|
||||||
let(:big_sur_update) { described_class.new("11.1") }
|
let(:big_sur_update) { described_class.new("11.1") }
|
||||||
|
|
||||||
|
describe ".kernel_major_version" do
|
||||||
|
it "returns the kernel major version" do
|
||||||
|
expect(described_class.kernel_major_version(version)).to eq "18"
|
||||||
|
expect(described_class.kernel_major_version(big_sur_major)).to eq "20"
|
||||||
|
expect(described_class.kernel_major_version(big_sur_update)).to eq "20"
|
||||||
|
end
|
||||||
|
|
||||||
|
it "matches the major version returned by OS.kernel_version", :needs_macos do
|
||||||
|
expect(described_class.kernel_major_version(OS::Mac.version)).to eq OS.kernel_version.major
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
specify "comparison with Symbol" do
|
specify "comparison with Symbol" do
|
||||||
expect(version).to be > :high_sierra
|
expect(version).to be > :high_sierra
|
||||||
expect(version).to eq :mojave
|
expect(version).to eq :mojave
|
||||||
|
Loading…
x
Reference in New Issue
Block a user