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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
require "language/python"
require "resource"
describe Language::Python::Virtualenv::Virtualenv do
subject { described_class.new(formula, dir, "python") }
let(:dir) { mktmpdir }
let(:resource) { double("resource", stage: true) }
let(:formula_bin) { dir/"formula_bin" }
let(:formula) { double("formula", resource: resource, bin: formula_bin) }
describe "#create" do
it "creates a virtual environment" do
expect(formula).to receive(:resource).with("homebrew-virtualenv").and_return(resource)
subject.create
end
specify "virtual environment creation is idempotent" do
expect(formula).to receive(:resource).with("homebrew-virtualenv").and_return(resource)
subject.create
FileUtils.mkdir_p dir/"bin"
FileUtils.touch dir/"bin/python"
subject.create
FileUtils.rm dir/"bin/python"
end
end
describe "#pip_install" do
it "accepts a string" do
expect(formula).to receive(:system)
.with(dir/"bin/pip", "install", "-v", "--no-deps",
"--no-binary", ":all:", "--ignore-installed", "foo")
.and_return(true)
subject.pip_install "foo"
end
it "accepts a multi-line strings" do
expect(formula).to receive(:system)
.with(dir/"bin/pip", "install", "-v", "--no-deps",
"--no-binary", ":all:", "--ignore-installed", "foo", "bar")
.and_return(true)
subject.pip_install <<~EOS
foo
bar
EOS
end
it "accepts an array" do
expect(formula).to receive(:system)
.with(dir/"bin/pip", "install", "-v", "--no-deps",
"--no-binary", ":all:", "--ignore-installed", "foo")
.and_return(true)
expect(formula).to receive(:system)
.with(dir/"bin/pip", "install", "-v", "--no-deps",
"--no-binary", ":all:", "--ignore-installed", "bar")
.and_return(true)
subject.pip_install ["foo", "bar"]
end
it "accepts a Resource" do
res = Resource.new("test")
expect(res).to receive(:stage).and_yield
expect(formula).to receive(:system)
.with(dir/"bin/pip", "install", "-v", "--no-deps",
"--no-binary", ":all:", "--ignore-installed", Pathname.pwd)
.and_return(true)
subject.pip_install res
end
end
describe "#pip_install_and_link" do
let(:src_bin) { dir/"bin" }
let(:dest_bin) { formula.bin }
it "can link scripts" do
src_bin.mkpath
expect(src_bin/"kilroy").not_to exist
expect(dest_bin/"kilroy").not_to exist
FileUtils.touch src_bin/"irrelevant"
bin_before = Dir.glob(src_bin/"*")
FileUtils.touch src_bin/"kilroy"
bin_after = Dir.glob(src_bin/"*")
expect(subject).to receive(:pip_install).with("foo")
expect(Dir).to receive(:[]).with(src_bin/"*").twice.and_return(bin_before, bin_after)
subject.pip_install_and_link "foo"
expect(src_bin/"kilroy").to exist
expect(dest_bin/"kilroy").to exist
expect(dest_bin/"kilroy").to be_a_symlink
expect((src_bin/"kilroy").realpath).to eq((dest_bin/"kilroy").realpath)
expect(dest_bin/"irrelevant").not_to exist
end
end
end
|