Merge pull request #2090 from reitermarkus/spec-bottles

Convert Utils::Bottles test to spec.
This commit is contained in:
Markus Reiter 2017-02-23 09:31:28 +01:00 committed by GitHub
commit 2ab1f13168
3 changed files with 81 additions and 80 deletions

View File

@ -1,79 +0,0 @@
require "testing_env"
require "utils/bottles"
class OSMacBottleTagTests < Homebrew::TestCase
def test_tag_tiger_ppc
MacOS.stubs(:version).returns(MacOS::Version.new("10.4"))
Hardware::CPU.stubs(:type).returns(:ppc)
Hardware::CPU.stubs(:family).returns(:foo)
MacOS.stubs(:prefer_64_bit?).returns(false)
assert_equal :tiger_foo, Utils::Bottles.tag
end
def test_tag_tiger_intel
MacOS.stubs(:version).returns(MacOS::Version.new("10.4"))
Hardware::CPU.stubs(:type).returns(:intel)
MacOS.stubs(:prefer_64_bit?).returns(false)
assert_equal :tiger, Utils::Bottles.tag
end
def test_tag_tiger_ppc_64
MacOS.stubs(:version).returns(MacOS::Version.new("10.4"))
Hardware::CPU.stubs(:type).returns(:ppc)
Hardware::CPU.stubs(:family).returns(:g5)
MacOS.stubs(:prefer_64_bit?).returns(true)
assert_equal :tiger_g5_64, Utils::Bottles.tag
end
# Note that this will probably never be used
def test_tag_tiger_intel_64
MacOS.stubs(:version).returns(MacOS::Version.new("10.4"))
Hardware::CPU.stubs(:type).returns(:intel)
MacOS.stubs(:prefer_64_bit?).returns(true)
assert_equal :tiger_64, Utils::Bottles.tag
end
def test_tag_leopard_intel
MacOS.stubs(:version).returns(MacOS::Version.new("10.5"))
Hardware::CPU.stubs(:type).returns(:intel)
MacOS.stubs(:prefer_64_bit?).returns(false)
assert_equal :leopard, Utils::Bottles.tag
end
def test_tag_leopard_ppc_64
MacOS.stubs(:version).returns(MacOS::Version.new("10.5"))
Hardware::CPU.stubs(:type).returns(:ppc)
Hardware::CPU.stubs(:family).returns(:g5)
MacOS.stubs(:prefer_64_bit?).returns(true)
assert_equal :leopard_g5_64, Utils::Bottles.tag
end
def test_tag_leopard_intel_64
MacOS.stubs(:version).returns(MacOS::Version.new("10.5"))
Hardware::CPU.stubs(:type).returns(:intel)
MacOS.stubs(:prefer_64_bit?).returns(true)
assert_equal :leopard_64, Utils::Bottles.tag
end
def test_tag_snow_leopard_32
MacOS.stubs(:version).returns(MacOS::Version.new("10.6"))
Hardware::CPU.stubs(:is_64_bit?).returns(false)
assert_equal :snow_leopard_32, Utils::Bottles.tag
end
def test_tag_snow_leopard_64
MacOS.stubs(:version).returns(MacOS::Version.new("10.6"))
Hardware::CPU.stubs(:is_64_bit?).returns(true)
assert_equal :snow_leopard, Utils::Bottles.tag
end
def test_tag_lion
MacOS.stubs(:version).returns(MacOS::Version.new("10.7"))
assert_equal :lion, Utils::Bottles.tag
end
def test_tag_mountain_lion
MacOS.stubs(:version).returns(MacOS::Version.new("10.8"))
assert_equal :mountain_lion, Utils::Bottles.tag
end
end

View File

@ -34,7 +34,7 @@ RSpec.configure do |config|
config.include(Test::Helper::Fixtures)
config.before(:each) do |example|
if example.metadata[:needs_macos]
skip "not on macOS" unless OS.mac?
skip "Not on macOS." unless OS.mac?
end
if example.metadata[:needs_python]

View File

@ -0,0 +1,80 @@
require "utils/bottles"
describe Utils::Bottles do
describe "#tag", :needs_macos do
it "returns :tiger_foo on Tiger PowerPC" do
allow(MacOS).to receive(:version).and_return(MacOS::Version.new("10.4"))
allow(Hardware::CPU).to receive(:type).and_return(:ppc)
allow(Hardware::CPU).to receive(:family).and_return(:foo)
allow(MacOS).to receive(:prefer_64_bit?).and_return(false)
expect(described_class.tag).to eq(:tiger_foo)
end
it "returns :tiger on Tiger Intel" do
allow(MacOS).to receive(:version).and_return(MacOS::Version.new("10.4"))
allow(Hardware::CPU).to receive(:type).and_return(:intel)
allow(MacOS).to receive(:prefer_64_bit?).and_return(false)
expect(described_class.tag).to eq(:tiger)
end
it "returns :tiger_g5_64 on Tiger PowerPC 64-bit" do
allow(MacOS).to receive(:version).and_return(MacOS::Version.new("10.4"))
allow(Hardware::CPU).to receive(:type).and_return(:ppc)
allow(Hardware::CPU).to receive(:family).and_return(:g5)
allow(MacOS).to receive(:prefer_64_bit?).and_return(true)
expect(described_class.tag).to eq(:tiger_g5_64)
end
# Note that this will probably never be used
it "returns :tiger_64 on Tiger Intel 64-bit" do
allow(MacOS).to receive(:version).and_return(MacOS::Version.new("10.4"))
allow(Hardware::CPU).to receive(:type).and_return(:intel)
allow(MacOS).to receive(:prefer_64_bit?).and_return(true)
expect(described_class.tag).to eq(:tiger_64)
end
it "returns :leopard on Leopard Intel" do
allow(MacOS).to receive(:version).and_return(MacOS::Version.new("10.5"))
allow(Hardware::CPU).to receive(:type).and_return(:intel)
allow(MacOS).to receive(:prefer_64_bit?).and_return(false)
expect(described_class.tag).to eq(:leopard)
end
it "returns :leopard_g5_64 on Leopard PowerPC 64-bit" do
allow(MacOS).to receive(:version).and_return(MacOS::Version.new("10.5"))
allow(Hardware::CPU).to receive(:type).and_return(:ppc)
allow(Hardware::CPU).to receive(:family).and_return(:g5)
allow(MacOS).to receive(:prefer_64_bit?).and_return(true)
expect(described_class.tag).to eq(:leopard_g5_64)
end
it "returns :leopard_64 on Leopard Intel 64-bit" do
allow(MacOS).to receive(:version).and_return(MacOS::Version.new("10.5"))
allow(Hardware::CPU).to receive(:type).and_return(:intel)
allow(MacOS).to receive(:prefer_64_bit?).and_return(true)
expect(described_class.tag).to eq(:leopard_64)
end
it "returns :snow_leopard_32 on Snow Leopard 32-bit" do
allow(MacOS).to receive(:version).and_return(MacOS::Version.new("10.6"))
allow(Hardware::CPU).to receive(:is_64_bit?).and_return(false)
expect(described_class.tag).to eq(:snow_leopard_32)
end
it "returns :snow_leopard on Snow Leopard 64-bit" do
allow(MacOS).to receive(:version).and_return(MacOS::Version.new("10.6"))
allow(Hardware::CPU).to receive(:is_64_bit?).and_return(true)
expect(described_class.tag).to eq(:snow_leopard)
end
it "returns :lion on Lion" do
allow(MacOS).to receive(:version).and_return(MacOS::Version.new("10.7"))
expect(described_class.tag).to eq(:lion)
end
it "returns :mountain_lion on Mountain Lion" do
allow(MacOS).to receive(:version).and_return(MacOS::Version.new("10.8"))
expect(described_class.tag).to eq(:mountain_lion)
end
end
end