-
-
Notifications
You must be signed in to change notification settings - Fork 277
/
locker_spec.rb
89 lines (76 loc) 路 2.63 KB
/
locker_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# frozen_string_literal: true
require "spec_helper"
describe Bundle::Locker do
subject(:locker) { described_class }
context ".lockfile" do
it "returns a Pathname" do
allow(Bundle::Brewfile).to receive(:path).and_return(Pathname("Brewfile"))
expect(locker.lockfile.class).to be Pathname
end
end
context ".write_lockfile?" do
it "returns false if --no-lock is passed" do
allow(ARGV).to receive(:include?).with("--no-lock").and_return(true)
expect(locker.write_lockfile?).to be false
end
it "returns false if HOMEBREW_BUNDLE_NO_LOCK is set" do
ENV["HOMEBREW_BUNDLE_NO_LOCK"] = "1"
expect(locker.write_lockfile?).to be false
end
it "returns true without --no-lock or HOMEBREW_BUNDLE_NO_LOCK" do
ENV["HOMEBREW_BUNDLE_NO_LOCK"] = nil
expect(locker.write_lockfile?).to be true
end
end
context ".lock" do
context "writes Brewfile.lock.json" do
let(:lockfile) { Pathname("Brewfile.json.lock") }
let(:brew_options) { { restart_service: true } }
let(:entries) do
[
Bundle::Dsl::Entry.new(:brew, "mysql", brew_options),
Bundle::Dsl::Entry.new(:cask, "adoptopenjdk8"),
Bundle::Dsl::Entry.new(:mas, "Xcode", id: 497799835),
Bundle::Dsl::Entry.new(:tap, "homebrew/homebrew-cask-versions"),
]
end
before do
allow(locker).to receive(:lockfile).and_return(lockfile)
allow(brew_options).to receive(:deep_stringify_keys)
.and_return( { "restart_service" => true } )
allow(locker).to receive(:`).with("brew info --json=v1 --installed").and_return <<~EOS
[
{
"name":"mysql",
"bottle":{
"stable":{}
}
}
]
EOS
allow(locker).to receive(:`).with("brew list --versions").and_return("mysql 8.0.18")
end
context "on macOS" do
before do
allow(OS).to receive(:mac?).and_return(true)
allow(locker).to receive(:`).with("brew cask list --versions").and_return("adoptopenjdk8 8,232:b09")
allow(locker).to receive(:`).with("mas list").and_return("497799835 Xcode (11.2)")
end
it do
expect(lockfile).to receive(:write)
expect(locker.lock(entries)).to be true
end
end
context "on Linux" do
before do
allow(OS).to receive(:mac?).and_return(false)
allow(OS).to receive(:linux?).and_return(true)
end
it do
expect(lockfile).to receive(:write)
expect(locker.lock(entries)).to be true
end
end
end
end
end