/
spec.test_whichr.rb
executable file
·77 lines (61 loc) · 1.68 KB
/
spec.test_whichr.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
require File.dirname(__FILE__) + '/../lib/whichr'
require 'spec/autorun'
require 'fileutils'
describe RubyWhich do
it "should have working __DIR__" do
__DIR__.should_not == nil
end
before do
ENV['PATH'] = 'test'
FileUtils.rm_rf 'test'
Dir.mkdir 'test'
@a = RubyWhich.new
FileUtils.touch 'test/abc.bat'
end
it "should not show duplicates with different cased drive letters" do
path = File.expand_path 'test'
ENV['PATH'] = path.upcase + ';' + path.downcase
outs = @a.which 'abc'
assert outs.length == 1
end
it "should not show non execs" do
FileUtils.rm 'test/abc.bat' # clean it up
FileUtils.touch 'test/abc'
File.chmod 0777, 'test/abc'
outs = @a.which('abc')
assert outs.length == 0
FileUtils.touch 'test/abc.bat'
outs = @a.which('abc')
assert outs.length == 1
end
it "should show non execs if you want it to" do
FileUtils.rm 'test/abc.bat' # clean it up
FileUtils.touch 'test/abc'
File.chmod 0777, 'test/abc'
outs = @a.which('abc', true)
assert outs.length == 1
end
it "should only give uniq k?" do
ENV['PATH'] = 'test' + File::PATH_SEPARATOR + 'test'
FileUtils.touch 'test/abc.bat'
outs = @a.which('abc')
assert outs.length == 1
end
it "should give you cwd if on doze" do
Dir.chdir 'test' do
outs = @a.which('abc')
if RUBY_PLATFORM =~ /mingw|mswin/
assert outs.length == 1
else
# LTODO
assert outs.length == 0
end
end
end
it "should not be ugly" do
outs = @a.which('abc')
assert !outs[0].include?('abc.BAT')
# should not have /'s on doze
assert !outs[0].include?('/')
end
end