/
path_helper_spec.rb
117 lines (97 loc) · 2.95 KB
/
path_helper_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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
require 'spec_helper'
require 'fpm/cookery/path_helper'
describe "PathHelper" do
class PathTest
include FPM::Cookery::PathHelper
def destdir; FPM::Cookery::Path.new('/tmp/dest') end
end
let(:helper) { PathTest.new }
describe "path helper methods" do
[ ['prefix', '/usr'],
['etc', '/etc'],
['opt', '/opt'],
['var', '/var'],
['bin', '/usr/bin'],
['doc', '/usr/share/doc'],
['include', '/usr/include'],
['info', '/usr/share/info'],
['lib', '/usr/lib'],
['libexec', '/usr/libexec'],
['man', '/usr/share/man'],
['man1', '/usr/share/man/man1'],
['man2', '/usr/share/man/man2'],
['man3', '/usr/share/man/man3'],
['man4', '/usr/share/man/man4'],
['man5', '/usr/share/man/man5'],
['man6', '/usr/share/man/man6'],
['man7', '/usr/share/man/man7'],
['man8', '/usr/share/man/man8'],
['sbin', '/usr/sbin'],
['share', '/usr/share'] ].each do |m|
name, path = m
describe "##{name}" do
context "without an argument" do
it "returns #{path}" do
helper.send(name).to_s.must_equal path
end
end
context "with an argument" do
it "adds the argument to the path" do
helper.send(name, 'foo/bar').to_s.must_equal "#{path}/foo/bar"
end
end
context "with a nil argument" do
it "does not add anything to the path" do
helper.send(name, nil).to_s.must_equal path
end
end
context "with installing set to true" do
before { helper.installing = true}
it "adds the destdir as prefix" do
helper.send(name, 'blah').to_s.must_equal "#{helper.destdir}#{path}/blah"
end
end
end
end
end
describe "#installing?" do
context "with installing set to true" do
before { helper.installing = true}
it "returns true" do
helper.installing?.must_equal true
end
end
context "with installing set to false" do
before { helper.installing = false }
it "returns true" do
helper.installing?.must_equal false
end
end
end
describe "#with_trueprefix" do
context "with installing set to true" do
before { helper.installing = true }
specify "prefix returns /" do
helper.with_trueprefix do
helper.prefix.to_s.must_equal '/usr'
end
end
it "will restore the previous installing value" do
helper.with_trueprefix {}
helper.installing.must_equal true
end
end
context "with installing set to false" do
before { helper.installing = false}
specify "prefix returns /" do
helper.with_trueprefix do
helper.prefix.to_s.must_equal '/usr'
end
end
it "will restore the previous installing value" do
helper.with_trueprefix {}
helper.installing.must_equal false
end
end
end
end