ptools 1.3.7 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 60d8a2d183abbb54bd0140d4681625c0c6d1aec1a4f03c0de4a63ef7e6b8625e
4
- data.tar.gz: 8e850bf76e10e887dd089b15a580e63dae8b32f159a7120f4bd2a4700870101c
3
+ metadata.gz: be2c833dd51c09611f84da85481ae3b8039d427955fa951c5aab0745bef680d7
4
+ data.tar.gz: 612f6f1ab4cb5e605d9b1c18d26a9b35b95e798a9e9e11d54f539bb5ee1f1082
5
5
  SHA512:
6
- metadata.gz: 22ed87d408f7f324838f3cd6a88428e28fcc5fcba6356c9c40117ec08be5fbc1dd6f36a1da75cfea6bd4d1ebc8d51bb219a8cff0435c326e89b704552c8464e5
7
- data.tar.gz: a7a276fc8b777a95edd4ac38cc4637fcde6567f9e321f02bc2b3b094c56556034d465bc60c9f834fd696c3b0928b9c65130ce853275b6b977b4571ec95e20b38
6
+ metadata.gz: 8ec40d7c6e2d9edb2cc0e5a41a74469d7a17d208cd67d0461963488c20f97ab06b125c17903c976c6f741f93a36612ccdd63fde6c9ac0a64671340b2dbe7d78c
7
+ data.tar.gz: 7cd78b2d229c8f98a7df154275d74cb0055336bac5b40368112dd83a3cf5b8ed96c3b708b5fe5cda543a263041ab2ab44fe1a656e8be70f5d4c0c36259646bb0
Binary file
data.tar.gz.sig CHANGED
Binary file
data/CHANGES CHANGED
@@ -1,3 +1,7 @@
1
+ == 1.4.0 - 20-Aug-2020
2
+ * Switched from test-unit to rspec, and reworked the tests bit in general.
3
+ * Removed the File.null method since Ruby has IO::NULL.
4
+
1
5
  == 1.3.7 - 24-Jun-2020
2
6
  * Fixed a bug where the File.binary? method would bomb on a zero byte file.
3
7
  Thanks go to Alexandru Emil Lupu for the spot and patch.
@@ -28,8 +32,7 @@
28
32
  * The Rakefile tasks now assume Rubygems 2.x.
29
33
 
30
34
  == 1.3.2 - 11-Dec-2014
31
- * Update to the File.tail method that deals prevents potential line ending
32
- issues in JRuby.
35
+ * Update to the File.tail method that prevents potential line ending issues in JRuby.
33
36
  * Added known issues with JRuby to the README.
34
37
 
35
38
  == 1.3.1 - 9-Dec-2014
data/Gemfile CHANGED
@@ -8,5 +8,5 @@ end
8
8
 
9
9
  group :test do
10
10
  gem 'rake'
11
- gem 'test-unit'
11
+ gem 'rspec'
12
12
  end
data/MANIFEST CHANGED
@@ -6,17 +6,22 @@
6
6
  * ptools.gemspec
7
7
  * certs/djberg96_pub.pem
8
8
  * lib/ptools.rb
9
- * test/test_constants.rb
10
- * test/test_head.rb
11
- * test/test_image.rb
12
- * test/test_nlconvert.rb
13
- * test/test_null.rb
14
- * test/test_tail.rb
15
- * test/test_touch.rb
16
- * test/test_wc.rb
17
- * test/test_which.rb
18
- * test/test_whereis.rb
19
- * test/img/test.gif
20
- * test/img/test.jpg
21
- * test/img/test.png
22
- * test/img/test.ico
9
+ * spec/binary_spec.rb
10
+ * spec/constants_spec.rb
11
+ * spec/head_spec.rb
12
+ * spec/image_spec.rb
13
+ * spec/nlconvert_spec.rb
14
+ * spec/sparse_spec.rb
15
+ * spec/tail_spec.rb
16
+ * spec/touch_spec.rb
17
+ * spec/wc_spec.rb
18
+ * spec/whereis_spec.rb
19
+ * spec/which_spec.rb
20
+ * spec/img/test.gif
21
+ * spec/img/test.ico
22
+ * spec/img/test.jpg
23
+ * spec/img/test.png
24
+ * spec/txt/empty.txt
25
+ * spec/txt/english.txt
26
+ * spec/txt/english.utf16
27
+ * spec/txt/korean.txt
data/README CHANGED
@@ -53,7 +53,7 @@
53
53
  Add whatever other tools people think might be useful.
54
54
 
55
55
  == License
56
- Artistic 2.0
56
+ Artistic-2.0
57
57
 
58
58
  == Copyright
59
59
  (C) 2003-2020 Daniel J. Berger
data/Rakefile CHANGED
@@ -2,6 +2,7 @@ require 'rake'
2
2
  require 'rake/clean'
3
3
  require 'rake/testtask'
4
4
  require 'rbconfig'
5
+ require 'rspec/core/rake_task'
5
6
  include RbConfig
6
7
 
7
8
  CLEAN.include("**/*.gem", "**/*.rbc", "**/*coverage*")
@@ -19,7 +20,7 @@ namespace 'gem' do
19
20
  require 'rubygems/package'
20
21
  spec = eval(IO.read('ptools.gemspec'))
21
22
  spec.signing_key = File.join(Dir.home, '.ssh', 'gem-private_key.pem')
22
- Gem::Package.build(spec, true)
23
+ Gem::Package.build(spec)
23
24
  end
24
25
 
25
26
  desc 'Install the ptools gem'
@@ -33,103 +34,54 @@ namespace 'gem' do
33
34
  end
34
35
  end
35
36
 
36
- Rake::TestTask.new do |t|
37
- task :test => :clean
38
- t.verbose = true
39
- t.warning = true
40
- end
41
-
42
- namespace 'test' do
43
- desc "Check test coverage using rcov"
44
- task :coverage => [:clean] do
45
- require 'rcov'
46
- rm_rf 'coverage'
47
- sh "rcov -Ilib test/test*.rb"
37
+ namespace 'spec' do
38
+ RSpec::Core::RakeTask.new(:binary) do |t|
39
+ t.pattern = 'spec/binary_spec.rb'
48
40
  end
49
41
 
50
- Rake::TestTask.new('binary') do |t|
51
- t.libs << 'test'
52
- t.verbose = true
53
- t.warning = true
54
- t.test_files = FileList['test/test_binary.rb']
42
+ RSpec::Core::RakeTask.new(:constants) do |t|
43
+ t.pattern = 'spec/constants_spec.rb'
55
44
  end
56
45
 
57
- Rake::TestTask.new('constants') do |t|
58
- t.libs << 'test'
59
- t.verbose = true
60
- t.warning = true
61
- t.test_files = FileList['test/test_constants.rb']
46
+ RSpec::Core::RakeTask.new(:head) do |t|
47
+ t.pattern = 'spec/head_spec.rb'
62
48
  end
63
49
 
64
- Rake::TestTask.new('head') do |t|
65
- t.libs << 'test'
66
- t.verbose = true
67
- t.warning = true
68
- t.test_files = FileList['test/test_head.rb']
50
+ RSpec::Core::RakeTask.new(:image) do |t|
51
+ t.pattern = 'spec/image_spec.rb'
69
52
  end
70
53
 
71
- Rake::TestTask.new('image') do |t|
72
- t.libs << 'test'
73
- t.verbose = true
74
- t.warning = true
75
- t.test_files = FileList['test/test_image.rb']
54
+ RSpec::Core::RakeTask.new(:nlconvert) do |t|
55
+ t.pattern = 'spec/nlconvert_spec.rb'
76
56
  end
77
57
 
78
- Rake::TestTask.new('nlconvert') do |t|
79
- t.libs << 'test'
80
- t.verbose = true
81
- t.warning = true
82
- t.test_files = FileList['test/test_nlconvert.rb']
58
+ RSpec::Core::RakeTask.new(:sparse) do |t|
59
+ t.pattern = 'spec/sparse_spec.rb'
83
60
  end
84
61
 
85
- Rake::TestTask.new('null') do |t|
86
- t.libs << 'test'
87
- t.verbose = true
88
- t.warning = true
89
- t.test_files = FileList['test/test_null.rb']
62
+ RSpec::Core::RakeTask.new(:tail) do |t|
63
+ t.pattern = 'spec/tail_spec.rb'
90
64
  end
91
65
 
92
- Rake::TestTask.new('sparse') do |t|
93
- t.libs << 'test'
94
- t.verbose = true
95
- t.warning = true
96
- t.test_files = FileList['test/test_is_sparse.rb']
66
+ RSpec::Core::RakeTask.new(:touch) do |t|
67
+ t.pattern = 'spec/touch_spec.rb'
97
68
  end
98
69
 
99
- Rake::TestTask.new('tail') do |t|
100
- t.libs << 'test'
101
- t.verbose = true
102
- t.warning = true
103
- t.test_files = FileList['test/test_tail.rb']
70
+ RSpec::Core::RakeTask.new(:wc) do |t|
71
+ t.pattern = 'spec/wc_spec.rb'
104
72
  end
105
-
106
- Rake::TestTask.new('touch') do |t|
107
- t.libs << 'test'
108
- t.verbose = true
109
- t.warning = true
110
- t.test_files = FileList['test/test_touch.rb']
111
- end
112
-
113
- Rake::TestTask.new('wc') do |t|
114
- t.libs << 'test'
115
- t.verbose = true
116
- t.warning = true
117
- t.test_files = FileList['test/test_wc.rb']
73
+
74
+ RSpec::Core::RakeTask.new(:whereis) do |t|
75
+ t.pattern = 'spec/whereis_spec.rb'
118
76
  end
119
77
 
120
- Rake::TestTask.new('whereis') do |t|
121
- t.libs << 'test'
122
- t.verbose = true
123
- t.warning = true
124
- t.test_files = FileList['test/test_whereis.rb']
78
+ RSpec::Core::RakeTask.new(:which) do |t|
79
+ t.pattern = 'spec/which_spec.rb'
125
80
  end
126
81
 
127
- Rake::TestTask.new('which') do |t|
128
- t.libs << 'test'
129
- t.verbose = true
130
- t.warning = true
131
- t.test_files = FileList['test/test_which.rb']
82
+ RSpec::Core::RakeTask.new(:all) do |t|
83
+ t.pattern = 'spec/*_spec.rb'
132
84
  end
133
85
  end
134
86
 
135
- task :default => :test
87
+ task :default => 'spec:all'
@@ -3,7 +3,7 @@ require 'win32/file' if File::ALT_SEPARATOR
3
3
 
4
4
  class File
5
5
  # The version of the ptools library.
6
- PTOOLS_VERSION = '1.3.7'.freeze
6
+ PTOOLS_VERSION = '1.4.0'.freeze
7
7
 
8
8
  # :stopdoc:
9
9
 
@@ -44,36 +44,6 @@ class File
44
44
  bool
45
45
  end
46
46
 
47
- # Returns the name of the null device (aka bitbucket) on your platform.
48
- #
49
- # Examples:
50
- #
51
- # # On Linux
52
- # File.null # => '/dev/null'
53
- #
54
- # # On MS Windows
55
- # File.null # => 'NUL'
56
- #--
57
- # The values I used here are based on information from
58
- # http://en.wikipedia.org/wiki//dev/null
59
- #
60
- def self.null
61
- case RbConfig::CONFIG['host_os']
62
- when /mswin|win32|msdos|mingw|windows/i
63
- 'NUL'
64
- when /amiga/i
65
- 'NIL:'
66
- when /openvms/i
67
- 'NL:'
68
- else
69
- '/dev/null'
70
- end
71
- end
72
-
73
- class << self
74
- alias null_device null
75
- end
76
-
77
47
  # Returns whether or not +file+ is a binary non-image file, i.e. executable,
78
48
  # shared object, ect. Note that this is NOT guaranteed to be 100% accurate.
79
49
  # It performs a "best guess" based on a simple test of the first
@@ -2,13 +2,13 @@ require 'rbconfig'
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'ptools'
5
- spec.version = '1.3.7'
5
+ spec.version = '1.4.0'
6
6
  spec.license = 'Artistic-2.0'
7
7
  spec.author = 'Daniel J. Berger'
8
8
  spec.email = 'djberg96@gmail.com'
9
9
  spec.homepage = 'https://github.com/djberg96/ptools'
10
10
  spec.summary = 'Extra methods for the File class'
11
- spec.test_files = Dir['test/test*']
11
+ spec.test_files = Dir['spec/_spec*']
12
12
  spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
13
13
  spec.cert_chain = ['certs/djberg96_pub.pem']
14
14
 
@@ -21,7 +21,7 @@ Gem::Specification.new do |spec|
21
21
  EOF
22
22
 
23
23
  spec.add_development_dependency('rake')
24
- spec.add_development_dependency('test-unit')
24
+ spec.add_development_dependency('rspec', '~> 3.9')
25
25
 
26
26
  if File::ALT_SEPARATOR
27
27
  spec.platform = Gem::Platform.new(['universal', 'mingw32'])
@@ -0,0 +1,59 @@
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 'rspec'
9
+ require 'ptools'
10
+
11
+ RSpec.describe File, :binary do
12
+ let(:dirname) { File.dirname(__FILE__) }
13
+ let(:bin_file) { File::ALT_SEPARATOR ? File.join(ENV['windir'], 'notepad.exe') : '/bin/ls' }
14
+
15
+ before do
16
+ @txt_file = File.join(dirname, 'txt', 'english.txt')
17
+ @emp_file = File.join(dirname, 'txt', 'empty.txt')
18
+ @uni_file = File.join(dirname, 'txt', 'korean.txt')
19
+ @utf_file = File.join(dirname, 'txt', 'english.utf16')
20
+ @png_file = File.join(dirname, 'img', 'test.png')
21
+ @jpg_file = File.join(dirname, 'img', 'test.jpg')
22
+ @gif_file = File.join(dirname, 'img', 'test.gif')
23
+ end
24
+
25
+ example "File.binary? basic functionality" do
26
+ expect(File).to respond_to(:binary?)
27
+ expect{ File.binary?(@txt_file) }.not_to raise_error
28
+ end
29
+
30
+ example "File.binary? returns true for binary files" do
31
+ expect(File.binary?(bin_file)).to be true
32
+ end
33
+
34
+ example "File.binary? returns false for text files" do
35
+ expect(File.binary?(@emp_file)).to be false
36
+ expect(File.binary?(@txt_file)).to be false
37
+ expect(File.binary?(@uni_file)).to be false
38
+ expect(File.binary?(@utf_file)).to be false
39
+ end
40
+
41
+ example "File.binary? returns false for image files" do
42
+ expect(File.binary?(@png_file)).to be false
43
+ expect(File.binary?(@jpg_file)).to be false
44
+ expect(File.binary?(@gif_file)).to be false
45
+ end
46
+
47
+ example "File.binary? accepts an optional percentage argument" do
48
+ expect(File.binary?(@txt_file, 0.50)).to be false
49
+ expect(File.binary?(@txt_file, 0.05)).to be true
50
+ end
51
+
52
+ example "File.binary? raises an error if the file cannot be found" do
53
+ expect{ File.binary?('bogus') }.to raise_error(SystemCallError)
54
+ end
55
+
56
+ example "File.binary? only accepts one argument" do
57
+ expect{ File.binary?(@txt_file, bin_file) }.to raise_error(ArgumentError)
58
+ end
59
+ end
@@ -0,0 +1,33 @@
1
+ ##############################################################################
2
+ # constants_spec.rb
3
+ #
4
+ # Specs for the constants that have been defined in the ptools library.
5
+ # This test case should be run via the 'rake spec:constants' task.
6
+ ##############################################################################
7
+ require 'rubygems'
8
+ require 'rspec'
9
+ require 'rbconfig'
10
+ require 'ptools'
11
+
12
+ RSpec.describe File, :constants do
13
+ let(:windows) { File::ALT_SEPARATOR }
14
+
15
+ example "PTOOLS_VERSION constant is set to expected value" do
16
+ expect(File::PTOOLS_VERSION).to eq('1.4.0')
17
+ expect(File::PTOOLS_VERSION.frozen?).to be true
18
+ end
19
+
20
+ example "IMAGE_EXT constant is set to array of values" do
21
+ expect(File::IMAGE_EXT.sort).to eq(%w[.bmp .gif .jpeg .jpg .png])
22
+ end
23
+
24
+ example "WINDOWS constant is defined on MS Windows" do
25
+ skip "skipped unless MS Windows" unless windows
26
+ expect(File::MSWINDOWS).not_to be_nil
27
+ end
28
+
29
+ example "WIN32EXTS constant is defined on MS Windows" do
30
+ skip "skipped unless MS Windows" unless windows
31
+ expect(File::WIN32EXTS).not_to be_nil
32
+ end
33
+ end
@@ -0,0 +1,41 @@
1
+ ######################################################################
2
+ # head_spec.rb
3
+ #
4
+ # Specs for the File.head method. These specs should be run via
5
+ # the 'rake spec:head' task.
6
+ ######################################################################
7
+ require 'rspec'
8
+ require 'ptools'
9
+
10
+ RSpec.describe File, :head do
11
+ let(:test_file) { 'test_file_head.txt' }
12
+
13
+ before do
14
+ File.open(test_file, 'w'){ |fh| 25.times{ |n| fh.puts "line#{n+1}" } }
15
+ @expected_head1 = ["line1\n","line2\n","line3\n","line4\n","line5\n"]
16
+ @expected_head1.push("line6\n","line7\n","line8\n","line9\n","line10\n")
17
+ @expected_head2 = ["line1\n","line2\n","line3\n","line4\n","line5\n"]
18
+ end
19
+
20
+ example "head method basic functionality" do
21
+ expect(File).to respond_to(:head)
22
+ expect{ File.head(test_file) }.not_to raise_error
23
+ expect{ File.head(test_file, 5) }.not_to raise_error
24
+ expect{ File.head(test_file){} }.not_to raise_error
25
+ end
26
+
27
+ example "head method returns the expected results" do
28
+ expect(File.head(test_file)).to be_kind_of(Array)
29
+ expect(File.head(test_file)).to eq(@expected_head1)
30
+ expect(File.head(test_file, 5)).to eq(@expected_head2)
31
+ end
32
+
33
+ example "head method requires two arguments" do
34
+ expect{ File.head(test_file, 5, "foo") }.to raise_error(ArgumentError)
35
+ expect{ File.head("bogus") }.to raise_error(Errno::ENOENT)
36
+ end
37
+
38
+ after do
39
+ File.delete(test_file) if File.exists?(test_file)
40
+ end
41
+ end
@@ -0,0 +1,51 @@
1
+ #####################################################################
2
+ # image_spec.rb
3
+ #
4
+ # Specs for the File.image? method. You should run these specs via
5
+ # the 'rake spec:image' task.
6
+ #####################################################################
7
+ require 'rspec'
8
+ require 'ptools'
9
+
10
+ RSpec.describe File, :image do
11
+ before do
12
+ Dir.chdir('spec') if File.exist?('spec')
13
+ @txt_file = File.join(Dir.pwd, 'txt', 'english.txt')
14
+ @uni_file = File.join(Dir.pwd, 'txt', 'korean.txt')
15
+ @jpg_file = File.join(Dir.pwd, 'img', 'test.jpg')
16
+ @png_file = File.join(Dir.pwd, 'img', 'test.png')
17
+ @gif_file = File.join(Dir.pwd, 'img', 'test.gif')
18
+ @ico_file = File.join(Dir.pwd, 'img', 'test.ico')
19
+ end
20
+
21
+ example "image? method basic functionality" do
22
+ expect(File).to respond_to(:image?)
23
+ expect{ File.image?(@txt_file) }.not_to raise_error
24
+ expect(File.image?(@txt_file)).to be(true).or be(false)
25
+ end
26
+
27
+ example "image? method returns false for a text file" do
28
+ expect(File.image?(@txt_file)).to be false
29
+ expect(File.image?(@uni_file)).to be false
30
+ end
31
+
32
+ example "image? method returns true for a gif" do
33
+ expect(File.image?(@gif_file)).to be true
34
+ end
35
+
36
+ example "image? method returns true for a jpeg" do
37
+ expect(File.image?(@jpg_file)).to be true
38
+ end
39
+
40
+ example "image? method returns true for a png" do
41
+ expect(File.image?(@png_file)).to be true
42
+ end
43
+
44
+ example "image? method returns true for an ico" do
45
+ expect(File.image?(@ico_file)).to be true
46
+ end
47
+
48
+ example "image? method raises an error if the file does not exist" do
49
+ expect{ File.image?('bogus') }.to raise_error(Exception) # Errno::ENOENT or ArgumentError
50
+ end
51
+ end