ptools 1.4.2 → 1.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/CHANGES.md +5 -0
- data/MANIFEST.md +1 -0
- data/README.md +29 -24
- data/Rakefile +4 -1
- data/lib/ptools.rb +92 -119
- data/ptools.gemspec +10 -7
- data/spec/binary_spec.rb +30 -30
- data/spec/constants_spec.rb +3 -3
- data/spec/head_spec.rb +18 -18
- data/spec/image_spec.rb +163 -26
- data/spec/img/jpg_no_ext +0 -0
- data/spec/img/test.bmp +0 -0
- data/spec/img/test.tiff +0 -0
- data/spec/nlconvert_spec.rb +51 -53
- data/spec/sparse_spec.rb +17 -21
- data/spec/spec_helper.rb +7 -0
- data/spec/tail_spec.rb +55 -55
- data/spec/touch_spec.rb +22 -22
- data/spec/wc_spec.rb +28 -28
- data/spec/whereis_spec.rb +29 -30
- data/spec/which_spec.rb +52 -60
- data.tar.gz.sig +0 -0
- metadata +37 -4
- metadata.gz.sig +2 -4
data/spec/tail_spec.rb
CHANGED
@@ -8,100 +8,100 @@ require 'rspec'
|
|
8
8
|
require 'ptools'
|
9
9
|
|
10
10
|
RSpec.describe File, :tail do
|
11
|
-
let(:dirname) {
|
12
|
-
let(:test_file1) {
|
13
|
-
let(:test_file64) {
|
14
|
-
let(:test_file128) {
|
15
|
-
let(:test_file_trail) {
|
16
|
-
let(:test_file_trail_nl) {
|
11
|
+
let(:dirname) { described_class.dirname(__FILE__) }
|
12
|
+
let(:test_file1) { described_class.join(dirname, 'test_file1.txt') }
|
13
|
+
let(:test_file64) { described_class.join(dirname, 'test_file64.txt') }
|
14
|
+
let(:test_file128) { described_class.join(dirname, 'test_file128.txt') }
|
15
|
+
let(:test_file_trail) { described_class.join(dirname, 'test_file_trail.txt') }
|
16
|
+
let(:test_file_trail_nl) { described_class.join(dirname, 'test_file_trail_nl.txt') }
|
17
17
|
|
18
18
|
before do
|
19
|
-
|
19
|
+
described_class.open(test_file1, 'w'){ |fh| 25.times{ |n| fh.puts "line#{n+1}" } }
|
20
20
|
|
21
21
|
# Trailing newline test
|
22
|
-
|
22
|
+
described_class.open(test_file_trail, 'w') do |fh|
|
23
23
|
2.times{ |n| fh.puts "trail#{n+1}" }
|
24
|
-
fh.write
|
25
|
-
|
24
|
+
fh.write 'trail3'
|
25
|
+
end
|
26
26
|
|
27
|
-
|
27
|
+
described_class.open(test_file_trail_nl, 'w') do |fh|
|
28
28
|
3.times{ |n| fh.puts "trail#{n+1}" }
|
29
|
-
|
29
|
+
end
|
30
30
|
|
31
31
|
# Larger files
|
32
|
-
test_tail_fmt_str =
|
32
|
+
test_tail_fmt_str = 'line data data data data data data data %5s'
|
33
33
|
|
34
|
-
|
35
|
-
2000.times
|
34
|
+
described_class.open(test_file64, 'w') do |fh|
|
35
|
+
2000.times do |n|
|
36
36
|
fh.puts test_tail_fmt_str % (n+1).to_s
|
37
|
-
|
38
|
-
|
37
|
+
end
|
38
|
+
end
|
39
39
|
|
40
|
-
|
41
|
-
4500.times
|
40
|
+
described_class.open(test_file128, 'w') do |fh|
|
41
|
+
4500.times do |n|
|
42
42
|
fh.puts test_tail_fmt_str % (n+1).to_s
|
43
|
-
|
44
|
-
|
43
|
+
end
|
44
|
+
end
|
45
45
|
|
46
|
-
@expected_tail1 = %w
|
46
|
+
@expected_tail1 = %w[
|
47
47
|
line16 line17 line18 line19 line20
|
48
48
|
line21 line22 line23 line24 line25
|
49
|
-
|
49
|
+
]
|
50
50
|
|
51
|
-
@expected_tail2 = [
|
51
|
+
@expected_tail2 = %w[line21 line22 line23 line24 line25]
|
52
52
|
|
53
53
|
@expected_tail_more = []
|
54
54
|
25.times{ |n| @expected_tail_more.push "line#{n+1}" }
|
55
55
|
|
56
|
-
@expected_tail_trail = %w
|
56
|
+
@expected_tail_trail = %w[trail2 trail3]
|
57
57
|
|
58
|
-
@test_tail_fmt_str =
|
58
|
+
@test_tail_fmt_str = 'line data data data data data data data %5s'
|
59
59
|
end
|
60
60
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
61
|
+
after do
|
62
|
+
described_class.delete(test_file1) if described_class.exist?(test_file1)
|
63
|
+
described_class.delete(test_file64) if described_class.exist?(test_file64)
|
64
|
+
described_class.delete(test_file128) if described_class.exist?(test_file128)
|
65
|
+
described_class.delete(test_file_trail_nl) if described_class.exist?(test_file_trail_nl)
|
66
|
+
described_class.delete(test_file_trail) if described_class.exist?(test_file_trail)
|
67
|
+
end
|
68
|
+
|
69
|
+
example 'tail basic functionality' do
|
70
|
+
expect(described_class).to respond_to(:tail)
|
71
|
+
expect{ described_class.tail(test_file1) }.not_to raise_error
|
72
|
+
expect{ described_class.tail(test_file1, 5) }.not_to raise_error
|
73
|
+
expect{ described_class.tail(test_file1){} }.not_to raise_error
|
66
74
|
end
|
67
75
|
|
68
|
-
example
|
69
|
-
expect(
|
70
|
-
expect(
|
71
|
-
expect(
|
76
|
+
example 'tail returns the expected values' do
|
77
|
+
expect(described_class.tail(test_file1)).to be_kind_of(Array)
|
78
|
+
expect(described_class.tail(test_file1)).to eq(@expected_tail1)
|
79
|
+
expect(described_class.tail(test_file1, 5)).to eq(@expected_tail2)
|
72
80
|
end
|
73
81
|
|
74
|
-
example
|
75
|
-
expect(
|
82
|
+
example 'specifying a number greater than the actual number of lines works as expected' do
|
83
|
+
expect(described_class.tail(test_file1, 30)).to eq(@expected_tail_more)
|
76
84
|
end
|
77
85
|
|
78
|
-
example
|
79
|
-
expect{
|
80
|
-
expect{
|
86
|
+
example 'tail requires two arguments' do
|
87
|
+
expect{ described_class.tail }.to raise_error(ArgumentError)
|
88
|
+
expect{ described_class.tail(test_file1, 5, 5) }.to raise_error(ArgumentError)
|
81
89
|
end
|
82
90
|
|
83
|
-
example
|
84
|
-
expect(
|
85
|
-
expect(
|
91
|
+
example 'tail works as expected when there is no trailing newline' do
|
92
|
+
expect(described_class.tail(test_file_trail, 2)).to eq(@expected_tail_trail)
|
93
|
+
expect(described_class.tail(test_file_trail_nl, 2)).to eq(@expected_tail_trail)
|
86
94
|
end
|
87
95
|
|
88
|
-
example
|
96
|
+
example 'tail works as expected on a file larger than 64k' do
|
89
97
|
expected_tail_64k = []
|
90
98
|
2000.times{ |n| expected_tail_64k.push(@test_tail_fmt_str % (n+1).to_s) }
|
91
|
-
expect(
|
99
|
+
expect(described_class.tail(test_file64, 2000)).to eq(expected_tail_64k)
|
92
100
|
end
|
93
101
|
|
94
|
-
example
|
102
|
+
example 'tail works as expected on a file larger than 128k' do
|
95
103
|
expected_tail_128k = []
|
96
104
|
4500.times{ |n| expected_tail_128k.push(@test_tail_fmt_str % (n+1).to_s) }
|
97
|
-
expect(
|
98
|
-
end
|
99
|
-
|
100
|
-
after do
|
101
|
-
File.delete(test_file1) if File.exist?(test_file1)
|
102
|
-
File.delete(test_file64) if File.exist?(test_file64)
|
103
|
-
File.delete(test_file128) if File.exist?(test_file128)
|
104
|
-
File.delete(test_file_trail_nl) if File.exist?(test_file_trail_nl)
|
105
|
-
File.delete(test_file_trail) if File.exist?(test_file_trail)
|
105
|
+
expect(described_class.tail(test_file128, 4500)).to eq(expected_tail_128k)
|
106
106
|
end
|
107
107
|
end
|
data/spec/touch_spec.rb
CHANGED
@@ -8,40 +8,40 @@ require 'rspec'
|
|
8
8
|
require 'ptools'
|
9
9
|
|
10
10
|
RSpec.describe File, :touch do
|
11
|
-
let(:dirname) {
|
11
|
+
let(:dirname) { described_class.dirname(__FILE__) }
|
12
12
|
let(:filename) { 'test_file_touch.txt' }
|
13
|
-
let(:xfile) {
|
13
|
+
let(:xfile) { described_class.join(dirname, filename) }
|
14
14
|
|
15
15
|
before do
|
16
|
-
|
17
|
-
@test_file =
|
16
|
+
described_class.open(xfile, 'w'){ |fh| 10.times{ |n| fh.puts "line #{n}" } }
|
17
|
+
@test_file = described_class.join(dirname, 'delete.this')
|
18
18
|
end
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
after do
|
21
|
+
described_class.delete(@test_file) if described_class.exist?(@test_file)
|
22
|
+
described_class.delete(xfile) if described_class.exist?(xfile)
|
23
23
|
end
|
24
24
|
|
25
|
-
example
|
26
|
-
expect(
|
27
|
-
expect
|
28
|
-
expect(File.size(@test_file)).to eq(0)
|
25
|
+
example 'touch basic functionality' do
|
26
|
+
expect(described_class).to respond_to(:touch)
|
27
|
+
expect{ described_class.touch(@test_file) }.not_to raise_error
|
29
28
|
end
|
30
29
|
|
31
|
-
example
|
32
|
-
|
33
|
-
|
34
|
-
expect
|
35
|
-
expect(File.size(xfile) == stat.size).to be true
|
36
|
-
expect(File.mtime(xfile) == stat.mtime).to be false
|
30
|
+
example 'touch a new file returns expected results' do
|
31
|
+
expect(described_class.touch(@test_file)).to eq(described_class)
|
32
|
+
expect(described_class.exist?(@test_file)).to be true
|
33
|
+
expect(described_class.size(@test_file)).to eq(0)
|
37
34
|
end
|
38
35
|
|
39
|
-
example
|
40
|
-
|
36
|
+
example 'touch an existing file returns expected results' do
|
37
|
+
stat = described_class.stat(xfile)
|
38
|
+
sleep 1
|
39
|
+
expect{ described_class.touch(xfile) }.not_to raise_error
|
40
|
+
expect(described_class.size(xfile) == stat.size).to be true
|
41
|
+
expect(described_class.mtime(xfile) == stat.mtime).to be false
|
41
42
|
end
|
42
43
|
|
43
|
-
|
44
|
-
|
45
|
-
File.delete(xfile) if File.exist?(xfile)
|
44
|
+
example 'touch requires an argument' do
|
45
|
+
expect{ described_class.touch }.to raise_error(ArgumentError)
|
46
46
|
end
|
47
47
|
end
|
data/spec/wc_spec.rb
CHANGED
@@ -11,55 +11,55 @@ RSpec.describe File, :wc do
|
|
11
11
|
let(:test_file) { 'test_file_wc.txt' }
|
12
12
|
|
13
13
|
before do
|
14
|
-
|
14
|
+
described_class.open(test_file, 'w'){ |fh| 25.times{ |n| fh.puts "line#{n+1}" } }
|
15
15
|
end
|
16
16
|
|
17
|
-
|
18
|
-
|
19
|
-
expect{ File.wc(test_file) }.not_to raise_error
|
17
|
+
after do
|
18
|
+
described_class.delete(test_file) if described_class.exist?(test_file)
|
20
19
|
end
|
21
20
|
|
22
|
-
example
|
23
|
-
expect
|
24
|
-
expect{
|
25
|
-
expect{ File.wc(test_file, 'words') }.not_to raise_error
|
26
|
-
expect{ File.wc(test_file, 'lines') }.not_to raise_error
|
21
|
+
example 'wc method basic functionality' do
|
22
|
+
expect(described_class).to respond_to(:wc)
|
23
|
+
expect{ described_class.wc(test_file) }.not_to raise_error
|
27
24
|
end
|
28
25
|
|
29
|
-
example
|
30
|
-
expect{
|
26
|
+
example 'wc accepts specific optional arguments' do
|
27
|
+
expect{ described_class.wc(test_file, 'bytes') }.not_to raise_error
|
28
|
+
expect{ described_class.wc(test_file, 'chars') }.not_to raise_error
|
29
|
+
expect{ described_class.wc(test_file, 'words') }.not_to raise_error
|
30
|
+
expect{ described_class.wc(test_file, 'lines') }.not_to raise_error
|
31
31
|
end
|
32
32
|
|
33
|
-
example
|
34
|
-
expect
|
35
|
-
expect(File.wc(test_file)).to eq([166, 166, 25, 25])
|
33
|
+
example 'argument to wc ignores the case of the option argument' do
|
34
|
+
expect{ described_class.wc(test_file, 'LINES') }.not_to raise_error
|
36
35
|
end
|
37
36
|
|
38
|
-
example
|
39
|
-
expect(
|
37
|
+
example 'wc with no option returns expected results' do
|
38
|
+
expect(described_class.wc(test_file)).to be_kind_of(Array)
|
39
|
+
expect(described_class.wc(test_file)).to eq([166, 166, 25, 25])
|
40
40
|
end
|
41
41
|
|
42
|
-
example
|
43
|
-
expect(
|
42
|
+
example 'wc with bytes option returns the expected result' do
|
43
|
+
expect(described_class.wc(test_file, 'bytes')).to eq(166)
|
44
44
|
end
|
45
45
|
|
46
|
-
example
|
47
|
-
expect(
|
46
|
+
example 'wc with chars option returns the expected result' do
|
47
|
+
expect(described_class.wc(test_file, 'chars')).to eq(166)
|
48
48
|
end
|
49
49
|
|
50
|
-
example
|
51
|
-
expect(
|
50
|
+
example 'wc with words option returns the expected result' do
|
51
|
+
expect(described_class.wc(test_file, 'words')).to eq(25)
|
52
52
|
end
|
53
53
|
|
54
|
-
example
|
55
|
-
expect
|
54
|
+
example 'wc with lines option returns the expected result' do
|
55
|
+
expect(described_class.wc(test_file, 'lines')).to eq(25)
|
56
56
|
end
|
57
57
|
|
58
|
-
example
|
59
|
-
expect{
|
58
|
+
example 'wc requires at least on argument' do
|
59
|
+
expect{ described_class.wc }.to raise_error(ArgumentError)
|
60
60
|
end
|
61
61
|
|
62
|
-
|
63
|
-
|
62
|
+
example 'an invalid option raises an error' do
|
63
|
+
expect{ described_class.wc(test_file, 'bogus') }.to raise_error(ArgumentError)
|
64
64
|
end
|
65
65
|
end
|
data/spec/whereis_spec.rb
CHANGED
@@ -14,11 +14,11 @@ RSpec.describe File, :whereis do
|
|
14
14
|
let(:bin_dir) { RbConfig::CONFIG['bindir'] }
|
15
15
|
|
16
16
|
before do
|
17
|
-
@expected_locs = [
|
17
|
+
@expected_locs = [described_class.join(bin_dir, ruby)]
|
18
18
|
|
19
19
|
if windows
|
20
20
|
@expected_locs[0] << '.exe'
|
21
|
-
@expected_locs[0].tr!(
|
21
|
+
@expected_locs[0].tr!('/', '\\')
|
22
22
|
end
|
23
23
|
|
24
24
|
unless windows
|
@@ -31,57 +31,56 @@ RSpec.describe File, :whereis do
|
|
31
31
|
@actual_locs = nil
|
32
32
|
end
|
33
33
|
|
34
|
-
example
|
35
|
-
expect(
|
36
|
-
expect{
|
37
|
-
expect(
|
34
|
+
example 'whereis basic functionality' do
|
35
|
+
expect(described_class).to respond_to(:whereis)
|
36
|
+
expect{ described_class.whereis('ruby') }.not_to raise_error
|
37
|
+
expect(described_class.whereis('ruby')).to be_kind_of(Array).or be_nil
|
38
38
|
end
|
39
39
|
|
40
|
-
example
|
41
|
-
expect{
|
40
|
+
example 'whereis accepts an optional second argument' do
|
41
|
+
expect{ described_class.whereis('ruby', '/usr/bin:/usr/local/bin') }.not_to raise_error
|
42
42
|
end
|
43
43
|
|
44
|
-
example
|
45
|
-
expect{ @actual_locs =
|
44
|
+
example 'whereis returns expected values' do
|
45
|
+
expect{ @actual_locs = described_class.whereis(ruby) }.not_to raise_error
|
46
46
|
expect(@actual_locs).to be_kind_of(Array)
|
47
47
|
expect((@expected_locs & @actual_locs).size > 0).to be true
|
48
48
|
end
|
49
49
|
|
50
|
-
example
|
51
|
-
expect(
|
50
|
+
example 'whereis returns nil if program not found' do
|
51
|
+
expect(described_class.whereis('xxxyyy')).to be_nil
|
52
52
|
end
|
53
53
|
|
54
|
-
example
|
55
|
-
expect(
|
54
|
+
example 'whereis returns nil if program cannot be found in provided path' do
|
55
|
+
expect(described_class.whereis(ruby, '/foo/bar')).to be_nil
|
56
56
|
end
|
57
57
|
|
58
|
-
example
|
59
|
-
absolute =
|
58
|
+
example 'whereis returns single element array or nil if absolute path is provided' do
|
59
|
+
absolute = described_class.join(bin_dir, ruby)
|
60
60
|
absolute << '.exe' if windows
|
61
61
|
|
62
|
-
expect(
|
63
|
-
expect(
|
62
|
+
expect(described_class.whereis(absolute)).to eq([absolute])
|
63
|
+
expect(described_class.whereis("/foo/bar/baz/#{ruby}")).to be_nil
|
64
64
|
end
|
65
65
|
|
66
|
-
example
|
67
|
-
|
68
|
-
expect(File.whereis(ruby + '.exe')).not_to be_nil
|
66
|
+
example 'whereis works with an explicit extension on ms windows', :windows_only => true do
|
67
|
+
expect(described_class.whereis("#{ruby}.exe")).not_to be_nil
|
69
68
|
end
|
70
69
|
|
71
|
-
example
|
72
|
-
expect{
|
70
|
+
example 'whereis requires at least one argument' do
|
71
|
+
expect{ described_class.whereis }.to raise_error(ArgumentError)
|
73
72
|
end
|
74
73
|
|
75
|
-
example
|
76
|
-
expect(
|
74
|
+
example 'whereis returns unique paths only' do
|
75
|
+
expect(described_class.whereis(ruby) == described_class.whereis(ruby).uniq).to be true
|
77
76
|
end
|
78
77
|
|
79
|
-
example
|
80
|
-
expect{
|
78
|
+
example 'whereis accepts a maximum of two arguments' do
|
79
|
+
expect{ described_class.whereis(ruby, 'foo', 'bar') }.to raise_error(ArgumentError)
|
81
80
|
end
|
82
81
|
|
83
|
-
example
|
84
|
-
expect{
|
85
|
-
expect{
|
82
|
+
example 'the second argument to whereis cannot be nil or empty' do
|
83
|
+
expect{ described_class.whereis(ruby, nil) }.to raise_error(ArgumentError)
|
84
|
+
expect{ described_class.whereis(ruby, '') }.to raise_error(ArgumentError)
|
86
85
|
end
|
87
86
|
end
|
data/spec/which_spec.rb
CHANGED
@@ -12,101 +12,93 @@ require 'tempfile'
|
|
12
12
|
|
13
13
|
describe File, :which do
|
14
14
|
before(:context) do
|
15
|
-
@
|
16
|
-
@
|
17
|
-
@
|
18
|
-
@ruby = RUBY_PLATFORM.match('java') ? 'jruby' : 'ruby'
|
19
|
-
@ruby = 'rbx' if defined?(Rubinius)
|
15
|
+
@dir = described_class.join(Dir.pwd, 'tempdir')
|
16
|
+
@non_exe = described_class.join(Dir.pwd, 'tempfile')
|
17
|
+
@ruby = RbConfig::CONFIG['RUBY_INSTALL_NAME']
|
20
18
|
|
21
|
-
Dir.mkdir(@dir) unless
|
19
|
+
Dir.mkdir(@dir) unless described_class.exist?(@dir)
|
22
20
|
FileUtils.touch(@non_exe)
|
23
|
-
|
24
|
-
|
21
|
+
described_class.chmod(775, @dir)
|
22
|
+
described_class.chmod(644, @non_exe)
|
25
23
|
|
26
|
-
@exe =
|
24
|
+
@exe = described_class.join(
|
27
25
|
RbConfig::CONFIG['bindir'],
|
28
26
|
RbConfig::CONFIG['ruby_install_name']
|
29
27
|
)
|
30
28
|
|
31
|
-
if
|
32
|
-
@exe.tr!('/','\\')
|
33
|
-
@exe <<
|
29
|
+
if File::ALT_SEPARATOR
|
30
|
+
@exe.tr!('/', '\\')
|
31
|
+
@exe << '.exe'
|
34
32
|
end
|
35
33
|
end
|
36
34
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
expect(File.which(@ruby)).to be_kind_of(String)
|
35
|
+
after(:context) do
|
36
|
+
FileUtils.rm(@non_exe)
|
37
|
+
FileUtils.rm_rf(@dir)
|
41
38
|
end
|
42
39
|
|
43
|
-
example
|
44
|
-
expect
|
40
|
+
example 'which method basic functionality' do
|
41
|
+
expect(described_class).to respond_to(:which)
|
42
|
+
expect{ described_class.which(@ruby) }.not_to raise_error
|
43
|
+
expect(described_class.which(@ruby)).to be_kind_of(String)
|
45
44
|
end
|
46
45
|
|
47
|
-
example
|
48
|
-
expect
|
49
|
-
expect(File.which('blahblahblah')).to be_nil
|
46
|
+
example 'which accepts an optional path to search' do
|
47
|
+
expect{ described_class.which(@ruby, '/usr/bin:/usr/local/bin') }.not_to raise_error
|
50
48
|
end
|
51
49
|
|
52
|
-
example
|
53
|
-
|
54
|
-
expect(
|
55
|
-
expect(File.which('notepad')).not_to be_nil
|
50
|
+
example 'which returns nil if not found' do
|
51
|
+
expect(described_class.which(@ruby, '/bogus/path')).to be_nil
|
52
|
+
expect(described_class.which('blahblahblah')).to be_nil
|
56
53
|
end
|
57
54
|
|
58
|
-
example
|
59
|
-
|
60
|
-
expect(
|
61
|
-
expect(File.which('notepad.exe')).not_to be_nil
|
55
|
+
example 'which handles executables without extensions on windows', :windows_only => true do
|
56
|
+
expect(described_class.which('ruby')).not_to be_nil
|
57
|
+
expect(described_class.which('notepad')).not_to be_nil
|
62
58
|
end
|
63
59
|
|
64
|
-
example
|
65
|
-
expect(
|
60
|
+
example 'which handles executables that already contain extensions on windows', :windows_only => true do
|
61
|
+
expect(described_class.which('ruby.exe')).not_to be_nil
|
62
|
+
expect(described_class.which('notepad.exe')).not_to be_nil
|
66
63
|
end
|
67
64
|
|
68
|
-
example
|
69
|
-
expect(
|
65
|
+
example 'which returns argument if an existent absolute path is provided' do
|
66
|
+
expect(described_class.which(@ruby)).to eq(@exe), 'May fail on a symlink'
|
70
67
|
end
|
71
68
|
|
72
|
-
example
|
73
|
-
expect(
|
69
|
+
example 'which returns nil if a non-existent absolute path is provided' do
|
70
|
+
expect(described_class.which('/foo/bar/baz/ruby')).to be_nil
|
74
71
|
end
|
75
72
|
|
76
|
-
example
|
77
|
-
expect(
|
73
|
+
example 'which does not pickup files that are not executable' do
|
74
|
+
expect(described_class.which(@non_exe)).to be_nil
|
78
75
|
end
|
79
76
|
|
80
|
-
example
|
81
|
-
expect
|
77
|
+
example 'which does not pickup executable directories' do
|
78
|
+
expect(described_class.which(@dir)).to be_nil
|
82
79
|
end
|
83
80
|
|
84
|
-
example
|
85
|
-
expect{
|
81
|
+
example 'which accepts a minimum of one argument' do
|
82
|
+
expect{ described_class.which }.to raise_error(ArgumentError)
|
86
83
|
end
|
87
84
|
|
88
|
-
example
|
89
|
-
expect{
|
90
|
-
expect{ File.which(@ruby, '') }.to raise_error(ArgumentError)
|
85
|
+
example 'which accepts a maximum of two arguments' do
|
86
|
+
expect{ described_class.which(@ruby, 'foo', 'bar') }.to raise_error(ArgumentError)
|
91
87
|
end
|
92
88
|
|
93
|
-
example
|
94
|
-
|
95
|
-
|
96
|
-
old_home = ENV['HOME']
|
97
|
-
|
98
|
-
ENV['HOME'] = Dir::Tmpname.tmpdir
|
99
|
-
program = Tempfile.new(['program', '.sh'])
|
100
|
-
File.chmod(755, program.path)
|
101
|
-
|
102
|
-
expect(File.which(File.basename(program.path), '~/')).not_to be_nil
|
103
|
-
ensure
|
104
|
-
ENV['HOME'] = old_home
|
105
|
-
end
|
89
|
+
example 'the second argument cannot be nil or empty' do
|
90
|
+
expect{ described_class.which(@ruby, nil) }.to raise_error(ArgumentError)
|
91
|
+
expect{ described_class.which(@ruby, '') }.to raise_error(ArgumentError)
|
106
92
|
end
|
107
93
|
|
108
|
-
|
109
|
-
|
110
|
-
|
94
|
+
example 'resolves with with ~', :unix_only => true do
|
95
|
+
old_home = ENV['HOME']
|
96
|
+
ENV['HOME'] = Dir::Tmpname.tmpdir
|
97
|
+
program = Tempfile.new(['program', '.sh'])
|
98
|
+
described_class.chmod(755, program.path)
|
99
|
+
|
100
|
+
expect(described_class.which(described_class.basename(program.path), '~/')).not_to be_nil
|
101
|
+
ensure
|
102
|
+
ENV['HOME'] = old_home
|
111
103
|
end
|
112
104
|
end
|
data.tar.gz.sig
CHANGED
Binary file
|