ptools 1.4.2-universal-mingw32 → 1.5.0-universal-mingw32

Sign up to get free protection for your applications and to get access to all the features.
data/spec/image_spec.rb CHANGED
@@ -1,51 +1,188 @@
1
1
  #####################################################################
2
2
  # image_spec.rb
3
3
  #
4
- # Specs for the File.image? method. You should run these specs via
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 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')
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
- 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)
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
- 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
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
- example "image? method returns true for a gif" do
33
- expect(File.image?(@gif_file)).to be true
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
- example "image? method returns true for a jpeg" do
37
- expect(File.image?(@jpg_file)).to be true
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
- example "image? method returns true for a png" do
41
- expect(File.image?(@png_file)).to be true
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
- example "image? method returns true for an ico" do
45
- expect(File.image?(@ico_file)).to be true
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
- 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
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
Binary file
data/spec/img/test.bmp ADDED
Binary file
Binary file
@@ -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) { File.dirname(__FILE__) }
14
- let(:test_file1) { File.join(dirname, 'test_nl_convert1.txt') }
15
- let(:test_file2) { File.join(dirname, 'test_nl_convert2.txt') }
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
- File.open(test_file1, 'w'){ |fh| 10.times{ |n| fh.puts "line #{n}" } }
19
- File.open(test_file2, 'w'){ |fh| 10.times{ |n| fh.puts "line #{n}" } }
20
- @test_file1 = File.join(dirname, 'test_nl_convert1.txt')
21
- @test_file2 = File.join(dirname, 'test_nl_convert2.txt')
22
- @dos_file = File.join(dirname, 'dos_test_file.txt')
23
- @mac_file = File.join(dirname, 'mac_test_file.txt')
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
- example "nl_for_platform basic functionality" do
28
- expect(File).to respond_to(:nl_for_platform)
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 "nl_for_platform returns expected results" do
32
- expect(File.nl_for_platform('dos') ).to eq( "\cM\cJ")
33
- expect(File.nl_for_platform('unix') ).to eq( "\cJ")
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{ File.nl_for_platform('local') }.not_to raise_error
44
+ expect{ described_class.nl_for_platform('local') }.not_to raise_error
40
45
  end
41
46
 
42
- example "nl_for_platform with unsupported platform raises an error" do
43
- expect{ File.nl_for_platform('bogus') }.to raise_error(ArgumentError)
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 "nl_convert basic functionality" do
47
- expect(File).to respond_to(:nl_convert)
51
+ example 'nl_convert basic functionality' do
52
+ expect(described_class).to respond_to(:nl_convert)
48
53
  end
49
54
 
50
- example "nl_convert accepts one, two or three arguments" do
51
- expect{ File.nl_convert(@test_file2) }.not_to raise_error
52
- expect{ File.nl_convert(@test_file2, @test_file2) }.not_to raise_error
53
- expect{ File.nl_convert(@test_file2, @test_file2, "unix") }.not_to raise_error
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 "nl_convert with dos platform argument works as expected" do
57
- expect{ File.nl_convert(@test_file1, @dos_file, "dos") }.not_to raise_error
58
- expect{ File.nl_convert(@test_file1, @dos_file, "dos") }.not_to raise_error
59
- expect(File.size(@dos_file)).to be > File.size(@test_file1)
60
- expect(IO.readlines(@dos_file).first.split("")[-2..-1]).to eq(["\cM","\cJ"])
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 "nl_convert with mac platform argument works as expected" do
64
- expect{ File.nl_convert(@test_file1, @mac_file, 'mac') }.not_to raise_error
65
- expect(IO.readlines(@mac_file).first.split("").last).to eq("\cM")
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(File.size(@mac_file)).to eq(File.size(@test_file1))
73
+ expect(described_class.size(@mac_file)).to eq(described_class.size(@test_file1))
69
74
  end
70
75
 
71
- example "nl_convert with unix platform argument works as expected" do
72
- expect{ File.nl_convert(@test_file1, @unix_file, "unix") }.not_to raise_error
73
- expect(IO.readlines(@unix_file).first.split("").last).to eq("\n")
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(File.size(@unix_file) >= File.size(@test_file1)).to be true
81
+ expect(described_class.size(@unix_file) >= described_class.size(@test_file1)).to be true
77
82
  else
78
- expect(File.size(@unix_file) <= File.size(@test_file1)).to be true
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 "nl_convert requires at least one argument" do
83
- expect{ File.nl_convert }.to raise_error(ArgumentError)
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 "nl_convert requires a valid platform string" do
87
- expect{ File.nl_convert(@test_file1, "bogus.txt", "blah") }.to raise_error(ArgumentError)
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 "nl_convert accepts a maximum of three arguments" do
91
- expect{ File.nl_convert(@example_file1, @test_file2, 'dos', 1) }.to raise_error(ArgumentError)
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 "nl_convert will fail on anything but plain files" do
96
- expect{ File.nl_convert(IO::NULL, @test_file1) }.to raise_error(ArgumentError)
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
- # test_is_sparse.rb
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 'rspec'
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(:osx) { RbConfig::CONFIG['host_os'] =~ /darwin|osx/i }
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("spec") if File.exist?("spec")
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
- example "is_sparse basic functionality" do
22
- skip "skipped on MS Windows or OSX" if windows || osx
23
- expect(File).to respond_to(:sparse?)
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 "is_sparse returns the expected results" do
29
- skip "skipped on MS Windows or OSX" if windows || osx
30
- expect(File.sparse?(sparse_file)).to be true
31
- expect(File.sparse?(non_sparse_file)).to be false
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 "is_sparse only accepts one argument" do
35
- skip if windows
36
- expect{ File.sparse?(sparse_file, sparse_file) }.to raise_error(ArgumentError)
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
- after do
40
- Dir.chdir("spec") if File.exist?("spec")
41
- File.delete(sparse_file) if File.exist?(sparse_file)
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
@@ -0,0 +1,7 @@
1
+ require 'ptools'
2
+ require 'rspec'
3
+
4
+ RSpec.configure do |config|
5
+ config.filter_run_excluding(:windows_only) unless Gem.win_platform?
6
+ config.filter_run_excluding(:unix_only) if Gem.win_platform?
7
+ end
data/spec/tail_spec.rb CHANGED
@@ -8,100 +8,100 @@ require 'rspec'
8
8
  require 'ptools'
9
9
 
10
10
  RSpec.describe File, :tail do
11
- let(:dirname) { File.dirname(__FILE__) }
12
- let(:test_file1) { File.join(dirname, 'test_file1.txt') }
13
- let(:test_file64) { File.join(dirname, 'test_file64.txt') }
14
- let(:test_file128) { File.join(dirname, 'test_file128.txt') }
15
- let(:test_file_trail) { File.join(dirname, 'test_file_trail.txt') }
16
- let(:test_file_trail_nl) { File.join(dirname, 'test_file_trail_nl.txt') }
11
+ let(:dirname) { described_class.dirname(__FILE__) }
12
+ let(:test_file1) { described_class.join(dirname, 'test_file1.txt') }
13
+ let(:test_file64) { described_class.join(dirname, 'test_file64.txt') }
14
+ let(:test_file128) { described_class.join(dirname, 'test_file128.txt') }
15
+ let(:test_file_trail) { described_class.join(dirname, 'test_file_trail.txt') }
16
+ let(:test_file_trail_nl) { described_class.join(dirname, 'test_file_trail_nl.txt') }
17
17
 
18
18
  before do
19
- File.open(test_file1, 'w'){ |fh| 25.times{ |n| fh.puts "line#{n+1}" } }
19
+ described_class.open(test_file1, 'w'){ |fh| 25.times{ |n| fh.puts "line#{n+1}" } }
20
20
 
21
21
  # Trailing newline test
22
- File.open(test_file_trail, 'w'){ |fh|
22
+ described_class.open(test_file_trail, 'w') do |fh|
23
23
  2.times{ |n| fh.puts "trail#{n+1}" }
24
- fh.write "trail3"
25
- }
24
+ fh.write 'trail3'
25
+ end
26
26
 
27
- File.open(test_file_trail_nl, 'w'){ |fh|
27
+ described_class.open(test_file_trail_nl, 'w') do |fh|
28
28
  3.times{ |n| fh.puts "trail#{n+1}" }
29
- }
29
+ end
30
30
 
31
31
  # Larger files
32
- test_tail_fmt_str = "line data data data data data data data %5s"
32
+ test_tail_fmt_str = 'line data data data data data data data %5s'
33
33
 
34
- File.open(test_file64, 'w'){ |fh|
35
- 2000.times{ |n|
34
+ described_class.open(test_file64, 'w') do |fh|
35
+ 2000.times do |n|
36
36
  fh.puts test_tail_fmt_str % (n+1).to_s
37
- }
38
- }
37
+ end
38
+ end
39
39
 
40
- File.open(test_file128, 'w'){ |fh|
41
- 4500.times{ |n|
40
+ described_class.open(test_file128, 'w') do |fh|
41
+ 4500.times do |n|
42
42
  fh.puts test_tail_fmt_str % (n+1).to_s
43
- }
44
- }
43
+ end
44
+ end
45
45
 
46
- @expected_tail1 = %w{
46
+ @expected_tail1 = %w[
47
47
  line16 line17 line18 line19 line20
48
48
  line21 line22 line23 line24 line25
49
- }
49
+ ]
50
50
 
51
- @expected_tail2 = ["line21","line22","line23","line24","line25"]
51
+ @expected_tail2 = %w[line21 line22 line23 line24 line25]
52
52
 
53
53
  @expected_tail_more = []
54
54
  25.times{ |n| @expected_tail_more.push "line#{n+1}" }
55
55
 
56
- @expected_tail_trail = %w{ trail2 trail3 }
56
+ @expected_tail_trail = %w[trail2 trail3]
57
57
 
58
- @test_tail_fmt_str = "line data data data data data data data %5s"
58
+ @test_tail_fmt_str = 'line data data data data data data data %5s'
59
59
  end
60
60
 
61
- example "tail basic functionality" do
62
- expect(File).to respond_to(:tail)
63
- expect{ File.tail(test_file1) }.not_to raise_error
64
- expect{ File.tail(test_file1, 5) }.not_to raise_error
65
- expect{ File.tail(test_file1){}.not_to raise_error }
61
+ after do
62
+ described_class.delete(test_file1) if described_class.exist?(test_file1)
63
+ described_class.delete(test_file64) if described_class.exist?(test_file64)
64
+ described_class.delete(test_file128) if described_class.exist?(test_file128)
65
+ described_class.delete(test_file_trail_nl) if described_class.exist?(test_file_trail_nl)
66
+ described_class.delete(test_file_trail) if described_class.exist?(test_file_trail)
67
+ end
68
+
69
+ example 'tail basic functionality' do
70
+ expect(described_class).to respond_to(:tail)
71
+ expect{ described_class.tail(test_file1) }.not_to raise_error
72
+ expect{ described_class.tail(test_file1, 5) }.not_to raise_error
73
+ expect{ described_class.tail(test_file1){} }.not_to raise_error
66
74
  end
67
75
 
68
- example "tail returns the expected values" do
69
- expect(File.tail(test_file1)).to be_kind_of(Array)
70
- expect(File.tail(test_file1)).to eq(@expected_tail1)
71
- expect(File.tail(test_file1, 5)).to eq(@expected_tail2)
76
+ example 'tail returns the expected values' do
77
+ expect(described_class.tail(test_file1)).to be_kind_of(Array)
78
+ expect(described_class.tail(test_file1)).to eq(@expected_tail1)
79
+ expect(described_class.tail(test_file1, 5)).to eq(@expected_tail2)
72
80
  end
73
81
 
74
- example "specifying a number greater than the actual number of lines works as expected" do
75
- expect(File.tail(test_file1, 30)).to eq(@expected_tail_more)
82
+ example 'specifying a number greater than the actual number of lines works as expected' do
83
+ expect(described_class.tail(test_file1, 30)).to eq(@expected_tail_more)
76
84
  end
77
85
 
78
- example "tail requires two arguments" do
79
- expect{ File.tail }.to raise_error(ArgumentError)
80
- expect{ File.tail(test_file1, 5, 5) }.to raise_error(ArgumentError)
86
+ example 'tail requires two arguments' do
87
+ expect{ described_class.tail }.to raise_error(ArgumentError)
88
+ expect{ described_class.tail(test_file1, 5, 5) }.to raise_error(ArgumentError)
81
89
  end
82
90
 
83
- example "tail works as expected when there is no trailing newline" do
84
- expect(File.tail(test_file_trail, 2)).to eq(@expected_tail_trail)
85
- expect(File.tail(test_file_trail_nl, 2)).to eq(@expected_tail_trail)
91
+ example 'tail works as expected when there is no trailing newline' do
92
+ expect(described_class.tail(test_file_trail, 2)).to eq(@expected_tail_trail)
93
+ expect(described_class.tail(test_file_trail_nl, 2)).to eq(@expected_tail_trail)
86
94
  end
87
95
 
88
- example "tail works as expected on a file larger than 64k" do
96
+ example 'tail works as expected on a file larger than 64k' do
89
97
  expected_tail_64k = []
90
98
  2000.times{ |n| expected_tail_64k.push(@test_tail_fmt_str % (n+1).to_s) }
91
- expect(File.tail(test_file64, 2000)).to eq(expected_tail_64k)
99
+ expect(described_class.tail(test_file64, 2000)).to eq(expected_tail_64k)
92
100
  end
93
101
 
94
- example "tail works as expected on a file larger than 128k" do
102
+ example 'tail works as expected on a file larger than 128k' do
95
103
  expected_tail_128k = []
96
104
  4500.times{ |n| expected_tail_128k.push(@test_tail_fmt_str % (n+1).to_s) }
97
- expect(File.tail(test_file128, 4500)).to eq(expected_tail_128k)
98
- end
99
-
100
- after do
101
- File.delete(test_file1) if File.exist?(test_file1)
102
- File.delete(test_file64) if File.exist?(test_file64)
103
- File.delete(test_file128) if File.exist?(test_file128)
104
- File.delete(test_file_trail_nl) if File.exist?(test_file_trail_nl)
105
- File.delete(test_file_trail) if File.exist?(test_file_trail)
105
+ expect(described_class.tail(test_file128, 4500)).to eq(expected_tail_128k)
106
106
  end
107
107
  end