ptools 1.3.3 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,47 @@
1
+ #####################################################################
2
+ # test_touch.rb
3
+ #
4
+ # Test case for the File.touch method. This test should be run
5
+ # via the 'rake test_touch task'.
6
+ #####################################################################
7
+ require 'rspec'
8
+ require 'ptools'
9
+
10
+ RSpec.describe File, :touch do
11
+ let(:dirname) { File.dirname(__FILE__) }
12
+ let(:filename) { 'test_file_touch.txt' }
13
+ let(:xfile) { File.join(dirname, filename) }
14
+
15
+ before do
16
+ File.open(xfile, 'w'){ |fh| 10.times{ |n| fh.puts "line #{n}" } }
17
+ @test_file = File.join(dirname, 'delete.this')
18
+ end
19
+
20
+ example "touch basic functionality" do
21
+ expect(File).to respond_to(:touch)
22
+ expect{ File.touch(@test_file) }.not_to raise_error
23
+ end
24
+
25
+ example "touch a new file returns expected results" do
26
+ expect(File.touch(@test_file)).to eq(File)
27
+ expect(File.exist?(@test_file)).to be true
28
+ expect(File.size(@test_file)).to eq(0)
29
+ end
30
+
31
+ example "touch an existing file returns expected results" do
32
+ stat = File.stat(xfile)
33
+ sleep 0.5
34
+ expect{ File.touch(xfile) }.not_to raise_error
35
+ expect(File.size(xfile) == stat.size).to be true
36
+ expect(File.mtime(xfile) == stat.mtime).to be false
37
+ end
38
+
39
+ example "touch requires an argument" do
40
+ expect{ File.touch }.to raise_error(ArgumentError)
41
+ end
42
+
43
+ after do
44
+ File.delete(@test_file) if File.exist?(@test_file)
45
+ File.delete(xfile) if File.exist?(xfile)
46
+ end
47
+ end
File without changes
File without changes
Binary file
File without changes
@@ -0,0 +1,65 @@
1
+ #####################################################################
2
+ # wc_spec.rb
3
+ #
4
+ # Specs for the File.wc method. These specs should be run via
5
+ # the 'rake wc' task.
6
+ #####################################################################
7
+ require 'rspec'
8
+ require 'ptools'
9
+
10
+ RSpec.describe File, :wc do
11
+ let(:test_file) { 'test_file_wc.txt' }
12
+
13
+ before do
14
+ File.open(test_file, 'w'){ |fh| 25.times{ |n| fh.puts "line#{n+1}" } }
15
+ end
16
+
17
+ example "wc method basic functionality" do
18
+ expect(File).to respond_to(:wc)
19
+ expect{ File.wc(test_file) }.not_to raise_error
20
+ end
21
+
22
+ example "wc accepts specific optional arguments" do
23
+ expect{ File.wc(test_file, 'bytes') }.not_to raise_error
24
+ expect{ File.wc(test_file, 'chars') }.not_to raise_error
25
+ expect{ File.wc(test_file, 'words') }.not_to raise_error
26
+ expect{ File.wc(test_file, 'lines') }.not_to raise_error
27
+ end
28
+
29
+ example "argument to wc ignores the case of the option argument" do
30
+ expect{ File.wc(test_file, 'LINES') }.not_to raise_error
31
+ end
32
+
33
+ example "wc with no option returns expected results" do
34
+ expect(File.wc(test_file)).to be_kind_of(Array)
35
+ expect(File.wc(test_file)).to eq([166, 166, 25, 25])
36
+ end
37
+
38
+ example "wc with bytes option returns the expected result" do
39
+ expect(File.wc(test_file, 'bytes')).to eq(166)
40
+ end
41
+
42
+ example "wc with chars option returns the expected result" do
43
+ expect(File.wc(test_file, 'chars')).to eq(166)
44
+ end
45
+
46
+ example "wc with words option returns the expected result" do
47
+ expect(File.wc(test_file, 'words')).to eq(25)
48
+ end
49
+
50
+ example "wc with lines option returns the expected result" do
51
+ expect(File.wc(test_file, 'lines')).to eq(25)
52
+ end
53
+
54
+ example "wc requires at least on argument" do
55
+ expect{ File.wc }.to raise_error(ArgumentError)
56
+ end
57
+
58
+ example "an invalid option raises an error" do
59
+ expect{ File.wc(test_file, 'bogus') }.to raise_error(ArgumentError)
60
+ end
61
+
62
+ after do
63
+ File.delete(test_file) if File.exists?(test_file)
64
+ end
65
+ end
@@ -0,0 +1,87 @@
1
+ ######################################################################
2
+ # test_whereis.rb
3
+ #
4
+ # Tests for the File.whereis method.
5
+ ######################################################################
6
+ require 'rubygems'
7
+ require 'rspec'
8
+ require 'ptools'
9
+ require 'rbconfig'
10
+
11
+ RSpec.describe File, :whereis do
12
+ let(:windows) { File::ALT_SEPARATOR }
13
+ let(:ruby) { RUBY_ENGINE }
14
+ let(:bin_dir) { RbConfig::CONFIG['bindir'] }
15
+
16
+ before do
17
+ @expected_locs = [File.join(bin_dir, ruby)]
18
+
19
+ if windows
20
+ @expected_locs[0] << '.exe'
21
+ @expected_locs[0].tr!("/", "\\")
22
+ end
23
+
24
+ unless windows
25
+ @expected_locs << "/usr/local/bin/#{ruby}"
26
+ @expected_locs << "/opt/sfw/bin/#{ruby}"
27
+ @expected_locs << "/opt/bin/#{ruby}"
28
+ @expected_locs << "/usr/bin/#{ruby}"
29
+ end
30
+
31
+ @actual_locs = nil
32
+ end
33
+
34
+ example "whereis basic functionality" do
35
+ expect(File).to respond_to(:whereis)
36
+ expect{ File.whereis('ruby') }.not_to raise_error
37
+ expect(File.whereis('ruby')).to be_kind_of(Array).or be_nil
38
+ end
39
+
40
+ example "whereis accepts an optional second argument" do
41
+ expect{ File.whereis('ruby', '/usr/bin:/usr/local/bin') }.not_to raise_error
42
+ end
43
+
44
+ example "whereis returns expected values" do
45
+ expect{ @actual_locs = File.whereis(ruby) }.not_to raise_error
46
+ expect(@actual_locs).to be_kind_of(Array)
47
+ expect((@expected_locs & @actual_locs).size > 0).to be true
48
+ end
49
+
50
+ example "whereis returns nil if program not found" do
51
+ expect(File.whereis('xxxyyy')).to be_nil
52
+ end
53
+
54
+ example "whereis returns nil if program cannot be found in provided path" do
55
+ expect(File.whereis(ruby, '/foo/bar')).to be_nil
56
+ end
57
+
58
+ example "whereis returns single element array or nil if absolute path is provided" do
59
+ absolute = File.join(bin_dir, ruby)
60
+ absolute << '.exe' if windows
61
+
62
+ expect(File.whereis(absolute)).to eq([absolute])
63
+ expect(File.whereis("/foo/bar/baz/#{ruby}")).to be_nil
64
+ end
65
+
66
+ example "whereis works with an explicit extension on ms windows" do
67
+ skip "skipped unless MS Windows" unless windows
68
+ expect(File.whereis(ruby + '.exe')).not_to be_nil
69
+ end
70
+
71
+ example "whereis requires at least one argument" do
72
+ expect{ File.whereis }.to raise_error(ArgumentError)
73
+ end
74
+
75
+ example "whereis returns unique paths only" do
76
+ expect(File.whereis(ruby) == File.whereis(ruby).uniq).to be true
77
+ end
78
+
79
+ example "whereis accepts a maximum of two arguments" do
80
+ expect{ File.whereis(ruby, 'foo', 'bar') }.to raise_error(ArgumentError)
81
+ end
82
+
83
+ example "the second argument to whereis cannot be nil or empty" do
84
+ expect{ File.whereis(ruby, nil) }.to raise_error(ArgumentError)
85
+ expect{ File.whereis(ruby, '') }.to raise_error(ArgumentError)
86
+ end
87
+ end
@@ -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,36 +1,41 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ptools
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.3
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
  - |
12
12
  -----BEGIN CERTIFICATE-----
13
- MIIDcDCCAligAwIBAgIBATANBgkqhkiG9w0BAQUFADA/MREwDwYDVQQDDAhkamJl
13
+ MIIEcDCCAtigAwIBAgIBATANBgkqhkiG9w0BAQsFADA/MREwDwYDVQQDDAhkamJl
14
14
  cmc5NjEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYKCZImiZPyLGQBGRYDY29t
15
- MB4XDTE1MDkwMjIwNDkxOFoXDTE2MDkwMTIwNDkxOFowPzERMA8GA1UEAwwIZGpi
15
+ MB4XDTE4MDMxODE1MjIwN1oXDTI4MDMxNTE1MjIwN1owPzERMA8GA1UEAwwIZGpi
16
16
  ZXJnOTYxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixkARkWA2Nv
17
- bTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAMyTkvXqRp6hLs9eoJOS
18
- Hmi8kRYbq9Vkf15/hMxJpotYMgJVHHWrmDcC5Dye2PbnXjTkKf266Zw0PtT9h+lI
19
- S3ts9HO+vaCFSMwFFZmnWJSpQ3CNw2RcHxjWkk9yF7imEM8Kz9ojhiDXzBetdV6M
20
- gr0lV/alUr7TNVBDngbXEfTWscyXh1qd7xZ4EcOdsDktCe5G45N/o3662tPQvJsi
21
- FOF0CM/KuBsa/HL1/eoEmF4B3EKIRfTHrQ3hu20Kv3RJ88QM4ec2+0dd97uX693O
22
- zv6981fyEg+aXLkxrkViM/tz2qR2ZE0jPhHTREPYeMEgptRkTmWSKAuLVWrJEfgl
23
- DtkCAwEAAaN3MHUwCQYDVR0TBAI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vQWW7E/Y3ijliWJS1GQFq
25
+ 058qERadHGu1yu1dojmFRo6W2KZvY9al2yIlbkpDrD5MYQIDAQABo3cwdTAJBgNV
26
+ HRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQUFZsMapgzJimzsbaBG2Tm8j5e
27
+ AzgwHQYDVR0RBBYwFIESZGpiZXJnOTZAZ21haWwuY29tMB0GA1UdEgQWMBSBEmRq
28
+ YmVyZzk2QGdtYWlsLmNvbTANBgkqhkiG9w0BAQsFAAOCAYEAW2tnYixXQtKxgGXq
29
+ /3iSWG2bLwvxS4go3srO+aRXZHrFUMlJ5W0mCxl03aazxxKTsVVpZD8QZxvK91OQ
30
+ h9zr9JBYqCLcCVbr8SkmYCi/laxIZxsNE5YI8cC8vvlLI7AMgSfPSnn/Epq1GjGY
31
+ 6L1iRcEDtanGCIvjqlCXO9+BmsnCfEVehqZkQHeYczA03tpOWb6pon2wzvMKSsKH
32
+ ks0ApVdstSLz1kzzAqem/uHdG9FyXdbTAwH1G4ZPv69sQAFAOCgAqYmdnzedsQtE
33
+ 1LQfaQrx0twO+CZJPcRLEESjq8ScQxWRRkfuh2VeR7cEU7L7KqT10mtUwrvw7APf
34
+ DYoeCY9KyjIBjQXfbj2ke5u1hZj94Fsq9FfbEQg8ygCgwThnmkTrrKEiMSs3alYR
35
+ ORVCZpRuCPpmC8qmqxUnARDArzucjaclkxjLWvCVHeFa9UP7K3Nl9oTjJNv+7/jM
36
+ WZs4eecIcUc4tKdHxcAJ0MO/Dkqq7hGaiHpwKY76wQ1+8xAh
32
37
  -----END CERTIFICATE-----
33
- date: 2015-09-25 00:00:00.000000000 Z
38
+ date: 2020-08-20 00:00:00.000000000 Z
34
39
  dependencies:
35
40
  - !ruby/object:Gem::Dependency
36
41
  name: rake
@@ -47,19 +52,19 @@ dependencies:
47
52
  - !ruby/object:Gem::Version
48
53
  version: '0'
49
54
  - !ruby/object:Gem::Dependency
50
- name: test-unit
55
+ name: rspec
51
56
  requirement: !ruby/object:Gem::Requirement
52
57
  requirements:
53
- - - ">="
58
+ - - "~>"
54
59
  - !ruby/object:Gem::Version
55
- version: 2.5.0
60
+ version: '3.9'
56
61
  type: :development
57
62
  prerelease: false
58
63
  version_requirements: !ruby/object:Gem::Requirement
59
64
  requirements:
60
- - - ">="
65
+ - - "~>"
61
66
  - !ruby/object:Gem::Version
62
- version: 2.5.0
67
+ version: '3.9'
63
68
  description: |2
64
69
  The ptools (power tools) library provides several handy methods to
65
70
  Ruby's core File class, such as File.which for finding executables,
@@ -72,7 +77,6 @@ extra_rdoc_files:
72
77
  - CHANGES
73
78
  - MANIFEST
74
79
  files:
75
- - ".gemtest"
76
80
  - CHANGES
77
81
  - Gemfile
78
82
  - MANIFEST
@@ -81,28 +85,30 @@ files:
81
85
  - certs/djberg96_pub.pem
82
86
  - lib/ptools.rb
83
87
  - ptools.gemspec
84
- - test/img/test.gif
85
- - test/img/test.jpg
86
- - test/img/test.png
87
- - test/test_binary.rb
88
- - test/test_constants.rb
89
- - test/test_head.rb
90
- - test/test_image.rb
91
- - test/test_is_sparse.rb
92
- - test/test_nlconvert.rb
93
- - test/test_null.rb
94
- - test/test_tail.rb
95
- - test/test_touch.rb
96
- - test/test_wc.rb
97
- - test/test_whereis.rb
98
- - test/test_which.rb
99
- - test/txt/english.txt
100
- - test/txt/korean.txt
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
101
107
  homepage: https://github.com/djberg96/ptools
102
108
  licenses:
103
- - Artistic 2.0
109
+ - Artistic-2.0
104
110
  metadata: {}
105
- post_install_message:
111
+ post_install_message:
106
112
  rdoc_options: []
107
113
  require_paths:
108
114
  - lib
@@ -117,21 +123,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
123
  - !ruby/object:Gem::Version
118
124
  version: '0'
119
125
  requirements: []
120
- rubyforge_project:
121
- rubygems_version: 2.4.5
122
- signing_key:
126
+ rubygems_version: 3.1.4
127
+ signing_key:
123
128
  specification_version: 4
124
129
  summary: Extra methods for the File class
125
- test_files:
126
- - test/test_binary.rb
127
- - test/test_constants.rb
128
- - test/test_head.rb
129
- - test/test_image.rb
130
- - test/test_is_sparse.rb
131
- - test/test_nlconvert.rb
132
- - test/test_null.rb
133
- - test/test_tail.rb
134
- - test/test_touch.rb
135
- - test/test_wc.rb
136
- - test/test_whereis.rb
137
- - test/test_which.rb
130
+ test_files: []