ptools 1.4.2 → 1.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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/binary_spec.rb
    CHANGED
    
    | 
         @@ -9,51 +9,51 @@ require 'rspec' 
     | 
|
| 
       9 
9 
     | 
    
         
             
            require 'ptools'
         
     | 
| 
       10 
10 
     | 
    
         | 
| 
       11 
11 
     | 
    
         
             
            RSpec.describe File, :binary do
         
     | 
| 
       12 
     | 
    
         
            -
              let(:dirname)  {  
     | 
| 
       13 
     | 
    
         
            -
              let(:bin_file) { File::ALT_SEPARATOR ?  
     | 
| 
      
 12 
     | 
    
         
            +
              let(:dirname)  { described_class.dirname(__FILE__) }
         
     | 
| 
      
 13 
     | 
    
         
            +
              let(:bin_file) { File::ALT_SEPARATOR ? described_class.join(ENV['windir'], 'notepad.exe') : '/bin/ls' }
         
     | 
| 
       14 
14 
     | 
    
         | 
| 
       15 
15 
     | 
    
         
             
              before do
         
     | 
| 
       16 
     | 
    
         
            -
                @txt_file =  
     | 
| 
       17 
     | 
    
         
            -
                @emp_file =  
     | 
| 
       18 
     | 
    
         
            -
                @uni_file =  
     | 
| 
       19 
     | 
    
         
            -
                @utf_file =  
     | 
| 
       20 
     | 
    
         
            -
                @png_file =  
     | 
| 
       21 
     | 
    
         
            -
                @jpg_file =  
     | 
| 
       22 
     | 
    
         
            -
                @gif_file =  
     | 
| 
      
 16 
     | 
    
         
            +
                @txt_file = described_class.join(dirname, 'txt', 'english.txt')
         
     | 
| 
      
 17 
     | 
    
         
            +
                @emp_file = described_class.join(dirname, 'txt', 'empty.txt')
         
     | 
| 
      
 18 
     | 
    
         
            +
                @uni_file = described_class.join(dirname, 'txt', 'korean.txt')
         
     | 
| 
      
 19 
     | 
    
         
            +
                @utf_file = described_class.join(dirname, 'txt', 'english.utf16')
         
     | 
| 
      
 20 
     | 
    
         
            +
                @png_file = described_class.join(dirname, 'img', 'test.png')
         
     | 
| 
      
 21 
     | 
    
         
            +
                @jpg_file = described_class.join(dirname, 'img', 'test.jpg')
         
     | 
| 
      
 22 
     | 
    
         
            +
                @gif_file = described_class.join(dirname, 'img', 'test.gif')
         
     | 
| 
       23 
23 
     | 
    
         
             
              end
         
     | 
| 
       24 
24 
     | 
    
         | 
| 
       25 
     | 
    
         
            -
              example  
     | 
| 
       26 
     | 
    
         
            -
                expect( 
     | 
| 
       27 
     | 
    
         
            -
                expect{  
     | 
| 
      
 25 
     | 
    
         
            +
              example 'File.binary? basic functionality' do
         
     | 
| 
      
 26 
     | 
    
         
            +
                expect(described_class).to respond_to(:binary?)
         
     | 
| 
      
 27 
     | 
    
         
            +
                expect{ described_class.binary?(@txt_file) }.not_to raise_error
         
     | 
| 
       28 
28 
     | 
    
         
             
              end
         
     | 
| 
       29 
29 
     | 
    
         | 
| 
       30 
     | 
    
         
            -
              example  
     | 
| 
       31 
     | 
    
         
            -
                expect( 
     | 
| 
      
 30 
     | 
    
         
            +
              example 'File.binary? returns true for binary files' do
         
     | 
| 
      
 31 
     | 
    
         
            +
                expect(described_class.binary?(bin_file)).to be true
         
     | 
| 
       32 
32 
     | 
    
         
             
              end
         
     | 
| 
       33 
33 
     | 
    
         | 
| 
       34 
     | 
    
         
            -
              example  
     | 
| 
       35 
     | 
    
         
            -
                expect( 
     | 
| 
       36 
     | 
    
         
            -
                expect( 
     | 
| 
       37 
     | 
    
         
            -
                expect( 
     | 
| 
       38 
     | 
    
         
            -
                expect( 
     | 
| 
      
 34 
     | 
    
         
            +
              example 'File.binary? returns false for text files' do
         
     | 
| 
      
 35 
     | 
    
         
            +
                expect(described_class.binary?(@emp_file)).to be false
         
     | 
| 
      
 36 
     | 
    
         
            +
                expect(described_class.binary?(@txt_file)).to be false
         
     | 
| 
      
 37 
     | 
    
         
            +
                expect(described_class.binary?(@uni_file)).to be false
         
     | 
| 
      
 38 
     | 
    
         
            +
                expect(described_class.binary?(@utf_file)).to be false
         
     | 
| 
       39 
39 
     | 
    
         
             
              end
         
     | 
| 
       40 
40 
     | 
    
         | 
| 
       41 
     | 
    
         
            -
              example  
     | 
| 
       42 
     | 
    
         
            -
                expect( 
     | 
| 
       43 
     | 
    
         
            -
                expect( 
     | 
| 
       44 
     | 
    
         
            -
                expect( 
     | 
| 
      
 41 
     | 
    
         
            +
              example 'File.binary? returns false for image files' do
         
     | 
| 
      
 42 
     | 
    
         
            +
                expect(described_class.binary?(@png_file)).to be false
         
     | 
| 
      
 43 
     | 
    
         
            +
                expect(described_class.binary?(@jpg_file)).to be false
         
     | 
| 
      
 44 
     | 
    
         
            +
                expect(described_class.binary?(@gif_file)).to be false
         
     | 
| 
       45 
45 
     | 
    
         
             
              end
         
     | 
| 
       46 
46 
     | 
    
         | 
| 
       47 
     | 
    
         
            -
              example  
     | 
| 
       48 
     | 
    
         
            -
                expect( 
     | 
| 
       49 
     | 
    
         
            -
                expect( 
     | 
| 
      
 47 
     | 
    
         
            +
              example 'File.binary? accepts an optional percentage argument' do
         
     | 
| 
      
 48 
     | 
    
         
            +
                expect(described_class.binary?(@txt_file, 0.50)).to be false
         
     | 
| 
      
 49 
     | 
    
         
            +
                expect(described_class.binary?(@txt_file, 0.05)).to be true
         
     | 
| 
       50 
50 
     | 
    
         
             
              end
         
     | 
| 
       51 
51 
     | 
    
         | 
| 
       52 
     | 
    
         
            -
              example  
     | 
| 
       53 
     | 
    
         
            -
                expect{  
     | 
| 
      
 52 
     | 
    
         
            +
              example 'File.binary? raises an error if the file cannot be found' do
         
     | 
| 
      
 53 
     | 
    
         
            +
                expect{ described_class.binary?('bogus') }.to raise_error(SystemCallError)
         
     | 
| 
       54 
54 
     | 
    
         
             
              end
         
     | 
| 
       55 
55 
     | 
    
         | 
| 
       56 
     | 
    
         
            -
              example  
     | 
| 
       57 
     | 
    
         
            -
                expect{  
     | 
| 
      
 56 
     | 
    
         
            +
              example 'File.binary? only accepts one argument' do
         
     | 
| 
      
 57 
     | 
    
         
            +
                expect{ described_class.binary?(@txt_file, bin_file) }.to raise_error(ArgumentError)
         
     | 
| 
       58 
58 
     | 
    
         
             
              end
         
     | 
| 
       59 
59 
     | 
    
         
             
            end
         
     | 
    
        data/spec/constants_spec.rb
    CHANGED
    
    | 
         @@ -12,12 +12,12 @@ require 'ptools' 
     | 
|
| 
       12 
12 
     | 
    
         
             
            RSpec.describe File, :constants do
         
     | 
| 
       13 
13 
     | 
    
         
             
              let(:windows) { File::ALT_SEPARATOR }
         
     | 
| 
       14 
14 
     | 
    
         | 
| 
       15 
     | 
    
         
            -
              example  
     | 
| 
       16 
     | 
    
         
            -
                expect(File::PTOOLS_VERSION).to eq('1.4. 
     | 
| 
      
 15 
     | 
    
         
            +
              example 'PTOOLS_VERSION constant is set to expected value' do
         
     | 
| 
      
 16 
     | 
    
         
            +
                expect(File::PTOOLS_VERSION).to eq('1.4.3')
         
     | 
| 
       17 
17 
     | 
    
         
             
                expect(File::PTOOLS_VERSION.frozen?).to be true
         
     | 
| 
       18 
18 
     | 
    
         
             
              end
         
     | 
| 
       19 
19 
     | 
    
         | 
| 
       20 
     | 
    
         
            -
              example  
     | 
| 
      
 20 
     | 
    
         
            +
              example 'IMAGE_EXT constant is set to array of values' do
         
     | 
| 
       21 
21 
     | 
    
         
             
                expect(File::IMAGE_EXT).to match_array(%w[.bmp .gif .ico .jpeg .jpg .png])
         
     | 
| 
       22 
22 
     | 
    
         
             
              end
         
     | 
| 
       23 
23 
     | 
    
         
             
            end
         
     | 
    
        data/spec/head_spec.rb
    CHANGED
    
    | 
         @@ -11,31 +11,31 @@ RSpec.describe File, :head do 
     | 
|
| 
       11 
11 
     | 
    
         
             
              let(:test_file) { 'test_file_head.txt' }
         
     | 
| 
       12 
12 
     | 
    
         | 
| 
       13 
13 
     | 
    
         
             
              before do
         
     | 
| 
       14 
     | 
    
         
            -
                 
     | 
| 
       15 
     | 
    
         
            -
                @expected_head1 = [ 
     | 
| 
       16 
     | 
    
         
            -
                @expected_head1.push("line6\n","line7\n","line8\n","line9\n","line10\n")
         
     | 
| 
       17 
     | 
    
         
            -
                @expected_head2 = [ 
     | 
| 
      
 14 
     | 
    
         
            +
                described_class.open(test_file, 'w'){ |fh| 25.times{ |n| fh.puts "line#{n+1}" } }
         
     | 
| 
      
 15 
     | 
    
         
            +
                @expected_head1 = %W[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 = %W[line1\n line2\n line3\n line4\n line5\n]
         
     | 
| 
       18 
18 
     | 
    
         
             
              end
         
     | 
| 
       19 
19 
     | 
    
         | 
| 
       20 
     | 
    
         
            -
               
     | 
| 
       21 
     | 
    
         
            -
                 
     | 
| 
       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
         
     | 
| 
      
 20 
     | 
    
         
            +
              after do
         
     | 
| 
      
 21 
     | 
    
         
            +
                described_class.delete(test_file) if described_class.exist?(test_file)
         
     | 
| 
       25 
22 
     | 
    
         
             
              end
         
     | 
| 
       26 
23 
     | 
    
         | 
| 
       27 
     | 
    
         
            -
              example  
     | 
| 
       28 
     | 
    
         
            -
                expect( 
     | 
| 
       29 
     | 
    
         
            -
                expect 
     | 
| 
       30 
     | 
    
         
            -
                expect 
     | 
| 
      
 24 
     | 
    
         
            +
              example 'head method basic functionality' do
         
     | 
| 
      
 25 
     | 
    
         
            +
                expect(described_class).to respond_to(:head)
         
     | 
| 
      
 26 
     | 
    
         
            +
                expect{ described_class.head(test_file) }.not_to raise_error
         
     | 
| 
      
 27 
     | 
    
         
            +
                expect{ described_class.head(test_file, 5) }.not_to raise_error
         
     | 
| 
      
 28 
     | 
    
         
            +
                expect{ described_class.head(test_file){} }.not_to raise_error
         
     | 
| 
       31 
29 
     | 
    
         
             
              end
         
     | 
| 
       32 
30 
     | 
    
         | 
| 
       33 
     | 
    
         
            -
              example  
     | 
| 
       34 
     | 
    
         
            -
                expect 
     | 
| 
       35 
     | 
    
         
            -
                expect 
     | 
| 
      
 31 
     | 
    
         
            +
              example 'head method returns the expected results' do
         
     | 
| 
      
 32 
     | 
    
         
            +
                expect(described_class.head(test_file)).to be_kind_of(Array)
         
     | 
| 
      
 33 
     | 
    
         
            +
                expect(described_class.head(test_file)).to eq(@expected_head1)
         
     | 
| 
      
 34 
     | 
    
         
            +
                expect(described_class.head(test_file, 5)).to eq(@expected_head2)
         
     | 
| 
       36 
35 
     | 
    
         
             
              end
         
     | 
| 
       37 
36 
     | 
    
         | 
| 
       38 
     | 
    
         
            -
               
     | 
| 
       39 
     | 
    
         
            -
                 
     | 
| 
      
 37 
     | 
    
         
            +
              example 'head method requires two arguments' do
         
     | 
| 
      
 38 
     | 
    
         
            +
                expect{ described_class.head(test_file, 5, 'foo') }.to raise_error(ArgumentError)
         
     | 
| 
      
 39 
     | 
    
         
            +
                expect{ described_class.head('bogus') }.to raise_error(Errno::ENOENT)
         
     | 
| 
       40 
40 
     | 
    
         
             
              end
         
     | 
| 
       41 
41 
     | 
    
         
             
            end
         
     | 
    
        data/spec/image_spec.rb
    CHANGED
    
    | 
         @@ -1,51 +1,188 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            #####################################################################
         
     | 
| 
       2 
2 
     | 
    
         
             
            # image_spec.rb
         
     | 
| 
       3 
3 
     | 
    
         
             
            #
         
     | 
| 
       4 
     | 
    
         
            -
            # Specs for  
     | 
| 
       5 
     | 
    
         
            -
            # the 'rake spec:image' task.
         
     | 
| 
      
 4 
     | 
    
         
            +
            # Specs for various image methods as well as the File.image? method
         
     | 
| 
      
 5 
     | 
    
         
            +
            # itself. You should run these specs via the 'rake spec:image' task.
         
     | 
| 
       6 
6 
     | 
    
         
             
            #####################################################################
         
     | 
| 
       7 
7 
     | 
    
         
             
            require 'rspec'
         
     | 
| 
       8 
8 
     | 
    
         
             
            require 'ptools'
         
     | 
| 
       9 
9 
     | 
    
         | 
| 
       10 
10 
     | 
    
         
             
            RSpec.describe File, :image do
         
     | 
| 
       11 
11 
     | 
    
         
             
              before do
         
     | 
| 
       12 
     | 
    
         
            -
                Dir.chdir('spec') if  
     | 
| 
       13 
     | 
    
         
            -
                @txt_file  =  
     | 
| 
       14 
     | 
    
         
            -
                @uni_file  =  
     | 
| 
       15 
     | 
    
         
            -
                @jpg_file  =  
     | 
| 
       16 
     | 
    
         
            -
                @png_file  =  
     | 
| 
       17 
     | 
    
         
            -
                @gif_file  =  
     | 
| 
       18 
     | 
    
         
            -
                @ 
     | 
| 
      
 12 
     | 
    
         
            +
                Dir.chdir('spec') if described_class.exist?('spec')
         
     | 
| 
      
 13 
     | 
    
         
            +
                @txt_file  = described_class.join(Dir.pwd, 'txt', 'english.txt')
         
     | 
| 
      
 14 
     | 
    
         
            +
                @uni_file  = described_class.join(Dir.pwd, 'txt', 'korean.txt')
         
     | 
| 
      
 15 
     | 
    
         
            +
                @jpg_file  = described_class.join(Dir.pwd, 'img', 'test.jpg')
         
     | 
| 
      
 16 
     | 
    
         
            +
                @png_file  = described_class.join(Dir.pwd, 'img', 'test.png')
         
     | 
| 
      
 17 
     | 
    
         
            +
                @gif_file  = described_class.join(Dir.pwd, 'img', 'test.gif')
         
     | 
| 
      
 18 
     | 
    
         
            +
                @tif_file  = described_class.join(Dir.pwd, 'img', 'test.tiff')
         
     | 
| 
      
 19 
     | 
    
         
            +
                @ico_file  = described_class.join(Dir.pwd, 'img', 'test.ico')
         
     | 
| 
      
 20 
     | 
    
         
            +
                @no_ext    = described_class.join(Dir.pwd, 'img', 'jpg_no_ext')
         
     | 
| 
      
 21 
     | 
    
         
            +
                @bmp_file  = described_class.join(Dir.pwd, 'img', 'test.bmp')
         
     | 
| 
       19 
22 
     | 
    
         
             
              end
         
     | 
| 
       20 
23 
     | 
    
         | 
| 
       21 
     | 
    
         
            -
               
     | 
| 
       22 
     | 
    
         
            -
                 
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
      
 24 
     | 
    
         
            +
              context 'bmp?' do
         
     | 
| 
      
 25 
     | 
    
         
            +
                example 'bmp? method basic functionality' do
         
     | 
| 
      
 26 
     | 
    
         
            +
                  described_class.bmp?(@bmp_file)
         
     | 
| 
      
 27 
     | 
    
         
            +
                  expect(described_class).to respond_to(:bmp?)
         
     | 
| 
      
 28 
     | 
    
         
            +
                  expect{ described_class.bmp?(@bmp_file) }.not_to raise_error
         
     | 
| 
      
 29 
     | 
    
         
            +
                  expect(described_class.bmp?(@bmp_file)).to be(true).or be(false)
         
     | 
| 
      
 30 
     | 
    
         
            +
                end
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
                example 'bmp? method returns true for a bitmap file' do
         
     | 
| 
      
 33 
     | 
    
         
            +
                  expect(described_class.bmp?(@bmp_file)).to be(true)
         
     | 
| 
      
 34 
     | 
    
         
            +
                end
         
     | 
| 
      
 35 
     | 
    
         
            +
             
     | 
| 
      
 36 
     | 
    
         
            +
                example 'bmp? method returns false for an image that is not a bitmap' do
         
     | 
| 
      
 37 
     | 
    
         
            +
                  expect(described_class.bmp?(@gif_file)).to be(false)
         
     | 
| 
      
 38 
     | 
    
         
            +
                  expect(described_class.bmp?(@tif_file)).to be(false)
         
     | 
| 
      
 39 
     | 
    
         
            +
                end
         
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
      
 41 
     | 
    
         
            +
                example 'bmp? method returns false for a text file' do
         
     | 
| 
      
 42 
     | 
    
         
            +
                  expect(described_class.bmp?(@txt_file)).to be(false)
         
     | 
| 
      
 43 
     | 
    
         
            +
                end
         
     | 
| 
       25 
44 
     | 
    
         
             
              end
         
     | 
| 
       26 
45 
     | 
    
         | 
| 
       27 
     | 
    
         
            -
               
     | 
| 
       28 
     | 
    
         
            -
                 
     | 
| 
       29 
     | 
    
         
            -
             
     | 
| 
      
 46 
     | 
    
         
            +
              context 'gif?' do
         
     | 
| 
      
 47 
     | 
    
         
            +
                example 'gif? method basic functionality' do
         
     | 
| 
      
 48 
     | 
    
         
            +
                  expect(described_class).to respond_to(:gif?)
         
     | 
| 
      
 49 
     | 
    
         
            +
                  expect{ described_class.gif?(@gif_file) }.not_to raise_error
         
     | 
| 
      
 50 
     | 
    
         
            +
                  expect(described_class.gif?(@gif_file)).to be(true).or be(false)
         
     | 
| 
      
 51 
     | 
    
         
            +
                end
         
     | 
| 
      
 52 
     | 
    
         
            +
             
     | 
| 
      
 53 
     | 
    
         
            +
                example 'gif? method returns true for a gif file' do
         
     | 
| 
      
 54 
     | 
    
         
            +
                  expect(described_class.gif?(@gif_file)).to be(true)
         
     | 
| 
      
 55 
     | 
    
         
            +
                end
         
     | 
| 
      
 56 
     | 
    
         
            +
             
     | 
| 
      
 57 
     | 
    
         
            +
                example 'gif? method returns false for an image that is not a gif' do
         
     | 
| 
      
 58 
     | 
    
         
            +
                  expect(described_class.gif?(@jpg_file)).to be(false)
         
     | 
| 
      
 59 
     | 
    
         
            +
                end
         
     | 
| 
      
 60 
     | 
    
         
            +
             
     | 
| 
      
 61 
     | 
    
         
            +
                example 'gif? method returns false for a text file' do
         
     | 
| 
      
 62 
     | 
    
         
            +
                  expect(described_class.gif?(@txt_file)).to be(false)
         
     | 
| 
      
 63 
     | 
    
         
            +
                end
         
     | 
| 
       30 
64 
     | 
    
         
             
              end
         
     | 
| 
       31 
65 
     | 
    
         | 
| 
       32 
     | 
    
         
            -
               
     | 
| 
       33 
     | 
    
         
            -
                 
     | 
| 
      
 66 
     | 
    
         
            +
              context 'ico?' do
         
     | 
| 
      
 67 
     | 
    
         
            +
                example 'ico? method basic functionality' do
         
     | 
| 
      
 68 
     | 
    
         
            +
                  expect(described_class).to respond_to(:ico?)
         
     | 
| 
      
 69 
     | 
    
         
            +
                  expect{ described_class.ico?(@ico_file) }.not_to raise_error
         
     | 
| 
      
 70 
     | 
    
         
            +
                  expect(described_class.ico?(@ico_file)).to be(true).or be(false)
         
     | 
| 
      
 71 
     | 
    
         
            +
                end
         
     | 
| 
      
 72 
     | 
    
         
            +
             
     | 
| 
      
 73 
     | 
    
         
            +
                example 'ico? method returns true for an icon file' do
         
     | 
| 
      
 74 
     | 
    
         
            +
                  expect(described_class.ico?(@ico_file)).to be(true)
         
     | 
| 
      
 75 
     | 
    
         
            +
                end
         
     | 
| 
      
 76 
     | 
    
         
            +
             
     | 
| 
      
 77 
     | 
    
         
            +
                example 'ico? method returns false for an image that is not a icon file' do
         
     | 
| 
      
 78 
     | 
    
         
            +
                  expect(described_class.ico?(@gif_file)).to be(false)
         
     | 
| 
      
 79 
     | 
    
         
            +
                  expect(described_class.ico?(@png_file)).to be(false)
         
     | 
| 
      
 80 
     | 
    
         
            +
                end
         
     | 
| 
      
 81 
     | 
    
         
            +
             
     | 
| 
      
 82 
     | 
    
         
            +
                example 'ico? method returns false for a text file' do
         
     | 
| 
      
 83 
     | 
    
         
            +
                  expect(described_class.ico?(@txt_file)).to be(false)
         
     | 
| 
      
 84 
     | 
    
         
            +
                end
         
     | 
| 
       34 
85 
     | 
    
         
             
              end
         
     | 
| 
       35 
86 
     | 
    
         | 
| 
       36 
     | 
    
         
            -
               
     | 
| 
       37 
     | 
    
         
            -
                 
     | 
| 
      
 87 
     | 
    
         
            +
              context 'image?' do
         
     | 
| 
      
 88 
     | 
    
         
            +
                example 'image? method basic functionality' do
         
     | 
| 
      
 89 
     | 
    
         
            +
                  expect(described_class).to respond_to(:image?)
         
     | 
| 
      
 90 
     | 
    
         
            +
                  expect{ described_class.image?(@txt_file) }.not_to raise_error
         
     | 
| 
      
 91 
     | 
    
         
            +
                  expect(described_class.image?(@txt_file)).to be(true).or be(false)
         
     | 
| 
      
 92 
     | 
    
         
            +
                end
         
     | 
| 
      
 93 
     | 
    
         
            +
             
     | 
| 
      
 94 
     | 
    
         
            +
                example 'image? method returns false for a text file' do
         
     | 
| 
      
 95 
     | 
    
         
            +
                  expect(described_class.image?(@txt_file)).to be false
         
     | 
| 
      
 96 
     | 
    
         
            +
                  expect(described_class.image?(@uni_file)).to be false
         
     | 
| 
      
 97 
     | 
    
         
            +
                end
         
     | 
| 
      
 98 
     | 
    
         
            +
             
     | 
| 
      
 99 
     | 
    
         
            +
                example 'image? method returns true for a gif' do
         
     | 
| 
      
 100 
     | 
    
         
            +
                  expect(described_class.image?(@gif_file)).to be true
         
     | 
| 
      
 101 
     | 
    
         
            +
                  expect(described_class.image?(@gif_file, check_file_extension: false)).to be true
         
     | 
| 
      
 102 
     | 
    
         
            +
                end
         
     | 
| 
      
 103 
     | 
    
         
            +
             
     | 
| 
      
 104 
     | 
    
         
            +
                example 'image? method returns true for a jpeg' do
         
     | 
| 
      
 105 
     | 
    
         
            +
                  expect(described_class.image?(@jpg_file)).to be true
         
     | 
| 
      
 106 
     | 
    
         
            +
                  expect(described_class.image?(@jpg_file, check_file_extension: false)).to be true
         
     | 
| 
      
 107 
     | 
    
         
            +
                end
         
     | 
| 
      
 108 
     | 
    
         
            +
             
     | 
| 
      
 109 
     | 
    
         
            +
                example 'image? method returns true for a png' do
         
     | 
| 
      
 110 
     | 
    
         
            +
                  expect(described_class.image?(@png_file)).to be true
         
     | 
| 
      
 111 
     | 
    
         
            +
                  expect(described_class.image?(@png_file, check_file_extension: false)).to be true
         
     | 
| 
      
 112 
     | 
    
         
            +
                end
         
     | 
| 
      
 113 
     | 
    
         
            +
             
     | 
| 
      
 114 
     | 
    
         
            +
                example 'image? method returns true for an ico' do
         
     | 
| 
      
 115 
     | 
    
         
            +
                  expect(described_class.image?(@ico_file)).to be true
         
     | 
| 
      
 116 
     | 
    
         
            +
                  expect(described_class.image?(@ico_file, check_file_extension: false)).to be true
         
     | 
| 
      
 117 
     | 
    
         
            +
                end
         
     | 
| 
      
 118 
     | 
    
         
            +
             
     | 
| 
      
 119 
     | 
    
         
            +
                example 'image? method raises an error if the file does not exist' do
         
     | 
| 
      
 120 
     | 
    
         
            +
                  expect{ described_class.image?('bogus') }.to raise_error(Exception) # Errno::ENOENT or ArgumentError
         
     | 
| 
      
 121 
     | 
    
         
            +
                end
         
     | 
| 
      
 122 
     | 
    
         
            +
             
     | 
| 
      
 123 
     | 
    
         
            +
                example "image? returns appropriate value if the extension isn't included" do
         
     | 
| 
      
 124 
     | 
    
         
            +
                  expect(described_class.image?(@no_ext, check_file_extension: true)).to be false
         
     | 
| 
      
 125 
     | 
    
         
            +
                  expect(described_class.image?(@no_ext, check_file_extension: false)).to be true
         
     | 
| 
      
 126 
     | 
    
         
            +
                end
         
     | 
| 
       38 
127 
     | 
    
         
             
              end
         
     | 
| 
       39 
128 
     | 
    
         | 
| 
       40 
     | 
    
         
            -
               
     | 
| 
       41 
     | 
    
         
            -
                 
     | 
| 
      
 129 
     | 
    
         
            +
              context 'jpg?' do
         
     | 
| 
      
 130 
     | 
    
         
            +
                example 'jpg? method basic functionality' do
         
     | 
| 
      
 131 
     | 
    
         
            +
                  expect(described_class).to respond_to(:jpg?)
         
     | 
| 
      
 132 
     | 
    
         
            +
                  expect{ described_class.jpg?(@jpg_file) }.not_to raise_error
         
     | 
| 
      
 133 
     | 
    
         
            +
                  expect(described_class.jpg?(@jpg_file)).to be(true).or be(false)
         
     | 
| 
      
 134 
     | 
    
         
            +
                end
         
     | 
| 
      
 135 
     | 
    
         
            +
             
     | 
| 
      
 136 
     | 
    
         
            +
                example 'jpg? method returns true for a jpeg file' do
         
     | 
| 
      
 137 
     | 
    
         
            +
                  expect(described_class.jpg?(@jpg_file)).to be(true)
         
     | 
| 
      
 138 
     | 
    
         
            +
                end
         
     | 
| 
      
 139 
     | 
    
         
            +
             
     | 
| 
      
 140 
     | 
    
         
            +
                example 'jpg? method returns false for an image that is not a jpeg' do
         
     | 
| 
      
 141 
     | 
    
         
            +
                  expect(described_class.jpg?(@gif_file)).to be(false)
         
     | 
| 
      
 142 
     | 
    
         
            +
                end
         
     | 
| 
      
 143 
     | 
    
         
            +
             
     | 
| 
      
 144 
     | 
    
         
            +
                example 'jpg? method returns false for a text file' do
         
     | 
| 
      
 145 
     | 
    
         
            +
                  expect(described_class.jpg?(@txt_file)).to be(false)
         
     | 
| 
      
 146 
     | 
    
         
            +
                end
         
     | 
| 
       42 
147 
     | 
    
         
             
              end
         
     | 
| 
       43 
148 
     | 
    
         | 
| 
       44 
     | 
    
         
            -
               
     | 
| 
       45 
     | 
    
         
            -
                 
     | 
| 
      
 149 
     | 
    
         
            +
              context 'png?' do
         
     | 
| 
      
 150 
     | 
    
         
            +
                example 'png? method basic functionality' do
         
     | 
| 
      
 151 
     | 
    
         
            +
                  expect(described_class).to respond_to(:png?)
         
     | 
| 
      
 152 
     | 
    
         
            +
                  expect{ described_class.png?(@png_file) }.not_to raise_error
         
     | 
| 
      
 153 
     | 
    
         
            +
                  expect(described_class.png?(@png_file)).to be(true).or be(false)
         
     | 
| 
      
 154 
     | 
    
         
            +
                end
         
     | 
| 
      
 155 
     | 
    
         
            +
             
     | 
| 
      
 156 
     | 
    
         
            +
                example 'png? method returns true for a png file' do
         
     | 
| 
      
 157 
     | 
    
         
            +
                  expect(described_class.png?(@png_file)).to be(true)
         
     | 
| 
      
 158 
     | 
    
         
            +
                end
         
     | 
| 
      
 159 
     | 
    
         
            +
             
     | 
| 
      
 160 
     | 
    
         
            +
                example 'png? method returns false for an image that is not a png' do
         
     | 
| 
      
 161 
     | 
    
         
            +
                  expect(described_class.png?(@gif_file)).to be(false)
         
     | 
| 
      
 162 
     | 
    
         
            +
                end
         
     | 
| 
      
 163 
     | 
    
         
            +
             
     | 
| 
      
 164 
     | 
    
         
            +
                example 'png? method returns false for a text file' do
         
     | 
| 
      
 165 
     | 
    
         
            +
                  expect(described_class.png?(@txt_file)).to be(false)
         
     | 
| 
      
 166 
     | 
    
         
            +
                end
         
     | 
| 
       46 
167 
     | 
    
         
             
              end
         
     | 
| 
       47 
168 
     | 
    
         | 
| 
       48 
     | 
    
         
            -
               
     | 
| 
       49 
     | 
    
         
            -
                 
     | 
| 
      
 169 
     | 
    
         
            +
              context 'tiff?' do
         
     | 
| 
      
 170 
     | 
    
         
            +
                example 'tiff? method basic functionality' do
         
     | 
| 
      
 171 
     | 
    
         
            +
                  expect(described_class).to respond_to(:tiff?)
         
     | 
| 
      
 172 
     | 
    
         
            +
                  expect{ described_class.tiff?(@tif_file) }.not_to raise_error
         
     | 
| 
      
 173 
     | 
    
         
            +
                  expect(described_class.tiff?(@tif_file)).to be(true).or be(false)
         
     | 
| 
      
 174 
     | 
    
         
            +
                end
         
     | 
| 
      
 175 
     | 
    
         
            +
             
     | 
| 
      
 176 
     | 
    
         
            +
                example 'tiff? method returns true for a tiff file' do
         
     | 
| 
      
 177 
     | 
    
         
            +
                  expect(described_class.tiff?(@tif_file)).to be(true)
         
     | 
| 
      
 178 
     | 
    
         
            +
                end
         
     | 
| 
      
 179 
     | 
    
         
            +
             
     | 
| 
      
 180 
     | 
    
         
            +
                example 'tiff? method returns false for an image that is not a tiff' do
         
     | 
| 
      
 181 
     | 
    
         
            +
                  expect(described_class.tiff?(@jpg_file)).to be(false)
         
     | 
| 
      
 182 
     | 
    
         
            +
                end
         
     | 
| 
      
 183 
     | 
    
         
            +
             
     | 
| 
      
 184 
     | 
    
         
            +
                example 'tiff? method returns false for a text file' do
         
     | 
| 
      
 185 
     | 
    
         
            +
                  expect(described_class.tiff?(@txt_file)).to be(false)
         
     | 
| 
      
 186 
     | 
    
         
            +
                end
         
     | 
| 
       50 
187 
     | 
    
         
             
              end
         
     | 
| 
       51 
188 
     | 
    
         
             
            end
         
     | 
    
        data/spec/img/jpg_no_ext
    ADDED
    
    | 
         Binary file 
     | 
    
        data/spec/img/test.bmp
    ADDED
    
    | 
         Binary file 
     | 
    
        data/spec/img/test.tiff
    ADDED
    
    | 
         Binary file 
     | 
    
        data/spec/nlconvert_spec.rb
    CHANGED
    
    | 
         @@ -10,95 +10,93 @@ require 'ptools' 
     | 
|
| 
       10 
10 
     | 
    
         | 
| 
       11 
11 
     | 
    
         
             
            RSpec.describe File, :nlconvert do
         
     | 
| 
       12 
12 
     | 
    
         
             
              let(:windows)    { File::ALT_SEPARATOR }
         
     | 
| 
       13 
     | 
    
         
            -
              let(:dirname)    {  
     | 
| 
       14 
     | 
    
         
            -
              let(:test_file1) {  
     | 
| 
       15 
     | 
    
         
            -
              let(:test_file2) {  
     | 
| 
      
 13 
     | 
    
         
            +
              let(:dirname)    { described_class.dirname(__FILE__) }
         
     | 
| 
      
 14 
     | 
    
         
            +
              let(:test_file1) { described_class.join(dirname, 'test_nl_convert1.txt') }
         
     | 
| 
      
 15 
     | 
    
         
            +
              let(:test_file2) { described_class.join(dirname, 'test_nl_convert2.txt') }
         
     | 
| 
       16 
16 
     | 
    
         | 
| 
       17 
17 
     | 
    
         
             
              before do
         
     | 
| 
       18 
     | 
    
         
            -
                 
     | 
| 
       19 
     | 
    
         
            -
                 
     | 
| 
       20 
     | 
    
         
            -
                @test_file1 =  
     | 
| 
       21 
     | 
    
         
            -
                @test_file2 =  
     | 
| 
       22 
     | 
    
         
            -
                @dos_file   =  
     | 
| 
       23 
     | 
    
         
            -
                @mac_file   =  
     | 
| 
      
 18 
     | 
    
         
            +
                described_class.open(test_file1, 'w'){ |fh| 10.times{ |n| fh.puts "line #{n}" } }
         
     | 
| 
      
 19 
     | 
    
         
            +
                described_class.open(test_file2, 'w'){ |fh| 10.times{ |n| fh.puts "line #{n}" } }
         
     | 
| 
      
 20 
     | 
    
         
            +
                @test_file1 = described_class.join(dirname, 'test_nl_convert1.txt')
         
     | 
| 
      
 21 
     | 
    
         
            +
                @test_file2 = described_class.join(dirname, 'test_nl_convert2.txt')
         
     | 
| 
      
 22 
     | 
    
         
            +
                @dos_file   = described_class.join(dirname, 'dos_test_file.txt')
         
     | 
| 
      
 23 
     | 
    
         
            +
                @mac_file   = described_class.join(dirname, 'mac_test_file.txt')
         
     | 
| 
       24 
24 
     | 
    
         
             
                @unix_file  = 'unix_test_file.txt'
         
     | 
| 
       25 
25 
     | 
    
         
             
              end
         
     | 
| 
       26 
26 
     | 
    
         | 
| 
       27 
     | 
    
         
            -
               
     | 
| 
       28 
     | 
    
         
            -
                 
     | 
| 
      
 27 
     | 
    
         
            +
              after do
         
     | 
| 
      
 28 
     | 
    
         
            +
                [@dos_file, @mac_file, @unix_file].each{ |file| described_class.delete(file) if described_class.exist?(file) }
         
     | 
| 
      
 29 
     | 
    
         
            +
                described_class.delete(test_file1) if described_class.exist?(test_file1)
         
     | 
| 
      
 30 
     | 
    
         
            +
                described_class.delete(test_file2) if described_class.exist?(test_file2)
         
     | 
| 
       29 
31 
     | 
    
         
             
              end
         
     | 
| 
       30 
32 
     | 
    
         | 
| 
       31 
     | 
    
         
            -
              example  
     | 
| 
       32 
     | 
    
         
            -
                expect( 
     | 
| 
       33 
     | 
    
         
            -
             
     | 
| 
       34 
     | 
    
         
            -
                expect(File.nl_for_platform('mac') ).to eq( "\cM")
         
     | 
| 
      
 33 
     | 
    
         
            +
              example 'nl_for_platform basic functionality' do
         
     | 
| 
      
 34 
     | 
    
         
            +
                expect(described_class).to respond_to(:nl_for_platform)
         
     | 
| 
      
 35 
     | 
    
         
            +
              end
         
     | 
| 
       35 
36 
     | 
    
         | 
| 
      
 37 
     | 
    
         
            +
              example 'nl_for_platform returns expected results' do
         
     | 
| 
      
 38 
     | 
    
         
            +
                expect(described_class.nl_for_platform('dos')).to eq("\cM\cJ")
         
     | 
| 
      
 39 
     | 
    
         
            +
                expect(described_class.nl_for_platform('unix')).to eq("\cJ")
         
     | 
| 
      
 40 
     | 
    
         
            +
                expect(described_class.nl_for_platform('mac')).to eq("\cM")
         
     | 
| 
       36 
41 
     | 
    
         
             
              end
         
     | 
| 
       37 
42 
     | 
    
         | 
| 
       38 
43 
     | 
    
         
             
              example "nl_for_platform with 'local' platform does not raise an error" do
         
     | 
| 
       39 
     | 
    
         
            -
                expect{  
     | 
| 
      
 44 
     | 
    
         
            +
                expect{ described_class.nl_for_platform('local') }.not_to raise_error
         
     | 
| 
       40 
45 
     | 
    
         
             
              end
         
     | 
| 
       41 
46 
     | 
    
         | 
| 
       42 
     | 
    
         
            -
              example  
     | 
| 
       43 
     | 
    
         
            -
                expect{  
     | 
| 
      
 47 
     | 
    
         
            +
              example 'nl_for_platform with unsupported platform raises an error' do
         
     | 
| 
      
 48 
     | 
    
         
            +
                expect{ described_class.nl_for_platform('bogus') }.to raise_error(ArgumentError)
         
     | 
| 
       44 
49 
     | 
    
         
             
              end
         
     | 
| 
       45 
50 
     | 
    
         | 
| 
       46 
     | 
    
         
            -
              example  
     | 
| 
       47 
     | 
    
         
            -
                expect( 
     | 
| 
      
 51 
     | 
    
         
            +
              example 'nl_convert basic functionality' do
         
     | 
| 
      
 52 
     | 
    
         
            +
                expect(described_class).to respond_to(:nl_convert)
         
     | 
| 
       48 
53 
     | 
    
         
             
              end
         
     | 
| 
       49 
54 
     | 
    
         | 
| 
       50 
     | 
    
         
            -
              example  
     | 
| 
       51 
     | 
    
         
            -
                expect{  
     | 
| 
       52 
     | 
    
         
            -
                expect{  
     | 
| 
       53 
     | 
    
         
            -
                expect{  
     | 
| 
      
 55 
     | 
    
         
            +
              example 'nl_convert accepts one, two or three arguments' do
         
     | 
| 
      
 56 
     | 
    
         
            +
                expect{ described_class.nl_convert(@test_file2) }.not_to raise_error
         
     | 
| 
      
 57 
     | 
    
         
            +
                expect{ described_class.nl_convert(@test_file2, @test_file2) }.not_to raise_error
         
     | 
| 
      
 58 
     | 
    
         
            +
                expect{ described_class.nl_convert(@test_file2, @test_file2, 'unix') }.not_to raise_error
         
     | 
| 
       54 
59 
     | 
    
         
             
              end
         
     | 
| 
       55 
60 
     | 
    
         | 
| 
       56 
     | 
    
         
            -
              example  
     | 
| 
       57 
     | 
    
         
            -
                expect{  
     | 
| 
       58 
     | 
    
         
            -
                expect{  
     | 
| 
       59 
     | 
    
         
            -
                expect( 
     | 
| 
       60 
     | 
    
         
            -
                expect( 
     | 
| 
      
 61 
     | 
    
         
            +
              example 'nl_convert with dos platform argument works as expected' do
         
     | 
| 
      
 62 
     | 
    
         
            +
                expect{ described_class.nl_convert(@test_file1, @dos_file, 'dos') }.not_to raise_error
         
     | 
| 
      
 63 
     | 
    
         
            +
                expect{ described_class.nl_convert(@test_file1, @dos_file, 'dos') }.not_to raise_error
         
     | 
| 
      
 64 
     | 
    
         
            +
                expect(described_class.size(@dos_file)).to be > described_class.size(@test_file1)
         
     | 
| 
      
 65 
     | 
    
         
            +
                expect(described_class.readlines(@dos_file)).to all(end_with("\cM\cJ"))
         
     | 
| 
       61 
66 
     | 
    
         
             
              end
         
     | 
| 
       62 
67 
     | 
    
         | 
| 
       63 
     | 
    
         
            -
              example  
     | 
| 
       64 
     | 
    
         
            -
                expect{  
     | 
| 
       65 
     | 
    
         
            -
                expect( 
     | 
| 
      
 68 
     | 
    
         
            +
              example 'nl_convert with mac platform argument works as expected' do
         
     | 
| 
      
 69 
     | 
    
         
            +
                expect{ described_class.nl_convert(@test_file1, @mac_file, 'mac') }.not_to raise_error
         
     | 
| 
      
 70 
     | 
    
         
            +
                expect(described_class.readlines(@mac_file)).to all(end_with("\cM"))
         
     | 
| 
       66 
71 
     | 
    
         | 
| 
       67 
72 
     | 
    
         
             
                skip if windows
         
     | 
| 
       68 
     | 
    
         
            -
                expect( 
     | 
| 
      
 73 
     | 
    
         
            +
                expect(described_class.size(@mac_file)).to eq(described_class.size(@test_file1))
         
     | 
| 
       69 
74 
     | 
    
         
             
              end
         
     | 
| 
       70 
75 
     | 
    
         | 
| 
       71 
     | 
    
         
            -
              example  
     | 
| 
       72 
     | 
    
         
            -
                expect{  
     | 
| 
       73 
     | 
    
         
            -
                expect( 
     | 
| 
      
 76 
     | 
    
         
            +
              example 'nl_convert with unix platform argument works as expected' do
         
     | 
| 
      
 77 
     | 
    
         
            +
                expect{ described_class.nl_convert(@test_file1, @unix_file, 'unix') }.not_to raise_error
         
     | 
| 
      
 78 
     | 
    
         
            +
                expect(described_class.readlines(@unix_file)).to all(end_with("\n"))
         
     | 
| 
       74 
79 
     | 
    
         | 
| 
       75 
80 
     | 
    
         
             
                if windows
         
     | 
| 
       76 
     | 
    
         
            -
                  expect( 
     | 
| 
      
 81 
     | 
    
         
            +
                  expect(described_class.size(@unix_file) >= described_class.size(@test_file1)).to be true
         
     | 
| 
       77 
82 
     | 
    
         
             
                else
         
     | 
| 
       78 
     | 
    
         
            -
                  expect( 
     | 
| 
      
 83 
     | 
    
         
            +
                  expect(described_class.size(@unix_file) <= described_class.size(@test_file1)).to be true
         
     | 
| 
       79 
84 
     | 
    
         
             
                end
         
     | 
| 
       80 
85 
     | 
    
         
             
              end
         
     | 
| 
       81 
86 
     | 
    
         | 
| 
       82 
     | 
    
         
            -
              example  
     | 
| 
       83 
     | 
    
         
            -
                expect{  
     | 
| 
      
 87 
     | 
    
         
            +
              example 'nl_convert requires at least one argument' do
         
     | 
| 
      
 88 
     | 
    
         
            +
                expect{ described_class.nl_convert }.to raise_error(ArgumentError)
         
     | 
| 
       84 
89 
     | 
    
         
             
              end
         
     | 
| 
       85 
90 
     | 
    
         | 
| 
       86 
     | 
    
         
            -
              example  
     | 
| 
       87 
     | 
    
         
            -
                expect{  
     | 
| 
      
 91 
     | 
    
         
            +
              example 'nl_convert requires a valid platform string' do
         
     | 
| 
      
 92 
     | 
    
         
            +
                expect{ described_class.nl_convert(@test_file1, 'bogus.txt', 'blah') }.to raise_error(ArgumentError)
         
     | 
| 
       88 
93 
     | 
    
         
             
              end
         
     | 
| 
       89 
94 
     | 
    
         | 
| 
       90 
     | 
    
         
            -
              example  
     | 
| 
       91 
     | 
    
         
            -
                expect{  
     | 
| 
       92 
     | 
    
         
            -
                expect{ File.nl_convert(@test_file1, @test_file2, 'dos', 1) }.to raise_error(ArgumentError)
         
     | 
| 
      
 95 
     | 
    
         
            +
              example 'nl_convert accepts a maximum of three arguments' do
         
     | 
| 
      
 96 
     | 
    
         
            +
                expect{ described_class.nl_convert(@test_file1, @test_file2, 'dos', 1) }.to raise_error(ArgumentError)
         
     | 
| 
       93 
97 
     | 
    
         
             
              end
         
     | 
| 
       94 
98 
     | 
    
         | 
| 
       95 
     | 
    
         
            -
              example  
     | 
| 
       96 
     | 
    
         
            -
                expect{  
     | 
| 
       97 
     | 
    
         
            -
              end
         
     | 
| 
       98 
     | 
    
         
            -
             
     | 
| 
       99 
     | 
    
         
            -
              after do
         
     | 
| 
       100 
     | 
    
         
            -
                [@dos_file, @mac_file, @unix_file].each{ |file| File.delete(file) if File.exist?(file) }
         
     | 
| 
       101 
     | 
    
         
            -
                File.delete(test_file1) if File.exist?(test_file1)
         
     | 
| 
       102 
     | 
    
         
            -
                File.delete(test_file2) if File.exist?(test_file2)
         
     | 
| 
      
 99 
     | 
    
         
            +
              example 'nl_convert will fail on anything but plain files' do
         
     | 
| 
      
 100 
     | 
    
         
            +
                expect{ described_class.nl_convert(IO::NULL, @test_file1) }.to raise_error(ArgumentError)
         
     | 
| 
       103 
101 
     | 
    
         
             
              end
         
     | 
| 
       104 
102 
     | 
    
         
             
            end
         
     | 
    
        data/spec/sparse_spec.rb
    CHANGED
    
    | 
         @@ -1,43 +1,39 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            #####################################################################
         
     | 
| 
       2 
     | 
    
         
            -
            #  
     | 
| 
      
 2 
     | 
    
         
            +
            # sparse_spec.rb
         
     | 
| 
       3 
3 
     | 
    
         
             
            #
         
     | 
| 
       4 
4 
     | 
    
         
             
            # Test case for the File.sparse? method. You should run this test
         
     | 
| 
       5 
5 
     | 
    
         
             
            # via the 'rake test:is_sparse' task.
         
     | 
| 
       6 
6 
     | 
    
         
             
            #####################################################################
         
     | 
| 
       7 
     | 
    
         
            -
            require ' 
     | 
| 
       8 
     | 
    
         
            -
            require 'ptools'
         
     | 
| 
      
 7 
     | 
    
         
            +
            require 'spec_helper'
         
     | 
| 
       9 
8 
     | 
    
         | 
| 
       10 
9 
     | 
    
         
             
            RSpec.describe File, :sparse do
         
     | 
| 
       11 
10 
     | 
    
         
             
              let(:windows) { File::ALT_SEPARATOR }
         
     | 
| 
       12 
     | 
    
         
            -
              let(: 
     | 
| 
       13 
     | 
    
         
            -
              let(:non_sparse_file) { File.expand_path(File.basename(__FILE__)) }
         
     | 
| 
      
 11 
     | 
    
         
            +
              let(:non_sparse_file) { described_class.expand_path(described_class.basename(__FILE__)) }
         
     | 
| 
       14 
12 
     | 
    
         
             
              let(:sparse_file) { 'test_sparse_file' }
         
     | 
| 
       15 
13 
     | 
    
         | 
| 
       16 
14 
     | 
    
         
             
              before do
         
     | 
| 
       17 
     | 
    
         
            -
                Dir.chdir( 
     | 
| 
      
 15 
     | 
    
         
            +
                Dir.chdir('spec') if described_class.exist?('spec')
         
     | 
| 
       18 
16 
     | 
    
         
             
                system("dd of=#{sparse_file} bs=1k seek=5120 count=0 2>/dev/null") unless windows
         
     | 
| 
       19 
17 
     | 
    
         
             
              end
         
     | 
| 
       20 
18 
     | 
    
         | 
| 
       21 
     | 
    
         
            -
               
     | 
| 
       22 
     | 
    
         
            -
                 
     | 
| 
       23 
     | 
    
         
            -
                 
     | 
| 
       24 
     | 
    
         
            -
                expect{ File.sparse?(sparse_file) }.not_to raise_error
         
     | 
| 
       25 
     | 
    
         
            -
                expect(File.sparse?(sparse_file)).to be(true).or be(false)
         
     | 
| 
      
 19 
     | 
    
         
            +
              after do
         
     | 
| 
      
 20 
     | 
    
         
            +
                Dir.chdir('spec') if described_class.exist?('spec')
         
     | 
| 
      
 21 
     | 
    
         
            +
                described_class.delete(sparse_file) if described_class.exist?(sparse_file)
         
     | 
| 
       26 
22 
     | 
    
         
             
              end
         
     | 
| 
       27 
23 
     | 
    
         | 
| 
       28 
     | 
    
         
            -
              example  
     | 
| 
       29 
     | 
    
         
            -
                 
     | 
| 
       30 
     | 
    
         
            -
                expect 
     | 
| 
       31 
     | 
    
         
            -
                expect( 
     | 
| 
      
 24 
     | 
    
         
            +
              example 'is_sparse basic functionality', :unix_only => true do
         
     | 
| 
      
 25 
     | 
    
         
            +
                expect(described_class).to respond_to(:sparse?)
         
     | 
| 
      
 26 
     | 
    
         
            +
                expect{ described_class.sparse?(sparse_file) }.not_to raise_error
         
     | 
| 
      
 27 
     | 
    
         
            +
                expect(described_class.sparse?(sparse_file)).to be(true).or be(false)
         
     | 
| 
       32 
28 
     | 
    
         
             
              end
         
     | 
| 
       33 
29 
     | 
    
         | 
| 
       34 
     | 
    
         
            -
              example  
     | 
| 
       35 
     | 
    
         
            -
                 
     | 
| 
       36 
     | 
    
         
            -
                expect 
     | 
| 
      
 30 
     | 
    
         
            +
              example 'is_sparse returns the expected results', :unix_only => true do
         
     | 
| 
      
 31 
     | 
    
         
            +
                expect(described_class.sparse?(sparse_file)).to be true
         
     | 
| 
      
 32 
     | 
    
         
            +
                expect(described_class.sparse?(non_sparse_file)).to be false
         
     | 
| 
       37 
33 
     | 
    
         
             
              end
         
     | 
| 
       38 
34 
     | 
    
         | 
| 
       39 
     | 
    
         
            -
               
     | 
| 
       40 
     | 
    
         
            -
                 
     | 
| 
       41 
     | 
    
         
            -
                 
     | 
| 
      
 35 
     | 
    
         
            +
              example 'is_sparse only accepts one argument' do
         
     | 
| 
      
 36 
     | 
    
         
            +
                skip if windows
         
     | 
| 
      
 37 
     | 
    
         
            +
                expect{ described_class.sparse?(sparse_file, sparse_file) }.to raise_error(ArgumentError)
         
     | 
| 
       42 
38 
     | 
    
         
             
              end
         
     | 
| 
       43 
39 
     | 
    
         
             
            end
         
     |