-
Notifications
You must be signed in to change notification settings - Fork 88
/
path_spec.rb
160 lines (131 loc) · 4.12 KB
/
path_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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
require 'spec_helper'
require 'fpm/cookery/path'
require 'tmpdir'
describe "Path" do
describe ".pwd" do
it "returns the current dir" do
Dir.chdir('/tmp') do
expect(FPM::Cookery::Path.pwd.to_s).to match(%r{/tmp|/private/tmp})
end
end
it "adds the given path to the current dir" do
Dir.chdir('/tmp') do
expect(FPM::Cookery::Path.pwd('foo').to_s).to match(%r{/tmp|/private/tmp})
end
end
end
describe "#+" do
let(:path) { FPM::Cookery::Path.new('/foo') }
describe "with a path fragmet" do
it "returns a new concatenated path object" do
expect((path + 'bar').to_s).to eq('/foo/bar')
end
end
describe "with an absolute path" do
it "overwrites the old path" do
expect((path + '/bar').to_s).to eq('/bar')
end
end
describe "with an empty fragment" do
it "does't modify the path" do
expect((path + '').to_s).to eq('/foo')
end
end
end
describe "#/" do
let(:path) { FPM::Cookery::Path.new('/foo') }
describe "with a path fragment" do
it "returns a new concatenated path object" do
expect((path/'bar').to_s).to eq('/foo/bar')
end
end
describe "with an absolute path" do
it "returns a new concatenated path object" do
expect((path/'/baz').to_s).to eq('/foo/baz')
end
end
describe "with a Path argument" do
it "returns a new concatenated path object" do
expect((path/path).to_s).to eq('/foo/foo')
end
end
describe "with a nil argument" do
it "does not modify the path" do
expect((path/nil).to_s).to eq('/foo')
end
end
end
describe "#=~" do
let(:path) { FPM::Cookery::Path.new('/bar/baz/quux.txt') }
context "given a Regexp matching the path" do
it "returns the index of the beginning of the the match" do
expect(path =~ %r[/\w{4}\.\w{3}]).to eq(8)
end
end
context "given a non-Regexp argument" do
it "raises TypeError" do
expect { path =~ 'this' }.to raise_error do |error|
expect(error).to be_a(TypeError)
expect(error.message).to match(/type\s+mismatch/)
end
end
end
end
describe "#mkdir" do
it "creates the directory" do
dir = Dir.mktmpdir
FileUtils.rm_rf(dir)
expect(File.exist?(dir)).to eq(false)
FPM::Cookery::Path.new(dir).mkdir
expect(File.exist?(dir)).to eq(true)
FileUtils.rm_rf(dir)
end
describe "directory exists" do
it "does not throw an error" do
dir = Dir.mktmpdir
expect(File.exist?(dir)).to eq(true)
expect(FPM::Cookery::Path.new(dir).mkdir).to eq([dir])
FileUtils.rm_rf(dir)
end
end
end
describe "#install" do
describe "with an array as src" do
it "installs every file in the list" do
Dir.mktmpdir do |dir|
path = FPM::Cookery::Path.new(dir)
path.install([__FILE__, File.expand_path('../spec_helper.rb', __FILE__)])
expect(File.exist?(path/File.basename(__FILE__))).to eq(true)
expect(File.exist?(path/'spec_helper.rb')).to eq(true)
end
end
end
describe "with a hash as src" do
it "installs the file with a new basename" do
Dir.mktmpdir do |dir|
path = FPM::Cookery::Path.new(dir)
path.install(File.expand_path('../spec_helper.rb', __FILE__) => 'foo.rb')
expect(File.exist?(path/'foo.rb')).to eq(true)
end
end
end
describe "with a string as src" do
it "installs the file" do
Dir.mktmpdir do |dir|
path = FPM::Cookery::Path.new(dir)
path.install(File.expand_path('../spec_helper.rb', __FILE__))
expect(File.exist?(path/'spec_helper.rb')).to eq(true)
end
end
end
describe "with a new basename argument" do
it "installs the file with a new basename" do
Dir.mktmpdir do |dir|
path = FPM::Cookery::Path.new(dir)
path.install(File.expand_path('../spec_helper.rb', __FILE__), 'foo.rb')
expect(File.exist?(path/'foo.rb')).to eq(true)
end
end
end
end
end