ptools 1.3.7 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,112 @@
1
+ #####################################################################
2
+ # which_spec.rb
3
+ #
4
+ # Test case for the File.which method. You should run this test
5
+ # via 'rake spec' or 'rake spec --tag which'.
6
+ #####################################################################
7
+ require 'rspec'
8
+ require 'rbconfig'
9
+ require 'fileutils'
10
+ require 'ptools'
11
+ require 'tempfile'
12
+
13
+ describe File, :which do
14
+ before(:context) do
15
+ @windows = File::ALT_SEPARATOR
16
+ @dir = File.join(Dir.pwd, 'tempdir')
17
+ @non_exe = File.join(Dir.pwd, 'tempfile')
18
+ @ruby = RUBY_PLATFORM.match('java') ? 'jruby' : 'ruby'
19
+ @ruby = 'rbx' if defined?(Rubinius)
20
+
21
+ Dir.mkdir(@dir) unless File.exist?(@dir)
22
+ FileUtils.touch(@non_exe)
23
+ File.chmod(775, @dir)
24
+ File.chmod(644, @non_exe)
25
+
26
+ @exe = File.join(
27
+ RbConfig::CONFIG['bindir'],
28
+ RbConfig::CONFIG['ruby_install_name']
29
+ )
30
+
31
+ if @windows
32
+ @exe.tr!('/','\\')
33
+ @exe << ".exe"
34
+ end
35
+ end
36
+
37
+ example "which method basic functionality" do
38
+ expect(File).to respond_to(:which)
39
+ expect{ File.which(@ruby) }.not_to raise_error
40
+ expect(File.which(@ruby)).to be_kind_of(String)
41
+ end
42
+
43
+ example "which accepts an optional path to search" do
44
+ expect{ File.which(@ruby, "/usr/bin:/usr/local/bin") }.not_to raise_error
45
+ end
46
+
47
+ example "which returns nil if not found" do
48
+ expect(File.which(@ruby, '/bogus/path')).to be_nil
49
+ expect(File.which('blahblahblah')).to be_nil
50
+ end
51
+
52
+ example "which handles executables without extensions on windows" do
53
+ skip "skipped unless MS Windows" unless @windows
54
+ expect(File.which('ruby')).not_to be_nil
55
+ expect(File.which('notepad')).not_to be_nil
56
+ end
57
+
58
+ example "which handles executables that already contain extensions on windows" do
59
+ skip "skipped unless MS Windows" unless @windows
60
+ expect(File.which('ruby.exe')).not_to be_nil
61
+ expect(File.which('notepad.exe')).not_to be_nil
62
+ end
63
+
64
+ example "which returns argument if an existent absolute path is provided" do
65
+ expect(File.which(@ruby)).to eq(@exe), "May fail on a symlink"
66
+ end
67
+
68
+ example "which returns nil if a non-existent absolute path is provided" do
69
+ expect(File.which('/foo/bar/baz/ruby')).to be_nil
70
+ end
71
+
72
+ example "which does not pickup files that are not executable" do
73
+ expect(File.which(@non_exe)).to be_nil
74
+ end
75
+
76
+ example "which does not pickup executable directories" do
77
+ expect(File.which(@dir)).to be_nil
78
+ end
79
+
80
+ example "which accepts a minimum of one argument" do
81
+ expect{ File.which }.to raise_error(ArgumentError)
82
+ end
83
+
84
+ example "which accepts a maximum of two arguments" do
85
+ expect{ File.which(@ruby, "foo", "bar") }.to raise_error(ArgumentError)
86
+ end
87
+
88
+ example "the second argument cannot be nil or empty" do
89
+ expect{ File.which(@ruby, nil) }.to raise_error(ArgumentError)
90
+ expect{ File.which(@ruby, '') }.to raise_error(ArgumentError)
91
+ end
92
+
93
+ example "resolves with with ~" do
94
+ skip "skipped on MS Windows" if @windows
95
+ begin
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
106
+ end
107
+
108
+ after(:context) do
109
+ FileUtils.rm(@non_exe)
110
+ FileUtils.rm_rf(@dir)
111
+ end
112
+ end
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ptools
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.7
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel J. Berger
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain:
11
11
  - |
@@ -35,7 +35,7 @@ cert_chain:
35
35
  ORVCZpRuCPpmC8qmqxUnARDArzucjaclkxjLWvCVHeFa9UP7K3Nl9oTjJNv+7/jM
36
36
  WZs4eecIcUc4tKdHxcAJ0MO/Dkqq7hGaiHpwKY76wQ1+8xAh
37
37
  -----END CERTIFICATE-----
38
- date:
38
+ date: 2020-08-20 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: rake
@@ -52,19 +52,19 @@ dependencies:
52
52
  - !ruby/object:Gem::Version
53
53
  version: '0'
54
54
  - !ruby/object:Gem::Dependency
55
- name: test-unit
55
+ name: rspec
56
56
  requirement: !ruby/object:Gem::Requirement
57
57
  requirements:
58
- - - ">="
58
+ - - "~>"
59
59
  - !ruby/object:Gem::Version
60
- version: '0'
60
+ version: '3.9'
61
61
  type: :development
62
62
  prerelease: false
63
63
  version_requirements: !ruby/object:Gem::Requirement
64
64
  requirements:
65
- - - ">="
65
+ - - "~>"
66
66
  - !ruby/object:Gem::Version
67
- version: '0'
67
+ version: '3.9'
68
68
  description: |2
69
69
  The ptools (power tools) library provides several handy methods to
70
70
  Ruby's core File class, such as File.which for finding executables,
@@ -77,44 +77,38 @@ extra_rdoc_files:
77
77
  - CHANGES
78
78
  - MANIFEST
79
79
  files:
80
- - test
81
- - test/test_constants.rb
82
- - test/txt
83
- - test/txt/empty.txt
84
- - test/txt/english.utf16
85
- - test/txt/english.txt
86
- - test/txt/korean.txt
87
- - test/test_head.rb
88
- - test/test_binary.rb
89
- - test/img
90
- - test/img/test.gif
91
- - test/img/test.ico
92
- - test/img/test.jpg
93
- - test/img/test.png
94
- - test/test_image.rb
95
- - test/test_null.rb
96
- - test/test_which.rb
97
- - test/test_tail.rb
98
- - test/test_is_sparse.rb
99
- - test/test_nlconvert.rb
100
- - test/test_whereis.rb
101
- - test/test_touch.rb
102
- - test/test_wc.rb
103
80
  - CHANGES
81
+ - Gemfile
104
82
  - MANIFEST
105
83
  - README
106
- - ptools.gemspec
107
84
  - Rakefile
108
- - certs
109
85
  - certs/djberg96_pub.pem
110
- - lib
111
86
  - lib/ptools.rb
112
- - Gemfile
87
+ - ptools.gemspec
88
+ - spec/binary_spec.rb
89
+ - spec/constants_spec.rb
90
+ - spec/head_spec.rb
91
+ - spec/image_spec.rb
92
+ - spec/img/test.gif
93
+ - spec/img/test.ico
94
+ - spec/img/test.jpg
95
+ - spec/img/test.png
96
+ - spec/nlconvert_spec.rb
97
+ - spec/sparse_spec.rb
98
+ - spec/tail_spec.rb
99
+ - spec/touch_spec.rb
100
+ - spec/txt/empty.txt
101
+ - spec/txt/english.txt
102
+ - spec/txt/english.utf16
103
+ - spec/txt/korean.txt
104
+ - spec/wc_spec.rb
105
+ - spec/whereis_spec.rb
106
+ - spec/which_spec.rb
113
107
  homepage: https://github.com/djberg96/ptools
114
108
  licenses:
115
109
  - Artistic-2.0
116
110
  metadata: {}
117
- post_install_message:
111
+ post_install_message:
118
112
  rdoc_options: []
119
113
  require_paths:
120
114
  - lib
@@ -129,20 +123,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
123
  - !ruby/object:Gem::Version
130
124
  version: '0'
131
125
  requirements: []
132
- rubygems_version: 3.0.3
133
- signing_key:
126
+ rubygems_version: 3.1.4
127
+ signing_key:
134
128
  specification_version: 4
135
129
  summary: Extra methods for the File class
136
- test_files:
137
- - test/test_constants.rb
138
- - test/test_head.rb
139
- - test/test_binary.rb
140
- - test/test_image.rb
141
- - test/test_null.rb
142
- - test/test_which.rb
143
- - test/test_tail.rb
144
- - test/test_is_sparse.rb
145
- - test/test_nlconvert.rb
146
- - test/test_whereis.rb
147
- - test/test_touch.rb
148
- - test/test_wc.rb
130
+ test_files: []
metadata.gz.sig CHANGED
Binary file
@@ -1,74 +0,0 @@
1
- #####################################################################
2
- # test_binary.rb
3
- #
4
- # Test case for the File.binary? method. You should run this test
5
- # via the 'rake test_binary' task.
6
- #####################################################################
7
- require 'rubygems'
8
- require 'test-unit'
9
- require 'ptools'
10
-
11
- class TC_Ptools_Binary < Test::Unit::TestCase
12
- def self.startup
13
- if File::ALT_SEPARATOR
14
- @@bin_file = File.join(ENV['windir'], 'notepad.exe')
15
- else
16
- @@bin_file = '/bin/ls'
17
- end
18
-
19
- @@dirname = File.dirname(__FILE__)
20
- end
21
-
22
- def setup
23
- @txt_file = File.join(@@dirname, 'txt', 'english.txt')
24
- @emp_file = File.join(@@dirname, 'txt', 'empty.txt')
25
- @uni_file = File.join(@@dirname, 'txt', 'korean.txt')
26
- @utf_file = File.join(@@dirname, 'txt', 'english.utf16')
27
- @png_file = File.join(@@dirname, 'img', 'test.png')
28
- @jpg_file = File.join(@@dirname, 'img', 'test.jpg')
29
- @gif_file = File.join(@@dirname, 'img', 'test.gif')
30
- end
31
-
32
- test "File.binary? basic functionality" do
33
- assert_respond_to(File, :binary?)
34
- assert_nothing_raised{ File.binary?(@txt_file) }
35
- end
36
-
37
- test "File.binary? returns true for binary files" do
38
- assert_true(File.binary?(@@bin_file))
39
- end
40
-
41
- test "File.binary? returns false for text files" do
42
- assert_false(File.binary?(@emp_file))
43
- assert_false(File.binary?(@txt_file))
44
- assert_false(File.binary?(@uni_file))
45
- assert_false(File.binary?(@utf_file))
46
- end
47
-
48
- test "File.binary? returns false for image files" do
49
- assert_false(File.binary?(@png_file))
50
- assert_false(File.binary?(@jpg_file))
51
- assert_false(File.binary?(@gif_file))
52
- end
53
-
54
- test "File.binary? accepts an optional percentage argument" do
55
- assert_false(File.binary?(@txt_file, 0.50))
56
- assert_true(File.binary?(@txt_file, 0.05))
57
- end
58
-
59
- test "File.binary? raises an error if the file cannot be found" do
60
- assert_raise_kind_of(SystemCallError){ File.binary?('bogus') }
61
- end
62
-
63
- test "File.binary? only accepts one argument" do
64
- assert_raise_kind_of(ArgumentError){ File.binary?(@txt_file, @@bin_file) }
65
- end
66
-
67
- def teardown
68
- @txt_file = nil
69
- @uni_file = nil
70
- @png_file = nil
71
- @jpg_file = nil
72
- @gif_file = nil
73
- end
74
- end
@@ -1,39 +0,0 @@
1
- #####################################################################
2
- # test_constants.rb
3
- #
4
- # Tests the constants that have been defined for our package. This
5
- # test case should be run via the 'rake test_constants' task.
6
- #####################################################################
7
- require 'rubygems'
8
- require 'test-unit'
9
- require 'rbconfig'
10
- require 'ptools'
11
-
12
- class TC_Ptools_Constants < Test::Unit::TestCase
13
- def self.startup
14
- @@windows = File::ALT_SEPARATOR
15
- end
16
-
17
- test "PTOOLS_VERSION constant is set to expected value" do
18
- assert_equal('1.3.7', File::PTOOLS_VERSION)
19
- assert_true(File::PTOOLS_VERSION.frozen?)
20
- end
21
-
22
- test "IMAGE_EXT constant is set to array of values" do
23
- assert_equal(%w[.bmp .gif .jpeg .jpg .png], File::IMAGE_EXT.sort)
24
- end
25
-
26
- test "WINDOWS constant is defined on MS Windows" do
27
- omit_unless(@@windows, "Skipping on Unix systems")
28
- assert_not_nil(File::MSWINDOWS)
29
- end
30
-
31
- test "WIN32EXTS constant is defined on MS Windows" do
32
- omit_unless(@@windows, "Skipping on Unix systems")
33
- assert_not_nil(File::WIN32EXTS)
34
- end
35
-
36
- def self.shutdown
37
- @@windows = nil
38
- end
39
- end
@@ -1,48 +0,0 @@
1
- ######################################################################
2
- # test_head.rb
3
- #
4
- # Test case for the File.head method. This test should be run via
5
- # the 'rake test_head' task.
6
- ######################################################################
7
- require 'test-unit'
8
- require 'ptools'
9
-
10
- class TC_FileHead < Test::Unit::TestCase
11
- def self.startup
12
- Dir.chdir('test') if File.exist?('test')
13
- File.open('test_file1.txt', 'w'){ |fh| 25.times{ |n| fh.puts "line#{n+1}" } }
14
- end
15
-
16
- def setup
17
- @test_file = 'test_file1.txt'
18
- @expected_head1 = ["line1\n","line2\n","line3\n","line4\n","line5\n"]
19
- @expected_head1.push("line6\n","line7\n","line8\n","line9\n","line10\n")
20
- @expected_head2 = ["line1\n","line2\n","line3\n","line4\n","line5\n"]
21
- end
22
-
23
- def test_head_basic
24
- assert_respond_to(File, :head)
25
- assert_nothing_raised{ File.head(@test_file) }
26
- assert_nothing_raised{ File.head(@test_file, 5) }
27
- assert_nothing_raised{ File.head(@test_file){} }
28
- end
29
-
30
- def test_head_expected_results
31
- assert_kind_of(Array, File.head(@test_file))
32
- assert_equal(@expected_head1, File.head(@test_file))
33
- assert_equal(@expected_head2, File.head(@test_file, 5))
34
- end
35
-
36
- def test_head_expected_errors
37
- assert_raises(ArgumentError){ File.head(@test_file, 5, "foo") }
38
- assert_raises(Errno::ENOENT){ File.head("bogus") }
39
- end
40
-
41
- def teardown
42
- @test_file = nil
43
- end
44
-
45
- def self.shutdown
46
- File.delete('test_file1.txt') if File.exist?('test_file1.txt')
47
- end
48
- end
@@ -1,62 +0,0 @@
1
- #####################################################################
2
- # test_image.rb
3
- #
4
- # Test case for the File.image? method. You should run this test
5
- # via the 'rake test:image' task.
6
- #####################################################################
7
- require 'test-unit'
8
- require 'ptools'
9
-
10
- class TC_Ptools_Image < Test::Unit::TestCase
11
- def self.startup
12
- Dir.chdir('test') if File.exist?('test')
13
- end
14
-
15
- def setup
16
- @txt_file = File.join(Dir.pwd, 'txt', 'english.txt')
17
- @uni_file = File.join(Dir.pwd, 'txt', 'korean.txt')
18
- @jpg_file = File.join(Dir.pwd, 'img', 'test.jpg')
19
- @png_file = File.join(Dir.pwd, 'img', 'test.png')
20
- @gif_file = File.join(Dir.pwd, 'img', 'test.gif')
21
- @ico_file = File.join(Dir.pwd, 'img', 'test.ico')
22
- end
23
-
24
- test "image? method basic functionality" do
25
- assert_respond_to(File, :image?)
26
- assert_nothing_raised{ File.image?(@txt_file) }
27
- assert_boolean(File.image?(@txt_file))
28
- end
29
-
30
- test "image? method returns false for a text file" do
31
- assert_false(File.image?(@txt_file))
32
- assert_false(File.image?(@uni_file))
33
- end
34
-
35
- test "image? method returns true for a gif" do
36
- assert_true(File.image?(@gif_file))
37
- end
38
-
39
- test "image? method returns true for a jpeg" do
40
- assert_true(File.image?(@jpg_file))
41
- end
42
-
43
- test "image? method returns true for a png" do
44
- assert_true(File.image?(@png_file))
45
- end
46
-
47
- test "image? method returns true for an ico" do
48
- assert_true(File.image?(@ico_file))
49
- end
50
-
51
- test "image? method raises an error if the file does not exist" do
52
- assert_raises(Errno::ENOENT, ArgumentError){ File.image?('bogus') }
53
- end
54
-
55
- def teardown
56
- @txt_file = nil
57
- @uni_file = nil
58
- @jpg_file = nil
59
- @png_file = nil
60
- @gif_file = nil
61
- end
62
- end