|
| 1 | +# typed: strict |
1 | 2 | # frozen_string_literal: true
|
2 | 3 |
|
3 | 4 | require "keg"
|
|
6 | 7 | RSpec.describe Keg do
|
7 | 8 | include FileUtils
|
8 | 9 |
|
9 |
| - def setup_test_keg(name, version) |
| 10 | + define_method(:setup_test_keg) do |name, version| |
10 | 11 | path = HOMEBREW_CELLAR/name/version
|
11 | 12 | (path/"bin").mkpath
|
12 | 13 |
|
@@ -319,6 +320,29 @@ def setup_test_keg(name, version)
|
319 | 320 | end
|
320 | 321 | end
|
321 | 322 |
|
| 323 | + describe "#homebrew_created_file?" do |
| 324 | + it "identifies Homebrew service files" do |
| 325 | + plist_file = instance_double(Pathname, extname: ".plist", basename: Pathname.new("homebrew.foo.plist")) |
| 326 | + service_file = instance_double(Pathname, extname: ".service", basename: Pathname.new("homebrew.foo.service")) |
| 327 | + timer_file = instance_double(Pathname, extname: ".timer", basename: Pathname.new("homebrew.foo.timer")) |
| 328 | + regular_file = instance_double(Pathname, extname: ".txt", basename: Pathname.new("readme.txt")) |
| 329 | + non_homebrew_plist = instance_double(Pathname, extname: ".plist", |
| 330 | + basename: Pathname.new("com.example.foo.plist")) |
| 331 | + |
| 332 | + allow(plist_file.basename).to receive(:to_s).and_return("homebrew.foo.plist") |
| 333 | + allow(service_file.basename).to receive(:to_s).and_return("homebrew.foo.service") |
| 334 | + allow(timer_file.basename).to receive(:to_s).and_return("homebrew.foo.timer") |
| 335 | + allow(regular_file.basename).to receive(:to_s).and_return("readme.txt") |
| 336 | + allow(non_homebrew_plist.basename).to receive(:to_s).and_return("com.example.foo.plist") |
| 337 | + |
| 338 | + expect(keg.homebrew_created_file?(plist_file)).to be true |
| 339 | + expect(keg.homebrew_created_file?(service_file)).to be true |
| 340 | + expect(keg.homebrew_created_file?(timer_file)).to be true |
| 341 | + expect(keg.homebrew_created_file?(regular_file)).to be false |
| 342 | + expect(keg.homebrew_created_file?(non_homebrew_plist)).to be false |
| 343 | + end |
| 344 | + end |
| 345 | + |
322 | 346 | specify "#link and #unlink" do
|
323 | 347 | expect(keg).not_to be_linked
|
324 | 348 | keg.link
|
|
0 commit comments