2019-04-19 15:38:03 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-02-17 19:05:17 +01:00
|
|
|
require "formula_pin"
|
|
|
|
|
2024-02-18 15:11:11 -08:00
|
|
|
RSpec.describe FormulaPin do
|
2021-01-31 13:14:23 -05:00
|
|
|
subject(:formula_pin) { described_class.new(formula) }
|
2018-03-25 13:30:37 +01:00
|
|
|
|
2017-02-17 19:05:17 +01:00
|
|
|
let(:name) { "double" }
|
2024-03-07 16:20:20 +00:00
|
|
|
let(:formula) { instance_double(Formula, name:, rack: HOMEBREW_CELLAR/name) }
|
2017-02-17 19:05:17 +01:00
|
|
|
|
2018-03-25 13:30:37 +01:00
|
|
|
before do
|
2017-02-17 19:05:17 +01:00
|
|
|
formula.rack.mkpath
|
|
|
|
|
|
|
|
allow(formula).to receive(:installed_prefixes) do
|
2017-06-20 15:27:16 +02:00
|
|
|
formula.rack.directory? ? formula.rack.subdirs.sort : []
|
2017-02-17 19:05:17 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
allow(formula).to receive(:installed_kegs) do
|
|
|
|
formula.installed_prefixes.map { |prefix| Keg.new(prefix) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it "is not pinnable by default" do
|
2021-01-31 13:14:23 -05:00
|
|
|
expect(formula_pin).not_to be_pinnable
|
2017-02-17 19:05:17 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
it "is pinnable if the Keg exists" do
|
|
|
|
(formula.rack/"0.1").mkpath
|
2021-01-31 13:14:23 -05:00
|
|
|
expect(formula_pin).to be_pinnable
|
2017-02-17 19:05:17 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
specify "#pin and #unpin" do
|
|
|
|
(formula.rack/"0.1").mkpath
|
|
|
|
|
2021-01-31 13:14:23 -05:00
|
|
|
formula_pin.pin
|
|
|
|
expect(formula_pin).to be_pinned
|
2017-02-17 19:05:17 +01:00
|
|
|
expect(HOMEBREW_PINNED_KEGS/name).to be_a_directory
|
|
|
|
expect(HOMEBREW_PINNED_KEGS.children.count).to eq(1)
|
|
|
|
|
2021-01-31 13:14:23 -05:00
|
|
|
formula_pin.unpin
|
|
|
|
expect(formula_pin).not_to be_pinned
|
2017-02-17 19:05:17 +01:00
|
|
|
expect(HOMEBREW_PINNED_KEGS).not_to be_a_directory
|
|
|
|
end
|
|
|
|
end
|