ptools 1.4.2-universal-mingw32 → 1.4.3-universal-mingw32

Sign up to get free protection for your applications and to get access to all the features.
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) { File.dirname(__FILE__) }
13
- let(:bin_file) { File::ALT_SEPARATOR ? File.join(ENV['windir'], 'notepad.exe') : '/bin/ls' }
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 = 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')
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 "File.binary? basic functionality" do
26
- expect(File).to respond_to(:binary?)
27
- expect{ File.binary?(@txt_file) }.not_to raise_error
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 "File.binary? returns true for binary files" do
31
- expect(File.binary?(bin_file)).to be true
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 "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
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 "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
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 "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
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 "File.binary? raises an error if the file cannot be found" do
53
- expect{ File.binary?('bogus') }.to raise_error(SystemCallError)
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 "File.binary? only accepts one argument" do
57
- expect{ File.binary?(@txt_file, bin_file) }.to raise_error(ArgumentError)
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
@@ -12,12 +12,12 @@ require 'ptools'
12
12
  RSpec.describe File, :constants do
13
13
  let(:windows) { File::ALT_SEPARATOR }
14
14
 
15
- example "PTOOLS_VERSION constant is set to expected value" do
16
- expect(File::PTOOLS_VERSION).to eq('1.4.2')
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 "IMAGE_EXT constant is set to array of values" do
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
- 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"]
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
- 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
20
+ after do
21
+ described_class.delete(test_file) if described_class.exist?(test_file)
25
22
  end
26
23
 
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)
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 "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)
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
- after do
39
- File.delete(test_file) if File.exists?(test_file)
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 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