pa 1.1.4 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +4 -4
- data/Gemfile.lock +8 -8
- data/lib/pa/cmd.rb +124 -87
- data/lib/pa/directory.rb +55 -19
- data/lib/pa/path.rb +38 -180
- data/lib/pa/state.rb +12 -4
- data/lib/pa/version.rb +1 -1
- data/lib/pa.rb +318 -38
- data/spec/pa/cmd_spec.rb +50 -17
- data/spec/pa/directory_spec.rb +107 -16
- data/spec/pa/path_spec.rb +71 -173
- data/spec/pa/state_spec.rb +9 -3
- data/spec/pa_spec.rb +261 -1
- data/spec/spec_helper.rb +39 -0
- metadata +9 -2
data/spec/pa/path_spec.rb
CHANGED
@@ -1,72 +1,32 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
class T_FakePath
|
4
|
-
def path
|
5
|
-
"hello"
|
6
|
-
end
|
7
|
-
end
|
1
|
+
require "spec_helper"
|
8
2
|
|
9
3
|
describe Pa do
|
10
|
-
|
11
|
-
it
|
12
|
-
Pa.
|
4
|
+
describe ".absolute?" do
|
5
|
+
it "is true if path is a absolute path" do
|
6
|
+
Pa.absolute?("/").should == true
|
13
7
|
end
|
14
8
|
|
15
|
-
it
|
16
|
-
Pa.
|
9
|
+
it "is false if path is a relative path" do
|
10
|
+
Pa.absolute?(".").should == false
|
17
11
|
end
|
18
12
|
end
|
19
13
|
|
20
|
-
|
21
|
-
|
22
|
-
'foo.bar'.match(Pa::NAME_EXT_PAT).captures.should == %w(foo bar)
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'matchs `foo`' do
|
26
|
-
'foo'.match(Pa::NAME_EXT_PAT).captures.should == ['foo', nil]
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
describe '.get' do
|
31
|
-
it 'get path from a path object' do
|
32
|
-
Pa.get(T_FakePath.new).should == 'hello'
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'get path from a string' do
|
36
|
-
Pa.get('foo').should == 'foo'
|
37
|
-
end
|
38
|
-
|
39
|
-
it 'get nil from nil' do
|
40
|
-
Pa.get(nil).should == nil
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'otherwise raise ArgumentError' do
|
44
|
-
lambda { Pa.get([]) }.should raise_error(ArgumentError)
|
45
|
-
end
|
14
|
+
it ".dir2 => String" do
|
15
|
+
Pa.dir2("/home/guten").should be_an_instance_of String
|
46
16
|
end
|
47
17
|
|
48
|
-
describe
|
49
|
-
it
|
50
|
-
Pa.absolute?('/').should == true
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'is false if path is a relative path' do
|
54
|
-
Pa.absolute?('.').should == false
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
describe '.dangling?' do
|
59
|
-
it 'works' do
|
18
|
+
describe ".dangling?" do
|
19
|
+
it "works" do
|
60
20
|
olddir=Dir.pwd
|
61
21
|
Dir.chdir("#{$specdir}/data/tmp")
|
62
22
|
|
63
23
|
begin
|
64
|
-
File.open(
|
65
|
-
File.symlink(
|
66
|
-
File.symlink(
|
24
|
+
File.open("fa", "w"){|f| f.puts "guten" }
|
25
|
+
File.symlink("fa", "symlink")
|
26
|
+
File.symlink("fb", "dangling")
|
67
27
|
|
68
|
-
Pa.dangling?(
|
69
|
-
Pa.dangling?(
|
28
|
+
Pa.dangling?("symlink").should be_false
|
29
|
+
Pa.dangling?("dangling").should be_true
|
70
30
|
ensure
|
71
31
|
FileUtils.rm_r Dir.glob("*")
|
72
32
|
Dir.chdir(olddir)
|
@@ -74,175 +34,113 @@ describe Pa do
|
|
74
34
|
end
|
75
35
|
end
|
76
36
|
|
77
|
-
describe
|
37
|
+
describe ".pwd2" do
|
78
38
|
olddir = Dir.getwd
|
79
|
-
Dir.chdir(
|
39
|
+
Dir.chdir("/tmp")
|
80
40
|
begin
|
81
|
-
Pa.pwd2.should ==
|
41
|
+
Pa.pwd2.should == "/tmp"
|
82
42
|
ensure
|
83
43
|
Dir.chdir(olddir)
|
84
44
|
end
|
85
45
|
end
|
86
46
|
|
87
|
-
describe
|
47
|
+
describe ".dir2" do
|
88
48
|
it "get a path's directory name" do
|
89
|
-
Pa.dir2(
|
49
|
+
Pa.dir2("/home/guten").should == "/home"
|
90
50
|
end
|
91
51
|
end
|
92
52
|
|
93
|
-
describe
|
94
|
-
it
|
95
|
-
Pa.base2(
|
53
|
+
describe ".base2" do
|
54
|
+
it "get name, ext with :ext => true" do
|
55
|
+
Pa.base2("/home/foo.bar", ext: true).should == ["foo", "bar"]
|
96
56
|
end
|
97
57
|
end
|
98
58
|
|
99
|
-
describe
|
59
|
+
describe ".base" do
|
60
|
+
it "works" do
|
61
|
+
Pa.base("/home/foo.bar", ext: true).should == [Pa("foo"), "bar"]
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe ".ext2" do
|
100
66
|
it "get a path's extension" do
|
101
|
-
Pa.ext2(
|
67
|
+
Pa.ext2("/home/a.txt").should == "txt"
|
102
68
|
end
|
103
69
|
|
104
|
-
it
|
105
|
-
Pa.ext2(
|
70
|
+
it "return nil when don extension" do
|
71
|
+
Pa.ext2("/home/a").should == nil
|
106
72
|
end
|
107
73
|
|
108
|
-
it
|
109
|
-
Pa.ext2(
|
74
|
+
it "with complex" do
|
75
|
+
Pa.ext2("/home/a.b.c.txt").should == "txt"
|
110
76
|
end
|
111
77
|
end
|
112
78
|
|
113
|
-
describe
|
114
|
-
it
|
115
|
-
Pa.absolute2(
|
79
|
+
describe ".absolute2" do
|
80
|
+
it "returns absolute_path" do
|
81
|
+
Pa.absolute2(".").should == File.absolute_path(".")
|
116
82
|
end
|
117
83
|
end
|
118
84
|
|
119
|
-
describe
|
120
|
-
it
|
121
|
-
Pa.expand2(
|
85
|
+
describe ".expand2" do
|
86
|
+
it "expand_path" do
|
87
|
+
Pa.expand2("~").should == File.expand_path("~")
|
122
88
|
end
|
123
89
|
end
|
124
90
|
|
125
|
-
describe
|
126
|
-
it
|
127
|
-
ENV[
|
128
|
-
Pa.shorten2(
|
91
|
+
describe ".shorten2" do
|
92
|
+
it "short /home/usr/file into ~/file" do
|
93
|
+
ENV["HOME"] = "/home/foo"
|
94
|
+
Pa.shorten2("/home/foo/file").should == "~/file"
|
129
95
|
end
|
130
96
|
|
131
|
-
it
|
132
|
-
ENV[
|
133
|
-
Pa.shorten2(
|
97
|
+
it "not short /home/other-user/file" do
|
98
|
+
ENV["HOME"] = "/home/foo"
|
99
|
+
Pa.shorten2("/home/bar/file").should == "/home/bar/file"
|
134
100
|
end
|
135
101
|
end
|
136
102
|
|
137
|
-
describe
|
138
|
-
Pa.real2(
|
103
|
+
describe ".real2" do
|
104
|
+
Pa.real2(".").should == File.realpath(".")
|
139
105
|
end
|
140
106
|
|
141
|
-
describe
|
107
|
+
describe ".parent2" do
|
142
108
|
before :each do
|
143
|
-
@path =
|
109
|
+
@path = "/home/foo/a.txt"
|
144
110
|
end
|
145
111
|
|
146
|
-
it
|
147
|
-
Pa.parent2(@path).should ==
|
112
|
+
it "return parent path" do
|
113
|
+
Pa.parent2(@path).should == "/home/foo"
|
148
114
|
end
|
149
115
|
|
150
|
-
it
|
151
|
-
Pa.parent2(@path, 2).should ==
|
116
|
+
it "return parent upto 2 level path" do
|
117
|
+
Pa.parent2(@path, 2).should == "/home"
|
152
118
|
end
|
153
119
|
end
|
154
120
|
|
155
|
-
describe
|
156
|
-
it
|
157
|
-
Pa.
|
158
|
-
end
|
121
|
+
describe "class DELEGATE_METHODS" do
|
122
|
+
it "works" do
|
123
|
+
Pa.should_receive(:pwd2).with(1,2)
|
159
124
|
|
160
|
-
|
161
|
-
Pa.split2('/home/b/a.txt', :all => true).should == ['/', 'home', 'b', 'a.txt']
|
125
|
+
Pa.pwd(1,2)
|
162
126
|
end
|
163
127
|
end
|
164
128
|
|
165
|
-
describe
|
166
|
-
it
|
167
|
-
Pa.
|
168
|
-
end
|
169
|
-
end
|
129
|
+
describe "instance DELEGATE_METHODS2" do
|
130
|
+
it "works" do
|
131
|
+
Pa.should_receive(:parent2).with("foo", 1, 2)
|
170
132
|
|
171
|
-
|
172
|
-
it 'join a path' do
|
173
|
-
Pa.join2('/a', 'b').should == '/a/b'
|
133
|
+
Pa.new("foo").parent2(1, 2)
|
174
134
|
end
|
135
|
+
end
|
175
136
|
|
176
|
-
|
177
|
-
|
178
|
-
|
137
|
+
describe "instance DELEGATE_METHODS" do
|
138
|
+
it "works" do
|
139
|
+
p = Pa.new("foo")
|
179
140
|
|
180
|
-
|
181
|
-
|
141
|
+
p.should_receive(:parent2).with(1,2)
|
142
|
+
ret = p.parent(1,2)
|
143
|
+
ret.should be_an_instance_of(Pa)
|
182
144
|
end
|
183
145
|
end
|
184
|
-
|
185
|
-
describe '#==' do
|
186
|
-
it 'runs ok' do
|
187
|
-
(Pa('/home') == Pa('/home')).should be_true
|
188
|
-
end
|
189
|
-
end
|
190
|
-
|
191
|
-
describe '#+' do
|
192
|
-
it 'runs ok' do
|
193
|
-
(Pa('/home')+'~').should == Pa('/home~')
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|
197
|
-
describe '#sub2' do
|
198
|
-
it 'runs ok' do
|
199
|
-
Pa('/home/foo').sub2(/o/,'').should == '/hme/foo'
|
200
|
-
end
|
201
|
-
end
|
202
|
-
|
203
|
-
describe '#sub!' do
|
204
|
-
it 'runs ok' do
|
205
|
-
pa = Pa('/home/foo')
|
206
|
-
pa.sub!(/o/,'')
|
207
|
-
pa.should == Pa('/hme/foo')
|
208
|
-
end
|
209
|
-
end
|
210
|
-
|
211
|
-
describe '#gsub2' do
|
212
|
-
it 'runs ok' do
|
213
|
-
Pa('/home/foo').gsub2(/o/,'').should == '/hme/f'
|
214
|
-
end
|
215
|
-
end
|
216
|
-
|
217
|
-
describe '#gsub!' do
|
218
|
-
it 'runs ok' do
|
219
|
-
pa = Pa('/home/foo')
|
220
|
-
pa.gsub!(/o/,'')
|
221
|
-
pa.should == Pa('/hme/f')
|
222
|
-
end
|
223
|
-
end
|
224
|
-
|
225
|
-
describe '#match' do
|
226
|
-
it 'runs ok' do
|
227
|
-
Pa('/home/foo').match(/foo/)[0].should == 'foo'
|
228
|
-
end
|
229
|
-
end
|
230
|
-
|
231
|
-
describe '#start_with?' do
|
232
|
-
it 'runs ok' do
|
233
|
-
Pa('/home/foo').start_with?('/home').should be_true
|
234
|
-
end
|
235
|
-
end
|
236
|
-
|
237
|
-
describe '#end_with?' do
|
238
|
-
it 'runs ok' do
|
239
|
-
Pa('/home/foo').end_with?('foo').should be_true
|
240
|
-
end
|
241
|
-
end
|
242
|
-
|
243
|
-
describe '#=~' do
|
244
|
-
it 'runs ok' do
|
245
|
-
(Pa('/home/foo') =~ /foo/).should be_true
|
246
|
-
end
|
247
|
-
end
|
248
146
|
end
|
data/spec/pa/state_spec.rb
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe Pa do
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
it ".exists?" do
|
5
|
+
File.should_receive(:exists?).with("foo")
|
6
|
+
Pa.exists?("foo")
|
7
|
+
end
|
8
|
+
|
9
|
+
it "#exists?" do
|
10
|
+
File.should_receive(:exists?).with("foo")
|
11
|
+
Pa.new("foo").exists?
|
12
|
+
end
|
7
13
|
end
|
data/spec/pa_spec.rb
CHANGED
@@ -1,9 +1,269 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
|
+
class Pa
|
4
|
+
class <<self
|
5
|
+
public :_wrap, :build_path2
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
3
9
|
describe Pa do
|
10
|
+
it "._wrap" do
|
11
|
+
Pa._wrap("foo").should == Pa("foo")
|
12
|
+
Pa._wrap(["guten", "tag"]).should == [Pa("guten"), Pa("tag")]
|
13
|
+
end
|
14
|
+
|
15
|
+
describe ".build_path2" do
|
16
|
+
it "works" do
|
17
|
+
Pa.build_path2(path: "foo/bar.avi").should == "foo/bar.avi"
|
18
|
+
Pa.build_path2(dir: "foo", name: "bar", ext: "avi").should == "foo/bar.avi"
|
19
|
+
end
|
20
|
+
|
21
|
+
it "complex examples" do
|
22
|
+
Pa.build_path2(dir: "foo").should == "foo"
|
23
|
+
Pa.build_path2(fname: "bar.avi").should == "bar.avi"
|
24
|
+
Pa.build_path2(base: "bar.avi").should == "bar.avi"
|
25
|
+
Pa.build_path2(name: "bar").should == "bar"
|
26
|
+
Pa.build_path2(fext: ".avi").should == ".avi"
|
27
|
+
Pa.build_path2(ext: "avi").should == ".avi"
|
28
|
+
Pa.build_path2(dir: "", fname: "bar.avi").should == "bar.avi"
|
29
|
+
end
|
30
|
+
|
31
|
+
it "percedure" do
|
32
|
+
Pa.build_path2(path: "foo", fname: "bar").should == "foo"
|
33
|
+
Pa.build_path2(fname: "foo", name: "bar").should == "foo"
|
34
|
+
Pa.build_path2(fname: "foo", ext: "bar").should == "foo"
|
35
|
+
Pa.build_path2(fname: "foo", fext: ".bar").should == "foo"
|
36
|
+
Pa.build_path2(fext: "foo", ext: "bar").should == "foo"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe ".get" do
|
41
|
+
it "get path from a path object" do
|
42
|
+
path = Object.new
|
43
|
+
def path.path
|
44
|
+
"hello"
|
45
|
+
end
|
46
|
+
Pa.get(path).should == "hello"
|
47
|
+
end
|
48
|
+
|
49
|
+
it "get path from a string" do
|
50
|
+
Pa.get("foo").should == "foo"
|
51
|
+
end
|
52
|
+
|
53
|
+
it "get nil from nil" do
|
54
|
+
Pa.get(nil).should == nil
|
55
|
+
end
|
56
|
+
|
57
|
+
it "otherwise raise ArgumentError" do
|
58
|
+
lambda { Pa.get([]) }.should raise_error(ArgumentError)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "split2" do
|
63
|
+
it "split a path into two part: dirname and basename" do
|
64
|
+
Pa.split2("/home/b/a.txt").should == ["/home/b", "a.txt"]
|
65
|
+
end
|
66
|
+
|
67
|
+
it "with :all options: split all parts" do
|
68
|
+
Pa.split2("/home/b/a.txt", :all => true).should == ["/", "home", "b", "a.txt"]
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "split" do
|
73
|
+
it "is a special case" do
|
74
|
+
Pa.split("/home/b/a.txt").should == [Pa("/home/b"), "a.txt"]
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
describe ".join2" do
|
79
|
+
it "join a path" do
|
80
|
+
Pa.join2("/a", "b").should == "/a/b"
|
81
|
+
end
|
82
|
+
|
83
|
+
it "skip nil values" do
|
84
|
+
Pa.join2("/a", "b", nil).should == "/a/b"
|
85
|
+
end
|
86
|
+
|
87
|
+
it "skip empty values" do
|
88
|
+
Pa.join2("/a", "b", "").should == "/a/b"
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe ".build2" do
|
93
|
+
it "works" do
|
94
|
+
Pa.build2("/home/guten.avi"){ |p| "#{p.dir}/foo.#{p.ext}" }.should == "/home/foo.avi"
|
95
|
+
Pa.build2(dir: "/home", name: "guten", ext: "avi").should == "/home/guten.avi"
|
96
|
+
Pa.build2(path: "/home/guten.avi"){ |p| "#{p.dir}/foo.#{p.ext}" }.should == "/home/foo.avi"
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
describe "class DELEGATE_METHODS" do
|
101
|
+
it "works" do
|
102
|
+
Pa.stub(:build2){|arg| arg }
|
103
|
+
|
104
|
+
Pa.build("foo").should == Pa("foo")
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
describe "#initilaize" do
|
109
|
+
it "support ~/foo path" do
|
110
|
+
Pa.new("~/foo").should == Pa("#{ENV['HOME']}/foo")
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
it "#absolute2" do
|
115
|
+
Pa.new("foo.avi").absolute2.should == File.join(File.absolute_path("."), "foo.avi")
|
116
|
+
end
|
117
|
+
|
118
|
+
it "#dir2" do
|
119
|
+
Pa.new("foo.avi").dir2.should == "."
|
120
|
+
end
|
121
|
+
|
122
|
+
it "#dir_strict2" do
|
123
|
+
Pa.new("foo.avi").dir_strict2.should == ""
|
124
|
+
Pa.new("./foo.avi").dir_strict2.should == "."
|
125
|
+
Pa.new("../foo.avi").dir_strict2.should == ".."
|
126
|
+
Pa.new("/foo.avi").dir_strict2.should == "/"
|
127
|
+
end
|
128
|
+
|
129
|
+
it "#base2" do
|
130
|
+
Pa.new("foo.avi").base2.should == "foo.avi"
|
131
|
+
end
|
132
|
+
|
133
|
+
it "#name2" do
|
134
|
+
Pa.new("foo.avi").name2.should == "foo"
|
135
|
+
end
|
136
|
+
|
137
|
+
it "#ext2" do
|
138
|
+
Pa.new("foo.avi").ext2.should == "avi"
|
139
|
+
Pa.new("foo").ext2.should == ""
|
140
|
+
end
|
141
|
+
|
142
|
+
it "#fext2" do
|
143
|
+
Pa.new("foo.avi").fext2.should == ".avi"
|
144
|
+
Pa.new("foo").ext2.should == ""
|
145
|
+
end
|
146
|
+
|
147
|
+
it "#inspect" do
|
148
|
+
Pa.new("/foo/bar.avi").inspect.should =~ /path|absolute/
|
149
|
+
end
|
150
|
+
|
151
|
+
it "#to_s" do
|
152
|
+
Pa.new("bar.avi").to_s.should == "bar.avi"
|
153
|
+
end
|
154
|
+
|
155
|
+
it "#replace" do
|
156
|
+
a = Pa.new("/home/guten")
|
157
|
+
a.replace "/bar/foo.avi"
|
158
|
+
|
159
|
+
a.path.should == "/bar/foo.avi"
|
160
|
+
a.absolute2.should == "/bar/foo.avi"
|
161
|
+
a.dir2.should == "/bar"
|
162
|
+
a.fname2.should == "foo.avi"
|
163
|
+
a.base2.should == "foo.avi"
|
164
|
+
a.name2.should == "foo"
|
165
|
+
a.ext2.should == "avi"
|
166
|
+
a.fext2.should == ".avi"
|
167
|
+
end
|
168
|
+
|
4
169
|
describe "#<=>" do
|
5
170
|
it "runs ok" do
|
6
|
-
(Pa(
|
171
|
+
(Pa("/home/b") <=> Pa("/home/a")).should == 1
|
7
172
|
end
|
8
173
|
end
|
174
|
+
|
175
|
+
describe "#+" do
|
176
|
+
it "runs ok" do
|
177
|
+
(Pa("/home")+"~").should == Pa("/home~")
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
describe "#sub2" do
|
182
|
+
it "runs ok" do
|
183
|
+
Pa("/home/foo").sub2(/o/,"").should == "/hme/foo"
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
describe "#sub!" do
|
188
|
+
it "runs ok" do
|
189
|
+
pa = Pa("/home/foo")
|
190
|
+
pa.sub!(/o/,"")
|
191
|
+
pa.should == Pa("/hme/foo")
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
describe "#gsub2" do
|
196
|
+
it "runs ok" do
|
197
|
+
Pa("/home/foo").gsub2(/o/,"").should == "/hme/f"
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
describe "#gsub!" do
|
202
|
+
it "runs ok" do
|
203
|
+
pa = Pa("/home/foo")
|
204
|
+
pa.gsub!(/o/,"")
|
205
|
+
pa.should == Pa("/hme/f")
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
describe "#match" do
|
210
|
+
it "runs ok" do
|
211
|
+
Pa("/home/foo").match(/foo/)[0].should == "foo"
|
212
|
+
end
|
213
|
+
end
|
214
|
+
|
215
|
+
describe "#start_with?" do
|
216
|
+
it "runs ok" do
|
217
|
+
Pa("/home/foo").start_with?("/home").should be_true
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
describe "#end_with?" do
|
222
|
+
it "runs ok" do
|
223
|
+
Pa("/home/foo").end_with?("foo").should be_true
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
describe "#=~" do
|
228
|
+
it "runs ok" do
|
229
|
+
(Pa("/home/foo") =~ /foo/).should be_true
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
describe "#build2" do
|
234
|
+
it "works" do
|
235
|
+
Pa.new("/home/guten.avi").build2(path: "/foo/bar.avi").should == "/foo/bar.avi"
|
236
|
+
Pa.new("/home/guten.avi").build2(dir: "foo").should == "foo/guten.avi"
|
237
|
+
Pa.new("/home/guten.avi").build2(fname: "bar").should == "/home/bar"
|
238
|
+
Pa.new("/home/guten.avi").build2(base: "bar").should == "/home/bar"
|
239
|
+
Pa.new("/home/guten.avi").build2(name: "bar").should == "/home/bar.avi"
|
240
|
+
Pa.new("/home/guten.avi").build2(ext: "ogg").should == "/home/guten.ogg"
|
241
|
+
Pa.new("/home/guten.avi").build2(fext: ".ogg").should == "/home/guten.ogg"
|
242
|
+
Pa.new("/home/guten.avi").build2(dir: "foo", name: "bar", ext: "ogg").should == "foo/bar.ogg"
|
243
|
+
end
|
244
|
+
|
245
|
+
it "percedure" do
|
246
|
+
Pa.new("/home/guten.avi").build2(path: "foo", fname: "bar").should == "foo"
|
247
|
+
Pa.new("/home/guten.avi").build2(fname: "foo", name: "bar").should == "/home/foo"
|
248
|
+
Pa.new("/home/guten.avi").build2(fname: "foo", ext: "ogg").should == "/home/foo"
|
249
|
+
Pa.new("/home/guten.avi").build2(fname: "foo", fext: ".ogg").should == "/home/foo"
|
250
|
+
Pa.new("/home/guten.avi").build2(fext: ".ogg", ext: "mp3").should == "/home/guten.ogg"
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
describe "instance DELEGATE_METHODS2" do
|
255
|
+
it "works" do
|
256
|
+
Pa.stub(:join2) { "foo" }
|
257
|
+
Pa.new("foo").join2.should == "foo"
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
describe "instance DELEGATE_METHODS" do
|
262
|
+
it "works" do
|
263
|
+
Pa.stub(:build2) { "foo" }
|
264
|
+
|
265
|
+
Pa.new("foo").build.should == Pa("foo")
|
266
|
+
end
|
267
|
+
end
|
268
|
+
|
9
269
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,3 +1,42 @@
|
|
1
1
|
require "pa"
|
2
2
|
|
3
3
|
$specdir = Pa.dir(__FILE__)
|
4
|
+
|
5
|
+
RSpec.configure do |config|
|
6
|
+
def capture(stream)
|
7
|
+
begin
|
8
|
+
stream = stream.to_s
|
9
|
+
eval "$#{stream} = StringIO.new"
|
10
|
+
yield
|
11
|
+
result = eval("$#{stream}").string
|
12
|
+
ensure
|
13
|
+
eval("$#{stream} = #{stream.upcase}")
|
14
|
+
end
|
15
|
+
|
16
|
+
result
|
17
|
+
end
|
18
|
+
|
19
|
+
alias :silence :capture
|
20
|
+
end
|
21
|
+
|
22
|
+
module Kernel
|
23
|
+
private
|
24
|
+
|
25
|
+
def xdescribe(*args, &blk)
|
26
|
+
describe *args do
|
27
|
+
pending "xxxxxxxxx"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def xcontext(*args, &blk)
|
32
|
+
context *args do
|
33
|
+
pending "xxxxxxxxx"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def xit(*args, &blk)
|
38
|
+
it *args do
|
39
|
+
pending "xxxxxxxx"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pa
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-02-02 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: ! 'a path library for Ruby
|
15
15
|
|
@@ -53,12 +53,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
53
53
|
- - ! '>='
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '0'
|
56
|
+
segments:
|
57
|
+
- 0
|
58
|
+
hash: -4359841082193627011
|
56
59
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
60
|
none: false
|
58
61
|
requirements:
|
59
62
|
- - ! '>='
|
60
63
|
- !ruby/object:Gem::Version
|
61
64
|
version: '0'
|
65
|
+
segments:
|
66
|
+
- 0
|
67
|
+
hash: -4359841082193627011
|
62
68
|
requirements: []
|
63
69
|
rubyforge_project: xx
|
64
70
|
rubygems_version: 1.8.11
|
@@ -66,3 +72,4 @@ signing_key:
|
|
66
72
|
specification_version: 3
|
67
73
|
summary: a path library for Ruby
|
68
74
|
test_files: []
|
75
|
+
has_rdoc:
|