fakefs 0.5.4 → 0.6.0

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.
@@ -1,5 +1,6 @@
1
- require "test_helper"
1
+ require 'test_helper'
2
2
 
3
+ # Fake File test class
3
4
  class FakeFileTest < Test::Unit::TestCase
4
5
  include FakeFS
5
6
 
@@ -10,12 +11,12 @@ class FakeFileTest < Test::Unit::TestCase
10
11
  end
11
12
 
12
13
  def test_fake_file_has_empty_content_by_default
13
- assert_equal "", @file.content
14
+ assert_equal '', @file.content
14
15
  end
15
16
 
16
17
  def test_fake_file_can_read_and_write_to_content
17
- @file.content = "foobar"
18
- assert_equal "foobar", @file.content
18
+ @file.content = 'foobar'
19
+ assert_equal 'foobar', @file.content
19
20
  end
20
21
 
21
22
  def test_fake_file_has_1_link_by_default
@@ -64,9 +65,9 @@ class FakeFileTest < Test::Unit::TestCase
64
65
 
65
66
  @file.link other_file
66
67
 
67
- @file.content = "foobar"
68
+ @file.content = 'foobar'
68
69
 
69
- assert_equal "foobar", other_file.content
70
+ assert_equal 'foobar', other_file.content
70
71
  end
71
72
 
72
73
  def test_clone_creates_new_inode
@@ -77,15 +78,15 @@ class FakeFileTest < Test::Unit::TestCase
77
78
  def test_cloning_does_not_use_same_content_object
78
79
  clone = @file.clone
79
80
 
80
- clone.content = "foo"
81
- @file.content = "bar"
81
+ clone.content = 'foo'
82
+ @file.content = 'bar'
82
83
 
83
- assert_equal "foo", clone.content
84
- assert_equal "bar", @file.content
84
+ assert_equal 'foo', clone.content
85
+ assert_equal 'bar', @file.content
85
86
  end
86
87
 
87
88
  def test_raises_an_error_with_the_correct_path
88
- path = "/some/non/existing/file"
89
+ path = '/some/non/existing/file'
89
90
  begin
90
91
  FakeFS::File.new path
91
92
  msg = nil
@@ -1,25 +1,33 @@
1
- require "test_helper"
1
+ require 'test_helper'
2
2
 
3
+ # Fake symlink test class
3
4
  class FakeSymlinkTest < Test::Unit::TestCase
4
5
  include FakeFS
5
6
 
6
7
  def test_symlink_has_method_missing_as_private
7
- methods = FakeSymlink.private_instance_methods.map { |m| m.to_s }
8
- assert methods.include?("method_missing")
8
+ methods = FakeSymlink.private_instance_methods.map(&:to_s)
9
+ assert methods.include?('method_missing')
9
10
  end
10
11
 
11
12
  def test_symlink_respond_to_accepts_multiple_params
12
13
  fake_symlink = FakeSymlink.new('foo')
13
- assert fake_symlink.respond_to?(:to_s, false), 'has public method \#to_s'
14
- assert fake_symlink.respond_to?(:to_s, true), 'has public or private method \#to_s'
15
- assert !fake_symlink.respond_to?(:initialize, false), 'has private method \#initialize'
16
- assert fake_symlink.respond_to?(:initialize, true), 'has private method \#initialize'
14
+ assert fake_symlink.respond_to?(:to_s, false),
15
+ 'has public method \#to_s'
16
+ assert fake_symlink.respond_to?(:to_s, true),
17
+ 'has public or private method \#to_s'
18
+ assert !fake_symlink.respond_to?(:initialize, false),
19
+ 'has private method \#initialize'
20
+ assert fake_symlink.respond_to?(:initialize, true),
21
+ 'has private method \#initialize'
17
22
  end
18
23
 
19
24
  def test_symlink_respond_to_uses_same_param_defaults
20
25
  fake_symlink = FakeSymlink.new('foo')
21
- assert_equal fake_symlink.respond_to?(:to_s), fake_symlink.entry.respond_to?(:to_s)
22
- assert_not_equal fake_symlink.respond_to?(:to_s), fake_symlink.entry.respond_to?(:initialize)
23
- assert_equal fake_symlink.respond_to?(:initialize), fake_symlink.entry.respond_to?(:initialize)
26
+ assert_equal fake_symlink.respond_to?(:to_s),
27
+ fake_symlink.entry.respond_to?(:to_s)
28
+ assert_not_equal fake_symlink.respond_to?(:to_s),
29
+ fake_symlink.entry.respond_to?(:initialize)
30
+ assert_equal fake_symlink.respond_to?(:initialize),
31
+ fake_symlink.entry.respond_to?(:initialize)
24
32
  end
25
33
  end
@@ -1,6 +1,7 @@
1
1
  # -*- coding: utf-8 -*-
2
- require "test_helper"
2
+ require 'test_helper'
3
3
 
4
+ # FakeFS tests
4
5
  class FakeFSTest < Test::Unit::TestCase
5
6
  include FakeFS
6
7
 
@@ -25,109 +26,109 @@ class FakeFSTest < Test::Unit::TestCase
25
26
  end
26
27
 
27
28
  def test_can_create_directories_with_file_utils_mkdir_p
28
- FileUtils.mkdir_p("/path/to/dir")
29
+ FileUtils.mkdir_p('/path/to/dir')
29
30
  assert_kind_of FakeDir, FileSystem.fs['path']['to']['dir']
30
31
  end
31
32
 
32
33
  def test_can_cd_to_directory_with_block
33
- FileUtils.mkdir_p("/path/to/dir")
34
+ FileUtils.mkdir_p('/path/to/dir')
34
35
  new_path = nil
35
- FileUtils.cd("/path/to") do
36
+ FileUtils.cd('/path/to') do
36
37
  new_path = Dir.getwd
37
38
  end
38
39
 
39
- assert_equal new_path, "/path/to"
40
+ assert_equal new_path, '/path/to'
40
41
  end
41
42
 
42
43
  def test_can_create_a_list_of_directories_with_file_utils_mkdir_p
43
- FileUtils.mkdir_p(["/path/to/dir1", "/path/to/dir2"])
44
+ FileUtils.mkdir_p(%w(/path/to/dir1 /path/to/dir2))
44
45
  assert_kind_of FakeDir, FileSystem.fs['path']['to']['dir1']
45
46
  assert_kind_of FakeDir, FileSystem.fs['path']['to']['dir2']
46
47
  end
47
48
 
48
49
  def test_can_create_directories_with_options
49
- FileUtils.mkdir_p("/path/to/dir", :mode => 0755)
50
+ FileUtils.mkdir_p('/path/to/dir', mode: 0755)
50
51
  assert_kind_of FakeDir, FileSystem.fs['path']['to']['dir']
51
52
  end
52
53
 
53
54
  def test_can_create_directories_with_file_utils_mkdir
54
- FileUtils.mkdir_p("/path/to/dir")
55
- FileUtils.mkdir("/path/to/dir/subdir")
55
+ FileUtils.mkdir_p('/path/to/dir')
56
+ FileUtils.mkdir('/path/to/dir/subdir')
56
57
  assert_kind_of FakeDir, FileSystem.fs['path']['to']['dir']['subdir']
57
58
  end
58
59
 
59
60
  def test_can_create_a_list_of_directories_with_file_utils_mkdir
60
- FileUtils.mkdir_p("/path/to/dir")
61
- FileUtils.mkdir(["/path/to/dir/subdir1", "/path/to/dir/subdir2"])
61
+ FileUtils.mkdir_p('/path/to/dir')
62
+ FileUtils.mkdir(%w(/path/to/dir/subdir1 /path/to/dir/subdir2))
62
63
  assert_kind_of FakeDir, FileSystem.fs['path']['to']['dir']['subdir1']
63
64
  assert_kind_of FakeDir, FileSystem.fs['path']['to']['dir']['subdir2']
64
65
  end
65
66
 
66
67
  def test_raises_error_when_creating_a_new_dir_with_mkdir_in_non_existent_path
67
68
  assert_raises Errno::ENOENT do
68
- FileUtils.mkdir("/this/path/does/not/exists/newdir")
69
+ FileUtils.mkdir('/this/path/does/not/exists/newdir')
69
70
  end
70
71
  end
71
72
 
72
73
  def test_raises_error_when_creating_a_new_dir_over_existing_file
73
- File.open("file", "w") {|f| f << "This is a file, not a directory." }
74
+ File.open('file', 'w') { |f| f << 'This is a file, not a directory.' }
74
75
 
75
76
  assert_raise Errno::EEXIST do
76
- FileUtils.mkdir_p("file/subdir")
77
+ FileUtils.mkdir_p('file/subdir')
77
78
  end
78
79
 
79
- FileUtils.mkdir("dir")
80
- File.open("dir/subfile", "w") {|f| f << "This is a file inside a directory." }
80
+ FileUtils.mkdir('dir')
81
+ File.open('dir/subfile', 'w') { |f| f << 'This is a file inside a directory.' }
81
82
 
82
83
  assert_raise Errno::EEXIST do
83
- FileUtils.mkdir_p("dir/subfile/subdir")
84
+ FileUtils.mkdir_p('dir/subfile/subdir')
84
85
  end
85
86
  end
86
87
 
87
88
  def test_can_create_directories_with_mkpath
88
- FileUtils.mkpath("/path/to/dir")
89
+ FileUtils.mkpath('/path/to/dir')
89
90
  assert_kind_of FakeDir, FileSystem.fs['path']['to']['dir']
90
91
  end
91
92
 
92
93
  def test_can_create_directories_with_mkpath_and_options
93
- FileUtils.mkpath("/path/to/dir", :mode => 0755)
94
+ FileUtils.mkpath('/path/to/dir', mode: 0755)
94
95
  assert_kind_of FakeDir, FileSystem.fs['path']['to']['dir']
95
96
  end
96
97
 
97
98
  def test_can_create_directories_with_mkdirs
98
- FileUtils.makedirs("/path/to/dir")
99
+ FileUtils.makedirs('/path/to/dir')
99
100
  assert_kind_of FakeDir, FileSystem.fs['path']['to']['dir']
100
101
  end
101
102
 
102
103
  def test_can_create_directories_with_mkdirs_and_options
103
- FileUtils.makedirs("/path/to/dir", :mode => 0755)
104
+ FileUtils.makedirs('/path/to/dir', mode: 0755)
104
105
  assert_kind_of FakeDir, FileSystem.fs['path']['to']['dir']
105
106
  end
106
107
 
107
108
  def test_unlink_errors_on_file_not_found
108
109
  assert_raise Errno::ENOENT do
109
- FileUtils.rm("/foo")
110
+ FileUtils.rm('/foo')
110
111
  end
111
112
  end
112
113
 
113
114
  def test_unlink_doesnt_error_on_file_not_found_when_forced
114
115
  assert_nothing_raised do
115
- FileUtils.rm("/foo", :force => true)
116
+ FileUtils.rm('/foo', force: true)
116
117
  end
117
118
  end
118
119
 
119
120
  def test_can_delete_directories
120
- FileUtils.mkdir_p("/path/to/dir")
121
- FileUtils.rmdir("/path/to/dir")
122
- assert File.exists?("/path/to/")
123
- assert File.exists?("/path/to/dir") == false
121
+ FileUtils.mkdir_p('/path/to/dir')
122
+ FileUtils.rmdir('/path/to/dir')
123
+ assert File.exist?('/path/to/')
124
+ assert File.exist?('/path/to/dir') == false
124
125
  end
125
126
 
126
127
  def test_can_delete_multiple_files
127
- FileUtils.touch(["foo", "bar"])
128
- FileUtils.rm(["foo", "bar"])
129
- assert File.exists?("foo") == false
130
- assert File.exists?("bar") == false
128
+ FileUtils.touch(%w(foo bar))
129
+ FileUtils.rm(%w(foo bar))
130
+ assert File.exist?('foo') == false
131
+ assert File.exist?('bar') == false
131
132
  end
132
133
 
133
134
  def test_aliases_exist
@@ -148,24 +149,24 @@ class FakeFSTest < Test::Unit::TestCase
148
149
  end
149
150
 
150
151
  def test_knows_directories_exist
151
- FileUtils.mkdir_p(path = "/path/to/dir")
152
- assert File.exists?(path)
152
+ FileUtils.mkdir_p(path = '/path/to/dir')
153
+ assert File.exist?(path)
153
154
  end
154
155
 
155
156
  def test_knows_directories_are_directories
156
- FileUtils.mkdir_p(path = "/path/to/dir")
157
+ FileUtils.mkdir_p(path = '/path/to/dir')
157
158
  assert File.directory?(path)
158
159
  end
159
160
 
160
161
  def test_knows_directories_are_directories_with_periods
161
- FileUtils.mkdir_p(period_path = "/path/to/periodfiles/one.one")
162
- FileUtils.mkdir("/path/to/periodfiles/one-one")
162
+ FileUtils.mkdir_p(period_path = '/path/to/periodfiles/one.one')
163
+ FileUtils.mkdir('/path/to/periodfiles/one-one')
163
164
 
164
165
  assert File.directory?(period_path)
165
166
  end
166
167
 
167
168
  def test_knows_symlink_directories_are_directories
168
- FileUtils.mkdir_p(path = "/path/to/dir")
169
+ FileUtils.mkdir_p(path = '/path/to/dir')
169
170
  FileUtils.ln_s path, sympath = '/sympath'
170
171
  assert File.directory?(sympath)
171
172
  end
@@ -176,29 +177,29 @@ class FakeFSTest < Test::Unit::TestCase
176
177
  end
177
178
 
178
179
  def test_doesnt_overwrite_existing_directories
179
- FileUtils.mkdir_p(path = "/path/to/dir")
180
- assert File.exists?(path)
181
- FileUtils.mkdir_p("/path/to")
182
- assert File.exists?(path)
180
+ FileUtils.mkdir_p(path = '/path/to/dir')
181
+ assert File.exist?(path)
182
+ FileUtils.mkdir_p('/path/to')
183
+ assert File.exist?(path)
183
184
  assert_raises Errno::EEXIST do
184
- FileUtils.mkdir("/path/to")
185
+ FileUtils.mkdir('/path/to')
185
186
  end
186
- assert File.exists?(path)
187
+ assert File.exist?(path)
187
188
  end
188
189
 
189
190
  def test_file_utils_mkdir_takes_options
190
- FileUtils.mkdir("/foo", :some => :option)
191
- assert File.exists?("/foo")
191
+ FileUtils.mkdir('/foo', some: :option)
192
+ assert File.exist?('/foo')
192
193
  end
193
194
 
194
195
  def test_symlink_with_missing_refferent_does_not_exist
195
196
  File.symlink('/foo', '/bar')
196
- assert !File.exists?('/bar')
197
+ assert !File.exist?('/bar')
197
198
  end
198
199
 
199
200
  def test_can_create_symlinks
200
- FileUtils.mkdir_p(target = "/path/to/target")
201
- FileUtils.ln_s(target, "/path/to/link")
201
+ FileUtils.mkdir_p(target = '/path/to/target')
202
+ FileUtils.ln_s(target, '/path/to/link')
202
203
  assert_kind_of FakeSymlink, FileSystem.fs['path']['to']['link']
203
204
 
204
205
  assert_raises(Errno::EEXIST) do
@@ -207,244 +208,246 @@ class FakeFSTest < Test::Unit::TestCase
207
208
  end
208
209
 
209
210
  def test_can_force_creation_of_symlinks
210
- FileUtils.mkdir_p(target = "/path/to/first/target")
211
- FileUtils.ln_s(target, "/path/to/link")
211
+ FileUtils.mkdir_p(target = '/path/to/first/target')
212
+ FileUtils.ln_s(target, '/path/to/link')
212
213
  assert_kind_of FakeSymlink, FileSystem.fs['path']['to']['link']
213
- FileUtils.ln_s(target, '/path/to/link', :force => true)
214
+ FileUtils.ln_s(target, '/path/to/link', force: true)
214
215
  end
215
216
 
216
217
  def test_create_symlink_using_ln_sf
217
- FileUtils.mkdir_p(target = "/path/to/first/target")
218
- FileUtils.ln_s(target, "/path/to/link")
218
+ FileUtils.mkdir_p(target = '/path/to/first/target')
219
+ FileUtils.ln_s(target, '/path/to/link')
219
220
  assert_kind_of FakeSymlink, FileSystem.fs['path']['to']['link']
220
221
  FileUtils.ln_sf(target, '/path/to/link')
221
222
  end
222
223
 
223
224
  def test_can_follow_symlinks
224
- FileUtils.mkdir_p(target = "/path/to/target")
225
- FileUtils.ln_s(target, link = "/path/to/symlink")
225
+ FileUtils.mkdir_p(target = '/path/to/target')
226
+ FileUtils.ln_s(target, link = '/path/to/symlink')
226
227
  assert_equal target, File.readlink(link)
227
228
  end
228
229
 
229
230
  def test_symlinks_in_different_directories
230
- FileUtils.mkdir_p("/path/to/bar")
231
- FileUtils.mkdir_p(target = "/path/to/foo/target")
231
+ FileUtils.mkdir_p('/path/to/bar')
232
+ FileUtils.mkdir_p(target = '/path/to/foo/target')
232
233
 
233
- FileUtils.ln_s(target, link = "/path/to/bar/symlink")
234
+ FileUtils.ln_s(target, link = '/path/to/bar/symlink')
234
235
  assert_equal target, File.readlink(link)
235
236
  end
236
237
 
237
238
  def test_symlink_with_relative_path_exists
238
- FileUtils.touch("/file")
239
- FileUtils.mkdir_p("/a/b")
240
- FileUtils.ln_s("../../file", link = "/a/b/symlink")
239
+ FileUtils.touch('/file')
240
+ FileUtils.mkdir_p('/a/b')
241
+ FileUtils.ln_s('../../file', '/a/b/symlink')
241
242
  assert File.exist?('/a/b/symlink')
242
243
  end
243
244
 
244
245
  def test_symlink_with_relative_path_and_nonexistant_file_does_not_exist
245
- FileUtils.touch("/file")
246
- FileUtils.mkdir_p("/a/b")
247
- FileUtils.ln_s("../../file_foo", link = "/a/b/symlink")
246
+ FileUtils.touch('/file')
247
+ FileUtils.mkdir_p('/a/b')
248
+ FileUtils.ln_s('../../file_foo', '/a/b/symlink')
248
249
  assert !File.exist?('/a/b/symlink')
249
250
  end
250
251
 
251
252
  def test_symlink_with_relative_path_has_correct_target
252
- FileUtils.touch("/file")
253
- FileUtils.mkdir_p("/a/b")
254
- FileUtils.ln_s("../../file", link = "/a/b/symlink")
255
- assert_equal "../../file", File.readlink(link)
253
+ FileUtils.touch('/file')
254
+ FileUtils.mkdir_p('/a/b')
255
+ FileUtils.ln_s('../../file', link = '/a/b/symlink')
256
+ assert_equal '../../file', File.readlink(link)
256
257
  end
257
258
 
258
259
  def test_symlinks_to_symlinks
259
- FileUtils.mkdir_p(target = "/path/to/foo/target")
260
- FileUtils.mkdir_p("/path/to/bar")
261
- FileUtils.mkdir_p("/path/to/bar2")
260
+ FileUtils.mkdir_p(target = '/path/to/foo/target')
261
+ FileUtils.mkdir_p('/path/to/bar')
262
+ FileUtils.mkdir_p('/path/to/bar2')
262
263
 
263
- FileUtils.ln_s(target, link1 = "/path/to/bar/symlink")
264
- FileUtils.ln_s(link1, link2 = "/path/to/bar2/symlink")
264
+ FileUtils.ln_s(target, link1 = '/path/to/bar/symlink')
265
+ FileUtils.ln_s(link1, link2 = '/path/to/bar2/symlink')
265
266
  assert_equal link1, File.readlink(link2)
266
267
  end
267
268
 
268
269
  def test_symlink_to_symlinks_should_raise_error_if_dir_doesnt_exist
269
- FileUtils.mkdir_p(target = "/path/to/foo/target")
270
+ FileUtils.mkdir_p(target = '/path/to/foo/target')
270
271
 
271
- assert !Dir.exists?("/path/to/bar")
272
+ assert !Dir.exist?('/path/to/bar')
272
273
 
273
274
  assert_raise Errno::ENOENT do
274
- FileUtils.ln_s(target, "/path/to/bar/symlink")
275
+ FileUtils.ln_s(target, '/path/to/bar/symlink')
275
276
  end
276
277
  end
277
278
 
278
279
  def test_knows_symlinks_are_symlinks
279
- FileUtils.mkdir_p(target = "/path/to/target")
280
- FileUtils.ln_s(target, link = "/path/to/symlink")
280
+ FileUtils.mkdir_p(target = '/path/to/target')
281
+ FileUtils.ln_s(target, link = '/path/to/symlink')
281
282
  assert File.symlink?(link)
282
283
  end
283
284
 
284
285
  def test_can_create_files_in_current_dir
285
286
  path = 'file.txt'
286
287
  File.open(path, 'w') do |f|
287
- f.write "Yatta!"
288
+ f.write 'Yatta!'
288
289
  end
289
290
 
290
- assert File.exists?(path)
291
+ assert File.exist?(path)
291
292
  assert File.readable?(path)
292
293
  assert File.writable?(path)
293
294
  end
294
295
 
296
+ def test_nothing_is_sticky
297
+ assert !File.sticky?('/')
298
+ end
299
+
295
300
  def test_can_create_files_in_existing_dir
296
- FileUtils.mkdir_p "/path/to"
297
- path = "/path/to/file.txt"
301
+ FileUtils.mkdir_p '/path/to'
302
+ path = '/path/to/file.txt'
298
303
 
299
304
  File.open(path, 'w') do |f|
300
- f.write "Yatta!"
305
+ f.write 'Yatta!'
301
306
  end
302
307
 
303
- assert File.exists?(path)
308
+ assert File.exist?(path)
304
309
  assert File.readable?(path)
305
310
  assert File.writable?(path)
306
311
  end
307
312
 
308
313
  def test_raises_ENOENT_trying_to_create_files_in_nonexistent_dir
309
- path = "/path/to/file.txt"
314
+ path = '/path/to/file.txt'
310
315
 
311
- assert_raises(Errno::ENOENT) {
316
+ assert_raises(Errno::ENOENT) do
312
317
  File.open(path, 'w') do |f|
313
- f.write "Yatta!"
318
+ f.write 'Yatta!'
314
319
  end
315
- }
320
+ end
316
321
  end
317
322
 
318
323
  def test_raises_ENOENT_trying_to_create_files_in_relative_nonexistent_dir
319
- FileUtils.mkdir_p "/some/path"
324
+ FileUtils.mkdir_p '/some/path'
320
325
 
321
- Dir.chdir("/some/path") {
322
- assert_raises(Errno::ENOENT) {
323
- File.open("../foo") {|f| f.write "moo" }
324
- }
325
- }
326
+ Dir.chdir('/some/path') do
327
+ assert_raises(Errno::ENOENT) do
328
+ File.open('../foo') { |f| f.write 'moo' }
329
+ end
330
+ end
326
331
  end
327
332
 
328
333
  def test_raises_ENOENT_trying_to_create_files_in_obscured_nonexistent_dir
329
- FileUtils.mkdir_p "/some/path"
334
+ FileUtils.mkdir_p '/some/path'
330
335
 
331
- assert_raises(Errno::ENOENT) {
332
- File.open("/some/path/../foo") {|f| f.write "moo" }
333
- }
336
+ assert_raises(Errno::ENOENT) do
337
+ File.open('/some/path/../foo') { |f| f.write 'moo' }
338
+ end
334
339
  end
335
340
 
336
341
  def test_raises_ENOENT_trying_to_create_tilde_referenced_nonexistent_dir
337
- path = "~/fakefs_test_#{$$}_0000"
342
+ path = "~/fakefs_test_#{$PID}_0000"
338
343
 
339
- while File.exist? path
340
- path = path.succ
341
- end
344
+ path = path.succ while File.exist? path
342
345
 
343
- assert_raises(Errno::ENOENT) {
344
- File.open("#{path}/foo") {|f| f.write "moo" }
345
- }
346
+ assert_raises(Errno::ENOENT) do
347
+ File.open("#{path}/foo") { |f| f.write 'moo' }
348
+ end
346
349
  end
347
350
 
348
351
  def test_raises_EISDIR_if_trying_to_open_existing_directory_name
349
- path = "/path/to"
352
+ path = '/path/to'
350
353
 
351
354
  FileUtils.mkdir_p path
352
355
 
353
- assert_raises(Errno::EISDIR) {
356
+ assert_raises(Errno::EISDIR) do
354
357
  File.open(path, 'w') do |f|
355
- f.write "Yatta!"
358
+ f.write 'Yatta!'
356
359
  end
357
- }
360
+ end
358
361
  end
359
362
 
360
363
  def test_can_create_files_with_bitmasks
361
- FileUtils.mkdir_p("/path/to")
364
+ FileUtils.mkdir_p('/path/to')
362
365
 
363
366
  path = '/path/to/file.txt'
364
367
  File.open(path, File::RDWR | File::CREAT) do |f|
365
- f.write "Yatta!"
368
+ f.write 'Yatta!'
366
369
  end
367
370
 
368
- assert File.exists?(path)
371
+ assert File.exist?(path)
369
372
  assert File.readable?(path)
370
373
  assert File.writable?(path)
371
374
  end
372
375
 
373
376
  def test_file_opens_in_read_only_mode
374
- File.open("foo", "w") { |f| f << "foo" }
377
+ File.open('foo', 'w') { |f| f << 'foo' }
375
378
 
376
- f = File.open("foo")
379
+ f = File.open('foo')
377
380
 
378
381
  assert_raises(IOError) do
379
- f << "bar"
382
+ f << 'bar'
380
383
  end
381
384
  end
382
385
 
383
386
  def test_file_opens_in_read_only_mode_with_bitmasks
384
- File.open("foo", "w") { |f| f << "foo" }
387
+ File.open('foo', 'w') { |f| f << 'foo' }
385
388
 
386
- f = File.open("foo", File::RDONLY)
389
+ f = File.open('foo', File::RDONLY)
387
390
 
388
391
  assert_raises(IOError) do
389
- f << "bar"
392
+ f << 'bar'
390
393
  end
391
394
  end
392
395
 
393
396
  def test_file_opens_in_invalid_mode
394
- FileUtils.touch("foo")
397
+ FileUtils.touch('foo')
395
398
 
396
399
  assert_raises(ArgumentError) do
397
- File.open("foo", "an_illegal_mode")
400
+ File.open('foo', 'an_illegal_mode')
398
401
  end
399
402
  end
400
403
 
401
404
  def test_raises_error_when_cannot_find_file_in_read_mode
402
405
  assert_raises(Errno::ENOENT) do
403
- File.open("does_not_exist", "r")
406
+ File.open('does_not_exist', 'r')
404
407
  end
405
408
  end
406
409
 
407
410
  def test_raises_error_when_cannot_find_file_in_read_write_mode
408
411
  assert_raises(Errno::ENOENT) do
409
- File.open("does_not_exist", "r+")
412
+ File.open('does_not_exist', 'r+')
410
413
  end
411
414
  end
412
415
 
413
416
  def test_creates_files_in_write_only_mode
414
- File.open("foo", "w")
415
- assert File.exists?("foo")
417
+ File.open('foo', 'w')
418
+ assert File.exist?('foo')
416
419
  end
417
420
 
418
421
  def test_creates_files_in_write_only_mode_with_bitmasks
419
- File.open("foo", File::WRONLY | File::CREAT)
420
- assert File.exists?("foo")
422
+ File.open('foo', File::WRONLY | File::CREAT)
423
+ assert File.exist?('foo')
421
424
  end
422
425
 
423
426
  def test_raises_in_write_only_mode_without_create_bitmask
424
427
  assert_raises(Errno::ENOENT) do
425
- File.open("foo", File::WRONLY)
428
+ File.open('foo', File::WRONLY)
426
429
  end
427
430
  end
428
431
 
429
432
  def test_creates_files_in_read_write_truncate_mode
430
- File.open("foo", "w+")
431
- assert File.exists?("foo")
433
+ File.open('foo', 'w+')
434
+ assert File.exist?('foo')
432
435
  end
433
436
 
434
437
  def test_creates_files_in_append_write_only
435
- File.open("foo", "a")
436
- assert File.exists?("foo")
438
+ File.open('foo', 'a')
439
+ assert File.exist?('foo')
437
440
  end
438
441
 
439
442
  def test_creates_files_in_append_read_write
440
- File.open("foo", "a+")
441
- assert File.exists?("foo")
443
+ File.open('foo', 'a+')
444
+ assert File.exist?('foo')
442
445
  end
443
446
 
444
447
  def test_file_in_write_only_raises_error_when_reading
445
- FileUtils.touch("foo")
448
+ FileUtils.touch('foo')
446
449
 
447
- f = File.open("foo", "w")
450
+ f = File.open('foo', 'w')
448
451
 
449
452
  assert_raises(IOError) do
450
453
  f.read
@@ -452,25 +455,21 @@ class FakeFSTest < Test::Unit::TestCase
452
455
  end
453
456
 
454
457
  def test_file_in_write_mode_truncates_existing_file
455
- File.open("foo", "w") { |f| f << "contents" }
456
-
457
- f = File.open("foo", "w")
458
-
459
- assert_equal "", File.read("foo")
458
+ File.open('foo', 'w') { |f| f << 'contents' }
459
+ File.open('foo', 'w')
460
+ assert_equal '', File.read('foo')
460
461
  end
461
462
 
462
463
  def test_file_in_read_write_truncation_mode_truncates_file
463
- File.open("foo", "w") { |f| f << "foo" }
464
-
465
- f = File.open("foo", "w+")
466
-
467
- assert_equal "", File.read("foo")
464
+ File.open('foo', 'w') { |f| f << 'foo' }
465
+ File.open('foo', 'w+')
466
+ assert_equal '', File.read('foo')
468
467
  end
469
468
 
470
469
  def test_file_in_append_write_only_raises_error_when_reading
471
- FileUtils.touch("foo")
470
+ FileUtils.touch('foo')
472
471
 
473
- f = File.open("foo", "a")
472
+ f = File.open('foo', 'a')
474
473
 
475
474
  assert_raises(IOError) do
476
475
  f.read
@@ -480,10 +479,10 @@ class FakeFSTest < Test::Unit::TestCase
480
479
  def test_can_read_files_once_written
481
480
  path = 'file.txt'
482
481
  File.open(path, 'w') do |f|
483
- f.write "Yatta!"
482
+ f.write 'Yatta!'
484
483
  end
485
484
 
486
- assert_equal "Yatta!", File.read(path)
485
+ assert_equal 'Yatta!', File.read(path)
487
486
  end
488
487
 
489
488
  def test_file_read_accepts_hashes
@@ -492,7 +491,7 @@ class FakeFSTest < Test::Unit::TestCase
492
491
  f.write 'Yatta!'
493
492
  end
494
493
 
495
- assert_nothing_raised { File.read(path, :mode => 'r:UTF-8:-') }
494
+ assert_nothing_raised { File.read(path, mode: 'r:UTF-8:-') }
496
495
  end
497
496
 
498
497
  def test_file_read_respects_args
@@ -516,17 +515,17 @@ class FakeFSTest < Test::Unit::TestCase
516
515
 
517
516
  def test_raises_error_when_opening_with_binary_mode_only
518
517
  assert_raise ArgumentError do
519
- File.open("/foo", "b")
518
+ File.open('/foo', 'b')
520
519
  end
521
520
  end
522
521
 
523
522
  def test_can_open_file_in_binary_mode
524
- File.open("foo", "wb") { |x| x << "a" }
525
- assert_equal "a", File.read("foo")
523
+ File.open('foo', 'wb') { |x| x << 'a' }
524
+ assert_equal 'a', File.read('foo')
526
525
  end
527
526
 
528
527
  def test_can_chunk_io_when_reading
529
- FileUtils.mkdir_p "/path/to"
528
+ FileUtils.mkdir_p '/path/to'
530
529
  path = '/path/to/file.txt'
531
530
  File.open(path, 'w') do |f|
532
531
  f << 'Yada Yada'
@@ -550,7 +549,7 @@ class FakeFSTest < Test::Unit::TestCase
550
549
  def test_can_get_correct_size_for_files_with_multibyte_characters
551
550
  path = 'file.txt'
552
551
  File.open(path, 'wb') do |f|
553
- f << "Y\xC3\xA1da" # Yáda
552
+ f << "Y\xC3\xA1da"
554
553
  end
555
554
  assert_equal 5, File.size(path)
556
555
  end
@@ -561,7 +560,7 @@ class FakeFSTest < Test::Unit::TestCase
561
560
  f << 'Yada Yada'
562
561
  end
563
562
  assert_equal 9, File.size?(path)
564
- assert_nil File.size?("other.txt")
563
+ assert_nil File.size?('other.txt')
565
564
  end
566
565
 
567
566
  def test_can_check_size_of_empty_file
@@ -569,7 +568,7 @@ class FakeFSTest < Test::Unit::TestCase
569
568
  File.open(path, 'w') do |f|
570
569
  f << ''
571
570
  end
572
- assert_nil File.size?("file.txt")
571
+ assert_nil File.size?('file.txt')
573
572
  end
574
573
 
575
574
  def test_zero_on_empty_file
@@ -599,21 +598,21 @@ class FakeFSTest < Test::Unit::TestCase
599
598
  end
600
599
  end
601
600
 
602
- if RUBY_VERSION >= "1.9"
601
+ if RUBY_VERSION >= '1.9'
603
602
  def test_can_set_mtime_on_new_file_touch_with_param
604
- time = Time.new(2002, 10, 31, 2, 2, 2, "+02:00")
605
- FileUtils.touch("foo.txt", :mtime => time)
603
+ time = Time.new(2002, 10, 31, 2, 2, 2, '+02:00')
604
+ FileUtils.touch('foo.txt', mtime: time)
606
605
 
607
- assert_equal File.mtime("foo.txt"), time
606
+ assert_equal File.mtime('foo.txt'), time
608
607
  end
609
608
 
610
609
  def test_can_set_mtime_on_existing_file_touch_with_param
611
- FileUtils.touch("foo.txt")
610
+ FileUtils.touch('foo.txt')
612
611
 
613
- time = Time.new(2002, 10, 31, 2, 2, 2, "+02:00")
614
- FileUtils.touch("foo.txt", :mtime => time)
612
+ time = Time.new(2002, 10, 31, 2, 2, 2, '+02:00')
613
+ FileUtils.touch('foo.txt', mtime: time)
615
614
 
616
- assert_equal File.mtime("foo.txt"), time
615
+ assert_equal File.mtime('foo.txt'), time
617
616
  end
618
617
  end
619
618
 
@@ -632,7 +631,7 @@ class FakeFSTest < Test::Unit::TestCase
632
631
  end
633
632
 
634
633
  def test_can_return_ctime_on_existing_file
635
- File.open("foo", "w") { |f| f << "some content" }
634
+ File.open('foo', 'w') { |f| f << 'some content' }
636
635
  assert File.ctime('foo').is_a?(Time)
637
636
  end
638
637
 
@@ -643,23 +642,23 @@ class FakeFSTest < Test::Unit::TestCase
643
642
  end
644
643
 
645
644
  def test_can_return_atime_on_existing_file
646
- File.open("foo", "w") { |f| f << "some content" }
645
+ File.open('foo', 'w') { |f| f << 'some content' }
647
646
  assert File.atime('foo').is_a?(Time)
648
647
  end
649
648
 
650
649
  def test_ctime_mtime_and_atime_are_equal_for_new_files
651
650
  FileUtils.touch('foo')
652
651
 
653
- ctime = File.ctime("foo")
654
- mtime = File.mtime("foo")
655
- atime = File.atime("foo")
652
+ ctime = File.ctime('foo')
653
+ mtime = File.mtime('foo')
654
+ atime = File.atime('foo')
656
655
  assert ctime.is_a?(Time)
657
656
  assert mtime.is_a?(Time)
658
657
  assert atime.is_a?(Time)
659
658
  assert_equal ctime, mtime
660
659
  assert_equal ctime, atime
661
660
 
662
- File.open("foo", "r") do |f|
661
+ File.open('foo', 'r') do |f|
663
662
  assert_equal ctime, f.ctime
664
663
  assert_equal mtime, f.mtime
665
664
  assert_equal atime, f.atime
@@ -667,10 +666,10 @@ class FakeFSTest < Test::Unit::TestCase
667
666
  end
668
667
 
669
668
  def test_ctime_mtime_and_atime_are_equal_for_new_directories
670
- FileUtils.mkdir_p("foo")
671
- ctime = File.ctime("foo")
672
- mtime = File.mtime("foo")
673
- atime = File.atime("foo")
669
+ FileUtils.mkdir_p('foo')
670
+ ctime = File.ctime('foo')
671
+ mtime = File.mtime('foo')
672
+ atime = File.atime('foo')
674
673
  assert ctime.is_a?(Time)
675
674
  assert mtime.is_a?(Time)
676
675
  assert atime.is_a?(Time)
@@ -679,33 +678,33 @@ class FakeFSTest < Test::Unit::TestCase
679
678
  end
680
679
 
681
680
  def test_file_ctime_is_equal_to_file_stat_ctime
682
- File.open("foo", "w") { |f| f << "some content" }
683
- assert_equal File.stat("foo").ctime, File.ctime("foo")
681
+ File.open('foo', 'w') { |f| f << 'some content' }
682
+ assert_equal File.stat('foo').ctime, File.ctime('foo')
684
683
  end
685
684
 
686
685
  def test_directory_ctime_is_equal_to_directory_stat_ctime
687
- FileUtils.mkdir_p("foo")
688
- assert_equal File.stat("foo").ctime, File.ctime("foo")
686
+ FileUtils.mkdir_p('foo')
687
+ assert_equal File.stat('foo').ctime, File.ctime('foo')
689
688
  end
690
689
 
691
690
  def test_file_mtime_is_equal_to_file_stat_mtime
692
- File.open("foo", "w") { |f| f << "some content" }
693
- assert_equal File.stat("foo").mtime, File.mtime("foo")
691
+ File.open('foo', 'w') { |f| f << 'some content' }
692
+ assert_equal File.stat('foo').mtime, File.mtime('foo')
694
693
  end
695
694
 
696
695
  def test_directory_mtime_is_equal_to_directory_stat_mtime
697
- FileUtils.mkdir_p("foo")
698
- assert_equal File.stat("foo").mtime, File.mtime("foo")
696
+ FileUtils.mkdir_p('foo')
697
+ assert_equal File.stat('foo').mtime, File.mtime('foo')
699
698
  end
700
699
 
701
700
  def test_file_atime_is_equal_to_file_stat_atime
702
- File.open("foo", "w") { |f| f << "some content" }
703
- assert_equal File.stat("foo").atime, File.atime("foo")
701
+ File.open('foo', 'w') { |f| f << 'some content' }
702
+ assert_equal File.stat('foo').atime, File.atime('foo')
704
703
  end
705
704
 
706
705
  def test_directory_atime_is_equal_to_directory_stat_atime
707
- FileUtils.mkdir_p("foo")
708
- assert_equal File.stat("foo").atime, File.atime("foo")
706
+ FileUtils.mkdir_p('foo')
707
+ assert_equal File.stat('foo').atime, File.atime('foo')
709
708
  end
710
709
 
711
710
  def test_utime_raises_error_if_path_does_not_exist
@@ -738,9 +737,9 @@ class FakeFSTest < Test::Unit::TestCase
738
737
  def test_file_a_time_updated_when_file_is_read
739
738
  old_atime = Time.now - 300
740
739
 
741
- path = "file.txt"
742
- File.open(path, "w") do |f|
743
- f << "Hello"
740
+ path = 'file.txt'
741
+ File.open(path, 'w') do |f|
742
+ f << 'Hello'
744
743
  end
745
744
 
746
745
  File.utime(old_atime, File.mtime(path), path)
@@ -753,8 +752,8 @@ class FakeFSTest < Test::Unit::TestCase
753
752
  def test_can_read_with_File_readlines
754
753
  path = 'file.txt'
755
754
  File.open(path, 'w') do |f|
756
- f.puts "Yatta!", "Gatta!"
757
- f.puts ["woot","toot"]
755
+ f.puts 'Yatta!', 'Gatta!'
756
+ f.puts %w(woot toot)
758
757
  end
759
758
 
760
759
  assert_equal ["Yatta!\n", "Gatta!\n", "woot\n", "toot\n"], File.readlines(path)
@@ -794,55 +793,54 @@ class FakeFSTest < Test::Unit::TestCase
794
793
  file.write 'Yada'
795
794
  file.close
796
795
  assert_raise IOError do
797
- file << "foo"
796
+ file << 'foo'
798
797
  end
799
798
  end
800
799
 
801
800
  def test_can_read_from_file_objects
802
801
  path = 'file.txt'
803
802
  File.open(path, 'w') do |f|
804
- f.write "Yatta!"
803
+ f.write 'Yatta!'
805
804
  end
806
805
 
807
- assert_equal "Yatta!", File.new(path).read
806
+ assert_equal 'Yatta!', File.new(path).read
808
807
  end
809
808
 
810
- if RUBY_VERSION >= "1.9"
809
+ if RUBY_VERSION >= '1.9'
811
810
  def test_file_object_has_default_external_encoding
812
- Encoding.default_external = "UTF-8"
811
+ Encoding.default_external = 'UTF-8'
813
812
  path = 'file.txt'
814
- File.open(path, 'w'){|f| f.write 'Yatta!' }
815
- assert_equal "UTF-8", File.new(path).read.encoding.name
813
+ File.open(path, 'w') { |f| f.write 'Yatta!' }
814
+ assert_equal 'UTF-8', File.new(path).read.encoding.name
816
815
  end
817
816
  end
818
817
 
819
818
  def test_file_object_initialization_with_mode_in_hash_parameter
820
819
  assert_nothing_raised do
821
- File.open("file.txt", {:mode => "w"}){ |f| f.write 'Yatta!' }
820
+ File.open('file.txt', mode: 'w') { |f| f.write 'Yatta!' }
822
821
  end
823
822
  end
824
823
 
825
824
  def test_file_object_initialization_with_brackets_in_filename
826
- filename = "bracket[1](2).txt"
827
- expected_contents = "Yokudekimashita"
825
+ filename = 'bracket[1](2).txt'
826
+ expected_contents = 'Yokudekimashita'
828
827
  assert_nothing_raised do
829
- File.open(filename, {:mode => "w"}){ |f| f.write "#{expected_contents}" }
828
+ File.open(filename, mode: 'w') { |f| f.write "#{expected_contents}" }
830
829
  end
831
- the_file = Dir["/*"]
830
+ the_file = Dir['/*']
832
831
  assert_equal the_file.length, 1
833
832
  assert_equal the_file[0], "/#{filename}"
834
- contents = File.open("/#{filename}").read()
833
+ contents = File.open("/#{filename}").read
835
834
  assert_equal contents, expected_contents
836
835
  end
837
836
 
838
837
  def test_file_object_initialization_with_brackets_in_filename
839
- # 日本語
840
838
  filename = "\u65e5\u672c\u8a9e.txt"
841
- expected_contents = "Yokudekimashita"
839
+ expected_contents = 'Yokudekimashita'
842
840
  assert_nothing_raised do
843
- File.open(filename, {:mode => "w"}){ |f| f.write "#{expected_contents}" }
841
+ File.open(filename, mode: 'w') { |f| f.write "#{expected_contents}" }
844
842
  end
845
- contents = File.open("/#{filename}").read()
843
+ contents = File.open("/#{filename}").read
846
844
  assert_equal contents, expected_contents
847
845
  end
848
846
 
@@ -853,38 +851,38 @@ class FakeFSTest < Test::Unit::TestCase
853
851
  end
854
852
 
855
853
  def test_file_read_errors_on_directory
856
- FileUtils.mkdir_p("a_directory")
854
+ FileUtils.mkdir_p('a_directory')
857
855
 
858
856
  assert_raise Errno::EISDIR do
859
- File.read("a_directory")
857
+ File.read('a_directory')
860
858
  end
861
859
  end
862
860
 
863
861
  def test_knows_files_are_files
864
862
  path = 'file.txt'
865
863
  File.open(path, 'w') do |f|
866
- f.write "Yatta!"
864
+ f.write 'Yatta!'
867
865
  end
868
866
 
869
867
  assert File.file?(path)
870
868
  end
871
869
 
872
870
  def test_File_io_returns_self
873
- f = File.open("foo", "w")
871
+ f = File.open('foo', 'w')
874
872
  assert_equal f, f.to_io
875
873
  end
876
874
 
877
875
  def test_File_to_i_is_alias_for_filno
878
- f = File.open("foo", "w")
876
+ f = File.open('foo', 'w')
879
877
  assert_equal f.method(:to_i), f.method(:fileno)
880
878
  end
881
879
 
882
880
  def test_knows_symlink_files_are_files
883
881
  path = 'file.txt'
884
882
  File.open(path, 'w') do |f|
885
- f.write "Yatta!"
883
+ f.write 'Yatta!'
886
884
  end
887
- FileUtils.ln_s path, sympath='/sympath'
885
+ FileUtils.ln_s path, sympath = '/sympath'
888
886
 
889
887
  assert File.file?(sympath)
890
888
  end
@@ -900,16 +898,16 @@ class FakeFSTest < Test::Unit::TestCase
900
898
  def test_can_chown_files
901
899
  good = 'file.txt'
902
900
  bad = 'nofile.txt'
903
- File.open(good,'w') { |f| f.write "foo" }
901
+ File.open(good, 'w') { |f| f.write 'foo' }
904
902
  username = Etc.getpwuid(Process.uid).name
905
903
  groupname = Etc.getgrgid(Process.gid).name
906
904
 
907
- out = FileUtils.chown(1337, 1338, good, :verbose => true)
905
+ out = FileUtils.chown(1337, 1338, good, verbose: true)
908
906
  assert_equal [good], out
909
907
  assert_equal File.stat(good).uid, 1337
910
908
  assert_equal File.stat(good).gid, 1338
911
909
  assert_raises(Errno::ENOENT) do
912
- FileUtils.chown(username, groupname, bad, :verbose => true)
910
+ FileUtils.chown(username, groupname, bad, verbose: true)
913
911
  end
914
912
 
915
913
  assert_equal [good], FileUtils.chown(username, groupname, good)
@@ -952,11 +950,11 @@ class FakeFSTest < Test::Unit::TestCase
952
950
  end
953
951
 
954
952
  def test_can_chmod_files
955
- good = "file.txt"
956
- bad = "nofile.txt"
953
+ good = 'file.txt'
954
+ bad = 'nofile.txt'
957
955
  FileUtils.touch(good)
958
956
 
959
- assert_equal [good], FileUtils.chmod(0600, good, :verbose => true)
957
+ assert_equal [good], FileUtils.chmod(0600, good, verbose: true)
960
958
  assert_equal File.stat(good).mode, 0100600
961
959
  assert_equal File.executable?(good), false
962
960
  assert_raises(Errno::ENOENT) do
@@ -985,19 +983,19 @@ class FakeFSTest < Test::Unit::TestCase
985
983
  end
986
984
 
987
985
  def test_can_chmod_R_files
988
- FileUtils.mkdir_p "/path/sub"
989
- FileUtils.touch "/path/file1"
990
- FileUtils.touch "/path/sub/file2"
986
+ FileUtils.mkdir_p '/path/sub'
987
+ FileUtils.touch '/path/file1'
988
+ FileUtils.touch '/path/sub/file2'
991
989
 
992
- assert_equal ["/path"], FileUtils.chmod_R(0600, "/path")
993
- assert_equal File.stat("/path").mode, 0100600
994
- assert_equal File.stat("/path/file1").mode, 0100600
995
- assert_equal File.stat("/path/sub").mode, 0100600
996
- assert_equal File.stat("/path/sub/file2").mode, 0100600
990
+ assert_equal ['/path'], FileUtils.chmod_R(0600, '/path')
991
+ assert_equal File.stat('/path').mode, 0100600
992
+ assert_equal File.stat('/path/file1').mode, 0100600
993
+ assert_equal File.stat('/path/sub').mode, 0100600
994
+ assert_equal File.stat('/path/sub/file2').mode, 0100600
997
995
 
998
- FileUtils.mkdir_p "/path2"
999
- FileUtils.touch "/path2/hej"
1000
- assert_equal ["/path2"], FileUtils.chmod_R(0600, "/path2")
996
+ FileUtils.mkdir_p '/path2'
997
+ FileUtils.touch '/path2/hej'
998
+ assert_equal ['/path2'], FileUtils.chmod_R(0600, '/path2')
1001
999
  end
1002
1000
 
1003
1001
  def test_dir_globs_paths
@@ -1010,7 +1008,7 @@ class FakeFSTest < Test::Unit::TestCase
1010
1008
 
1011
1009
  FileUtils.cp_r '/path/bar', '/path/bar2'
1012
1010
 
1013
- assert_equal ['/path'], Dir['/path']
1011
+ assert_equal ['/path'], Dir['/path']
1014
1012
  assert_equal %w( /path/bar /path/bar2 /path/foo /path/foobar ), Dir['/path/*']
1015
1013
 
1016
1014
  assert_equal ['/path/bar/baz'], Dir['/path/bar/*']
@@ -1043,30 +1041,30 @@ class FakeFSTest < Test::Unit::TestCase
1043
1041
  end
1044
1042
 
1045
1043
  def test_file_utils_cp_allows_verbose_option
1046
- File.open('foo', 'w') {|f| f << 'TEST' }
1047
- assert_equal "cp foo bar\n", capture_stderr { FileUtils.cp 'foo', 'bar', :verbose => true }
1044
+ File.open('foo', 'w') { |f| f << 'TEST' }
1045
+ assert_equal "cp foo bar\n", capture_stderr { FileUtils.cp 'foo', 'bar', verbose: true }
1048
1046
  end
1049
1047
 
1050
1048
  def test_file_utils_cp_allows_noop_option
1051
- File.open('foo', 'w') {|f| f << 'TEST' }
1052
- FileUtils.cp 'foo', 'bar', :noop => true
1049
+ File.open('foo', 'w') { |f| f << 'TEST' }
1050
+ FileUtils.cp 'foo', 'bar', noop: true
1053
1051
  assert !File.exist?('bar'), 'does not actually copy'
1054
1052
  end
1055
1053
 
1056
1054
  def test_file_utils_cp_raises_on_invalid_option
1057
1055
  assert_raises ArgumentError do
1058
- FileUtils.cp 'foo', 'bar', :whatisthis => "I don't know"
1056
+ FileUtils.cp 'foo', 'bar', whatisthis: "I don't know"
1059
1057
  end
1060
1058
  end
1061
1059
 
1062
1060
  def test_file_utils_cp_r_allows_verbose_option
1063
- FileUtils.touch "/foo"
1064
- assert_equal "cp -r /foo /bar\n", capture_stderr { FileUtils.cp_r '/foo', '/bar', :verbose => true }
1061
+ FileUtils.touch '/foo'
1062
+ assert_equal "cp -r /foo /bar\n", capture_stderr { FileUtils.cp_r '/foo', '/bar', verbose: true }
1065
1063
  end
1066
1064
 
1067
1065
  def test_file_utils_cp_r_allows_noop_option
1068
- FileUtils.touch "/foo"
1069
- FileUtils.cp_r '/foo', '/bar', :noop => true
1066
+ FileUtils.touch '/foo'
1067
+ FileUtils.cp_r '/foo', '/bar', noop: true
1070
1068
  assert !File.exist?('/bar'), 'does not actually copy'
1071
1069
  end
1072
1070
 
@@ -1078,12 +1076,12 @@ class FakeFSTest < Test::Unit::TestCase
1078
1076
  end
1079
1077
 
1080
1078
  def test_dir_glob_takes_optional_flags
1081
- FileUtils.touch "/foo"
1082
- assert_equal Dir.glob("/*", 0), ["/foo"]
1079
+ FileUtils.touch '/foo'
1080
+ assert_equal Dir.glob('/*', 0), ['/foo']
1083
1081
  end
1084
1082
 
1085
1083
  def test_dir_glob_handles_recursive_globs
1086
- FileUtils.mkdir_p "/one/two/three"
1084
+ FileUtils.mkdir_p '/one/two/three'
1087
1085
  File.open('/one/two/three/four.rb', 'w')
1088
1086
  File.open('/one/five.rb', 'w')
1089
1087
  assert_equal ['/one/five.rb', '/one/two/three/four.rb'], Dir['/one/**/*.rb']
@@ -1092,7 +1090,7 @@ class FakeFSTest < Test::Unit::TestCase
1092
1090
  end
1093
1091
 
1094
1092
  def test_dir_recursive_glob_ending_in_wildcards_returns_both_files_and_dirs
1095
- FileUtils.mkdir_p "/one/two/three"
1093
+ FileUtils.mkdir_p '/one/two/three'
1096
1094
  File.open('/one/two/three/four.rb', 'w')
1097
1095
  File.open('/one/five.rb', 'w')
1098
1096
  assert_equal ['/one/five.rb', '/one/two', '/one/two/three', '/one/two/three/four.rb'], Dir['/one/**/*']
@@ -1100,9 +1098,9 @@ class FakeFSTest < Test::Unit::TestCase
1100
1098
  end
1101
1099
 
1102
1100
  def test_dir_glob_ending_in_group_and_wildcard
1103
- FileUtils.mkdir_p "/tmp/python-3.4.1"
1104
- FileUtils.mkdir_p "/tmp/python-2.7.8"
1105
- assert_equal ['/tmp/python-2.7.8', '/tmp/python-3.4.1'], Dir.glob("/tmp/python-[0-9]*")
1101
+ FileUtils.mkdir_p '/tmp/python-3.4.1'
1102
+ FileUtils.mkdir_p '/tmp/python-2.7.8'
1103
+ assert_equal ['/tmp/python-2.7.8', '/tmp/python-3.4.1'], Dir.glob('/tmp/python-[0-9]*')
1106
1104
  end
1107
1105
 
1108
1106
  def test_dir_glob_with_block
@@ -1116,24 +1114,24 @@ class FakeFSTest < Test::Unit::TestCase
1116
1114
  end
1117
1115
 
1118
1116
  def test_copy_with_subdirectory
1119
- FileUtils.mkdir_p "/one/two/three/"
1120
- FileUtils.mkdir_p "/onebis/two/three/"
1121
- FileUtils.touch "/one/two/three/foo"
1122
- Dir.glob("/one/two/three/*") do |hook|
1123
- FileUtils.cp(hook, "/onebis/two/three/")
1117
+ FileUtils.mkdir_p '/one/two/three/'
1118
+ FileUtils.mkdir_p '/onebis/two/three/'
1119
+ FileUtils.touch '/one/two/three/foo'
1120
+ Dir.glob('/one/two/three/*') do |hook|
1121
+ FileUtils.cp(hook, '/onebis/two/three/')
1124
1122
  end
1125
1123
  assert_equal ['/onebis/two/three/foo'], Dir['/onebis/two/three/*']
1126
1124
  end
1127
1125
 
1128
- if RUBY_VERSION >= "1.9"
1126
+ if RUBY_VERSION >= '1.9'
1129
1127
  def test_dir_home
1130
1128
  assert_equal RealDir.home, Dir.home
1131
1129
  end
1132
1130
  end
1133
1131
 
1134
1132
  def test_should_report_pos_as_0_when_opening
1135
- File.open("foo", "w") do |f|
1136
- f << "foobar"
1133
+ File.open('foo', 'w') do |f|
1134
+ f << 'foobar'
1137
1135
  f.rewind
1138
1136
 
1139
1137
  assert_equal 0, f.pos
@@ -1141,8 +1139,8 @@ class FakeFSTest < Test::Unit::TestCase
1141
1139
  end
1142
1140
 
1143
1141
  def test_should_report_pos_as_1_when_seeking_one_char
1144
- File.open("foo", "w") do |f|
1145
- f << "foobar"
1142
+ File.open('foo', 'w') do |f|
1143
+ f << 'foobar'
1146
1144
 
1147
1145
  f.rewind
1148
1146
  f.seek(1)
@@ -1152,22 +1150,22 @@ class FakeFSTest < Test::Unit::TestCase
1152
1150
  end
1153
1151
 
1154
1152
  def test_should_set_pos
1155
- File.open("foo", "w") do |f|
1156
- f << "foo"
1153
+ File.open('foo', 'w') do |f|
1154
+ f << 'foo'
1157
1155
  end
1158
1156
 
1159
- fp = File.open("foo", "r")
1157
+ fp = File.open('foo', 'r')
1160
1158
  fp.pos = 1
1161
1159
 
1162
1160
  assert_equal 1, fp.pos
1163
1161
  end
1164
1162
 
1165
1163
  def test_should_set_pos_with_tell_method
1166
- File.open("foo", "w") do |f|
1167
- f << "foo"
1164
+ File.open('foo', 'w') do |f|
1165
+ f << 'foo'
1168
1166
  end
1169
1167
 
1170
- fp = File.open("foo", "r")
1168
+ fp = File.open('foo', 'r')
1171
1169
  fp.tell = 1
1172
1170
 
1173
1171
  assert_equal 1, fp.pos
@@ -1196,12 +1194,12 @@ class FakeFSTest < Test::Unit::TestCase
1196
1194
  end
1197
1195
 
1198
1196
  def test_does_not_remove_methods_from_stringio
1199
- stringio = StringIO.new("foo")
1197
+ stringio = StringIO.new('foo')
1200
1198
  assert stringio.respond_to?(:size)
1201
1199
  end
1202
1200
 
1203
1201
  def test_is_not_a_stringio
1204
- File.open("foo", "w") do |f|
1202
+ File.open('foo', 'w') do |f|
1205
1203
  assert !f.is_a?(StringIO), 'File is not a StringIO'
1206
1204
  end
1207
1205
  end
@@ -1212,8 +1210,8 @@ class FakeFSTest < Test::Unit::TestCase
1212
1210
  assert_equal '/', FileSystem.fs.name
1213
1211
  assert_equal [], Dir.glob('/path/*')
1214
1212
  Dir.chdir '/path' do
1215
- File.open('foo', 'w') { |f| f.write 'foo'}
1216
- File.open('foobar', 'w') { |f| f.write 'foo'}
1213
+ File.open('foo', 'w') { |f| f.write 'foo' }
1214
+ File.open('foobar', 'w') { |f| f.write 'foo' }
1217
1215
  end
1218
1216
 
1219
1217
  assert_equal '/', FileSystem.fs.name
@@ -1231,8 +1229,8 @@ class FakeFSTest < Test::Unit::TestCase
1231
1229
  FileUtils.mkdir_p '/path'
1232
1230
 
1233
1231
  Dir.chdir '/path' do
1234
- File.open('foo', 'w') { |f| f.write 'foo'}
1235
- File.open('/foobar', 'w') { |f| f.write 'foo'}
1232
+ File.open('foo', 'w') { |f| f.write 'foo' }
1233
+ File.open('/foobar', 'w') { |f| f.write 'foo' }
1236
1234
  end
1237
1235
  assert_equal ['/path/foo'], Dir.glob('/path/*').sort
1238
1236
  assert_equal ['/foobar', '/path'], Dir.glob('/*').sort
@@ -1249,26 +1247,26 @@ class FakeFSTest < Test::Unit::TestCase
1249
1247
  def test_chdir_should_be_nestable
1250
1248
  FileUtils.mkdir_p '/path/me'
1251
1249
  Dir.chdir '/path' do
1252
- File.open('foo', 'w') { |f| f.write 'foo'}
1250
+ File.open('foo', 'w') { |f| f.write 'foo' }
1253
1251
  Dir.chdir 'me' do
1254
- File.open('foobar', 'w') { |f| f.write 'foo'}
1252
+ File.open('foobar', 'w') { |f| f.write 'foo' }
1255
1253
  end
1256
1254
  end
1257
1255
 
1258
- assert_equal ['/path/foo','/path/me'], Dir.glob('/path/*').sort
1256
+ assert_equal ['/path/foo', '/path/me'], Dir.glob('/path/*').sort
1259
1257
  assert_equal ['/path/me/foobar'], Dir.glob('/path/me/*').sort
1260
1258
  end
1261
1259
 
1262
1260
  def test_chdir_should_be_nestable_with_absolute_paths
1263
1261
  FileUtils.mkdir_p '/path/me'
1264
1262
  Dir.chdir '/path' do
1265
- File.open('foo', 'w') { |f| f.write 'foo'}
1263
+ File.open('foo', 'w') { |f| f.write 'foo' }
1266
1264
  Dir.chdir '/path/me' do
1267
- File.open('foobar', 'w') { |f| f.write 'foo'}
1265
+ File.open('foobar', 'w') { |f| f.write 'foo' }
1268
1266
  end
1269
1267
  end
1270
1268
 
1271
- assert_equal ['/path/foo','/path/me'], Dir.glob('/path/*').sort
1269
+ assert_equal ['/path/foo', '/path/me'], Dir.glob('/path/*').sort
1272
1270
  assert_equal ['/path/me/foobar'], Dir.glob('/path/me/*').sort
1273
1271
  end
1274
1272
 
@@ -1284,21 +1282,23 @@ class FakeFSTest < Test::Unit::TestCase
1284
1282
  FileUtils.mkdir_p '/path'
1285
1283
 
1286
1284
  Dir.chdir '/path' do
1287
- File.open('foo', 'w') { |f| f.write 'foo'}
1288
- File.open('foobar', 'w') { |f| f.write 'foo'}
1285
+ File.open('foo', 'w') { |f| f.write 'foo' }
1286
+ File.open('foobar', 'w') { |f| f.write 'foo' }
1289
1287
  end
1290
1288
 
1291
1289
  begin
1292
1290
  Dir.chdir('/path') do
1293
- raise Exception
1291
+ fail Errno::ENOENT
1294
1292
  end
1295
- rescue Exception # hardcore
1293
+ rescue Errno::ENOENT => e # hardcore
1294
+ 'Nothing to do'
1296
1295
  end
1297
1296
 
1298
1297
  Dir.chdir('/path') do
1299
1298
  begin
1300
- Dir.chdir('nope'){ }
1301
- rescue Errno::ENOENT
1299
+ Dir.chdir('nope') {}
1300
+ rescue Errno::ENOENT => e
1301
+ 'Nothing to do'
1302
1302
  end
1303
1303
 
1304
1304
  assert_equal ['/', '/path'], FileSystem.dir_levels
@@ -1313,7 +1313,7 @@ class FakeFSTest < Test::Unit::TestCase
1313
1313
  FileUtils.mkdir_p 'subdir'
1314
1314
  assert_equal ['subdir'], Dir.glob('*')
1315
1315
  Dir.chdir('subdir')
1316
- File.open('foo', 'w') { |f| f.write 'foo'}
1316
+ File.open('foo', 'w') { |f| f.write 'foo' }
1317
1317
  assert_equal ['foo'], Dir.glob('*')
1318
1318
 
1319
1319
  assert_raises(Errno::ENOENT) do
@@ -1353,9 +1353,9 @@ class FakeFSTest < Test::Unit::TestCase
1353
1353
 
1354
1354
  def test_expand_path_with_parent_dir
1355
1355
  FakeFS.deactivate!
1356
- real = File.expand_path('../other.file',__FILE__)
1356
+ real = File.expand_path('../other.file', __FILE__)
1357
1357
  FakeFS.activate!
1358
- fake = File.expand_path('../other.file',__FILE__)
1358
+ fake = File.expand_path('../other.file', __FILE__)
1359
1359
  assert_equal real, fake
1360
1360
  end
1361
1361
 
@@ -1368,12 +1368,15 @@ class FakeFSTest < Test::Unit::TestCase
1368
1368
  end
1369
1369
 
1370
1370
  def test_file_open_defaults_to_read
1371
- File.open('foo','w') { |f| f.write 'bar' }
1371
+ File.open('foo', 'w') { |f| f.write 'bar' }
1372
1372
  assert_equal 'bar', File.open('foo') { |f| f.read }
1373
1373
  end
1374
1374
 
1375
1375
  def test_flush_exists_on_file
1376
- r = File.open('foo','w') { |f| f.write 'bar'; f.flush }
1376
+ r = File.open('foo', 'w') do |f|
1377
+ f.write 'bar'
1378
+ f.flush
1379
+ end
1377
1380
  assert_equal 'foo', r.path
1378
1381
  end
1379
1382
 
@@ -1382,9 +1385,9 @@ class FakeFSTest < Test::Unit::TestCase
1382
1385
  FileUtils.mv 'blafgag', 'foo'
1383
1386
  end
1384
1387
  exception = assert_raise(Errno::ENOENT) do
1385
- FileUtils.mv ['foo', 'bar'], 'destdir'
1388
+ FileUtils.mv %w(foo bar), 'destdir'
1386
1389
  end
1387
- assert_equal "No such file or directory - foo", exception.message
1390
+ assert_equal 'No such file or directory - foo', exception.message
1388
1391
  end
1389
1392
 
1390
1393
  def test_mv_actually_works
@@ -1401,36 +1404,36 @@ class FakeFSTest < Test::Unit::TestCase
1401
1404
  end
1402
1405
 
1403
1406
  def test_mv_works_with_options
1404
- File.open('foo', 'w') {|f| f.write 'bar'}
1405
- FileUtils.mv 'foo', 'baz', :force => true
1407
+ File.open('foo', 'w') { |f| f.write 'bar' }
1408
+ FileUtils.mv 'foo', 'baz', force: true
1406
1409
  assert_equal('bar', File.open('baz') { |f| f.read })
1407
1410
  end
1408
1411
 
1409
1412
  def test_mv_to_directory
1410
- File.open('foo', 'w') {|f| f.write 'bar'}
1413
+ File.open('foo', 'w') { |f| f.write 'bar' }
1411
1414
  FileUtils.mkdir_p 'destdir'
1412
1415
  FileUtils.mv 'foo', 'destdir'
1413
- assert_equal('bar', File.open('destdir/foo') {|f| f.read })
1416
+ assert_equal('bar', File.open('destdir/foo') { |f| f.read })
1414
1417
  assert File.directory?('destdir')
1415
1418
  end
1416
1419
 
1417
1420
  def test_mv_array
1418
- File.open('foo', 'w') {|f| f.write 'bar' }
1419
- File.open('baz', 'w') {|f| f.write 'binky' }
1421
+ File.open('foo', 'w') { |f| f.write 'bar' }
1422
+ File.open('baz', 'w') { |f| f.write 'binky' }
1420
1423
  FileUtils.mkdir_p 'destdir'
1421
1424
  FileUtils.mv %w(foo baz), 'destdir'
1422
- assert_equal('bar', File.open('destdir/foo') {|f| f.read })
1423
- assert_equal('binky', File.open('destdir/baz') {|f| f.read })
1425
+ assert_equal('bar', File.open('destdir/foo') { |f| f.read })
1426
+ assert_equal('binky', File.open('destdir/baz') { |f| f.read })
1424
1427
  end
1425
1428
 
1426
1429
  def test_mv_accepts_verbose_option
1427
1430
  FileUtils.touch 'foo'
1428
- assert_equal "mv foo bar\n", capture_stderr { FileUtils.mv 'foo', 'bar', :verbose => true }
1431
+ assert_equal "mv foo bar\n", capture_stderr { FileUtils.mv 'foo', 'bar', verbose: true }
1429
1432
  end
1430
1433
 
1431
1434
  def test_mv_accepts_noop_option
1432
1435
  FileUtils.touch 'foo'
1433
- FileUtils.mv 'foo', 'bar', :noop => true
1436
+ FileUtils.mv 'foo', 'bar', noop: true
1434
1437
  assert File.exist?('foo'), 'does not remove src'
1435
1438
  assert !File.exist?('bar'), 'does not create target'
1436
1439
  end
@@ -1452,25 +1455,25 @@ class FakeFSTest < Test::Unit::TestCase
1452
1455
 
1453
1456
  def test_mv_ignores_failures_when_using_force
1454
1457
  FileUtils.mkdir_p 'dir/stuff'
1455
- FileUtils.touch %w[stuff other]
1456
- FileUtils.mv %w[stuff other], 'dir', :force => true
1458
+ FileUtils.touch %w(stuff other)
1459
+ FileUtils.mv %w(stuff other), 'dir', force: true
1457
1460
  assert File.exist?('stuff'), 'failed move remains where it was'
1458
1461
  assert File.exist?('dir/other'), 'successful one is moved'
1459
1462
  assert !File.exist?('other'), 'successful one is moved'
1460
1463
 
1461
- FileUtils.mv 'stuff', '/this/path/is/not/here', :force => true
1464
+ FileUtils.mv 'stuff', '/this/path/is/not/here', force: true
1462
1465
  assert File.exist?('stuff'), 'failed move remains where it was'
1463
1466
  assert !File.exist?('/this/path/is/not/here'), 'nothing is created for a failed move'
1464
1467
  end
1465
1468
 
1466
1469
  def test_cp_actually_works
1467
- File.open('foo', 'w') {|f| f.write 'bar' }
1470
+ File.open('foo', 'w') { |f| f.write 'bar' }
1468
1471
  FileUtils.cp('foo', 'baz')
1469
1472
  assert_equal 'bar', File.read('baz')
1470
1473
  end
1471
1474
 
1472
1475
  def test_cp_file_into_dir
1473
- File.open('foo', 'w') {|f| f.write 'bar' }
1476
+ File.open('foo', 'w') { |f| f.write 'bar' }
1474
1477
  FileUtils.mkdir_p 'baz'
1475
1478
 
1476
1479
  FileUtils.cp('foo', 'baz')
@@ -1493,12 +1496,12 @@ class FakeFSTest < Test::Unit::TestCase
1493
1496
  exception = assert_raise(Errno::ENOTDIR) do
1494
1497
  FileUtils.cp(%w(foo), 'baz')
1495
1498
  end
1496
- assert_equal "Not a directory - baz", exception.to_s
1499
+ assert_equal 'Not a directory - baz', exception.to_s
1497
1500
  end
1498
1501
 
1499
1502
  def test_cp_overwrites_dest_file
1500
- File.open('foo', 'w') {|f| f.write 'FOO' }
1501
- File.open('bar', 'w') {|f| f.write 'BAR' }
1503
+ File.open('foo', 'w') { |f| f.write 'FOO' }
1504
+ File.open('bar', 'w') { |f| f.write 'BAR' }
1502
1505
 
1503
1506
  FileUtils.cp('foo', 'bar')
1504
1507
  assert_equal 'FOO', File.read('bar')
@@ -1519,7 +1522,7 @@ class FakeFSTest < Test::Unit::TestCase
1519
1522
  end
1520
1523
 
1521
1524
  def test_copy_file_works
1522
- File.open('foo', 'w') {|f| f.write 'bar' }
1525
+ File.open('foo', 'w') { |f| f.write 'bar' }
1523
1526
  FileUtils.copy_file('foo', 'baz', :ignore_param_1, :ignore_param_2)
1524
1527
  assert_equal 'bar', File.read('baz')
1525
1528
  end
@@ -1541,7 +1544,7 @@ class FakeFSTest < Test::Unit::TestCase
1541
1544
 
1542
1545
  def test_cp_r_handles_copying_directories
1543
1546
  FileUtils.mkdir_p 'subdir'
1544
- Dir.chdir('subdir'){ File.open('foo', 'w') { |f| f.write 'footext' } }
1547
+ Dir.chdir('subdir') { File.open('foo', 'w') { |f| f.write 'footext' } }
1545
1548
 
1546
1549
  FileUtils.mkdir_p 'baz'
1547
1550
 
@@ -1603,18 +1606,18 @@ class FakeFSTest < Test::Unit::TestCase
1603
1606
 
1604
1607
  FileUtils.cp_r '/path/foo', '/path/bar'
1605
1608
 
1606
- assert File.exists?('/path/bar/baz')
1609
+ assert File.exist?('/path/bar/baz')
1607
1610
  FileUtils.rm_rf '/path/bar/baz'
1608
1611
  assert_equal %w( /path/bar/bar ), Dir['/path/bar/*']
1609
1612
  end
1610
1613
 
1611
1614
  def test_clone_clones_normal_files
1612
1615
  RealFile.open(here('foo'), 'w') { |f| f.write 'bar' }
1613
- assert !File.exists?(here('foo'))
1616
+ assert !File.exist?(here('foo'))
1614
1617
  FileSystem.clone(here('foo'))
1615
1618
  assert_equal 'bar', File.open(here('foo')) { |f| f.read }
1616
1619
  ensure
1617
- RealFile.unlink(here('foo')) if RealFile.exists?(here('foo'))
1620
+ RealFile.unlink(here('foo')) if RealFile.exist?(here('foo'))
1618
1621
  end
1619
1622
 
1620
1623
  def test_clone_clones_directories
@@ -1622,7 +1625,7 @@ class FakeFSTest < Test::Unit::TestCase
1622
1625
 
1623
1626
  FileSystem.clone(here('subdir'))
1624
1627
 
1625
- assert File.exists?(here('subdir')), 'subdir was cloned'
1628
+ assert File.exist?(here('subdir')), 'subdir was cloned'
1626
1629
  assert File.directory?(here('subdir')), 'subdir is a directory'
1627
1630
  ensure
1628
1631
  act_on_real_fs { RealFileUtils.rm_rf(here('subdir')) }
@@ -1631,7 +1634,7 @@ class FakeFSTest < Test::Unit::TestCase
1631
1634
  def test_clone_clones_dot_files_even_hard_to_find_ones
1632
1635
  act_on_real_fs { RealFileUtils.mkdir_p(here('subdir/.bar/baz/.quux/foo')) }
1633
1636
 
1634
- assert !File.exists?(here('subdir'))
1637
+ assert !File.exist?(here('subdir'))
1635
1638
 
1636
1639
  FileSystem.clone(here('subdir'))
1637
1640
  assert_equal ['.', '..', '.bar'], Dir.entries(here('subdir'))
@@ -1644,8 +1647,8 @@ class FakeFSTest < Test::Unit::TestCase
1644
1647
  act_on_real_fs { RealFileUtils.mkdir_p(here('subdir/.bar/baz/.quux/foo')) }
1645
1648
  FileUtils.mkdir_p '/path'
1646
1649
  Dir.chdir('/path')
1647
- FileSystem.clone(here('subdir'), "/foo")
1648
- assert Dir.glob "/foo/*"
1650
+ FileSystem.clone(here('subdir'), '/foo')
1651
+ assert Dir.glob '/foo/*'
1649
1652
  ensure
1650
1653
  act_on_real_fs { RealFileUtils.rm_rf(here('subdir')) }
1651
1654
  end
@@ -1653,10 +1656,10 @@ class FakeFSTest < Test::Unit::TestCase
1653
1656
  def test_clone_with_target_specified
1654
1657
  act_on_real_fs { RealFileUtils.mkdir_p(here('subdir/.bar/baz/.quux/foo')) }
1655
1658
 
1656
- assert !File.exists?(here('subdir'))
1659
+ assert !File.exist?(here('subdir'))
1657
1660
 
1658
1661
  FileSystem.clone(here('subdir'), here('subdir2'))
1659
- assert !File.exists?(here('subdir'))
1662
+ assert !File.exist?(here('subdir'))
1660
1663
  assert_equal ['.', '..', '.bar'], Dir.entries(here('subdir2'))
1661
1664
  assert_equal ['.', '..', 'foo'], Dir.entries(here('subdir2/.bar/baz/.quux'))
1662
1665
  ensure
@@ -1669,12 +1672,12 @@ class FakeFSTest < Test::Unit::TestCase
1669
1672
 
1670
1673
  act_on_real_fs do
1671
1674
  RealDir.mkdir(RealFile.dirname(original))
1672
- RealFile.open(original, 'w') {|f| f << 'stuff' }
1675
+ RealFile.open(original, 'w') { |f| f << 'stuff' }
1673
1676
  RealFileUtils.ln_s original, symlink
1674
1677
  assert RealFile.symlink?(symlink), 'real symlink is in place'
1675
1678
  end
1676
1679
 
1677
- assert !File.exists?(original), 'file does not already exist'
1680
+ assert !File.exist?(original), 'file does not already exist'
1678
1681
 
1679
1682
  FileSystem.clone(File.dirname(original))
1680
1683
  assert File.symlink?(symlink), 'symlinks are cloned as symlinks'
@@ -1691,12 +1694,12 @@ class FakeFSTest < Test::Unit::TestCase
1691
1694
 
1692
1695
  act_on_real_fs do
1693
1696
  RealFileUtils.mkdir_p(original)
1694
- RealFile.open(original_file, 'w') {|f| f << 'stuff' }
1697
+ RealFile.open(original_file, 'w') { |f| f << 'stuff' }
1695
1698
  RealFileUtils.ln_s original, symlink
1696
1699
  assert RealFile.symlink?(symlink), 'real symlink is in place'
1697
1700
  end
1698
1701
 
1699
- assert !File.exists?(original_file), 'file does not already exist'
1702
+ assert !File.exist?(original_file), 'file does not already exist'
1700
1703
 
1701
1704
  FileSystem.clone(File.dirname(original))
1702
1705
  assert File.symlink?(symlink), 'symlinks are cloned as symlinks'
@@ -1715,30 +1718,30 @@ class FakeFSTest < Test::Unit::TestCase
1715
1718
  end
1716
1719
 
1717
1720
  def test_file_can_read_from_symlinks
1718
- File.open('first', 'w') { |f| f.write '1'}
1721
+ File.open('first', 'w') { |f| f.write '1' }
1719
1722
  FileUtils.ln_s 'first', 'one'
1720
1723
  assert_equal '1', File.open('one') { |f| f.read }
1721
1724
 
1722
1725
  FileUtils.mkdir_p 'subdir'
1723
- File.open('subdir/nother','w') { |f| f.write 'works' }
1726
+ File.open('subdir/nother', 'w') { |f| f.write 'works' }
1724
1727
  FileUtils.ln_s 'subdir', 'new'
1725
1728
  assert_equal 'works', File.open('new/nother') { |f| f.read }
1726
1729
  end
1727
1730
 
1728
1731
  def test_can_symlink_through_file
1729
- FileUtils.touch("/foo")
1732
+ FileUtils.touch('/foo')
1730
1733
 
1731
- File.symlink("/foo", "/bar")
1734
+ File.symlink('/foo', '/bar')
1732
1735
 
1733
- assert File.symlink?("/bar")
1736
+ assert File.symlink?('/bar')
1734
1737
  end
1735
1738
 
1736
1739
  def test_files_can_be_touched
1737
1740
  FileUtils.touch('touched_file')
1738
- assert File.exists?('touched_file')
1739
- list = ['newfile', 'another']
1741
+ assert File.exist?('touched_file')
1742
+ list = %w(newfile another)
1740
1743
  FileUtils.touch(list)
1741
- list.each { |fp| assert(File.exists?(fp)) }
1744
+ list.each { |fp| assert(File.exist?(fp)) }
1742
1745
  end
1743
1746
 
1744
1747
  def test_touch_does_not_work_if_the_dir_path_cannot_be_found
@@ -1754,7 +1757,7 @@ class FakeFSTest < Test::Unit::TestCase
1754
1757
  end
1755
1758
 
1756
1759
  def test_extname
1757
- assert File.extname("test.doc") == ".doc"
1760
+ assert File.extname('test.doc') == '.doc'
1758
1761
  end
1759
1762
 
1760
1763
  # Directory tests
@@ -1778,12 +1781,12 @@ class FakeFSTest < Test::Unit::TestCase
1778
1781
  assert dir.close.nil?
1779
1782
 
1780
1783
  assert_raises(IOError) do
1781
- dir.each { |dir| dir }
1784
+ dir.each { |d| d }
1782
1785
  end
1783
1786
  end
1784
1787
 
1785
1788
  def test_directory_each
1786
- test = ['.', '..', 'file_1', 'file_2', 'file_3', 'file_4', 'file_5' ]
1789
+ test = ['.', '..', 'file_1', 'file_2', 'file_3', 'file_4', 'file_5']
1787
1790
 
1788
1791
  FileUtils.mkdir_p('/this/path/should/be/here')
1789
1792
 
@@ -1794,8 +1797,8 @@ class FakeFSTest < Test::Unit::TestCase
1794
1797
  dir = Dir.new('/this/path/should/be/here')
1795
1798
 
1796
1799
  yielded = []
1797
- dir.each do |dir|
1798
- yielded << dir
1800
+ dir.each do |d|
1801
+ yielded << d
1799
1802
  end
1800
1803
 
1801
1804
  assert yielded.size == test.size
@@ -1809,7 +1812,7 @@ class FakeFSTest < Test::Unit::TestCase
1809
1812
  end
1810
1813
 
1811
1814
  def test_directory_pos
1812
- test = ['.', '..', 'file_1', 'file_2', 'file_3', 'file_4', 'file_5' ]
1815
+ test = ['.', '..', 'file_1', 'file_2', 'file_3', 'file_4', 'file_5']
1813
1816
  FileUtils.mkdir_p('/this/path/should/be/here')
1814
1817
  test.each do |f|
1815
1818
  FileUtils.touch("/this/path/should/be/here/#{f}")
@@ -1831,7 +1834,7 @@ class FakeFSTest < Test::Unit::TestCase
1831
1834
  end
1832
1835
 
1833
1836
  def test_directory_pos_assign
1834
- test = ['.', '..', 'file_1', 'file_2', 'file_3', 'file_4', 'file_5' ]
1837
+ test = ['.', '..', 'file_1', 'file_2', 'file_3', 'file_4', 'file_5']
1835
1838
 
1836
1839
  FileUtils.mkdir_p('/this/path/should/be/here')
1837
1840
  test.each do |f|
@@ -1846,7 +1849,7 @@ class FakeFSTest < Test::Unit::TestCase
1846
1849
  end
1847
1850
 
1848
1851
  def test_directory_read
1849
- test = ['.', '..', 'file_1', 'file_2', 'file_3', 'file_4', 'file_5' ]
1852
+ test = ['.', '..', 'file_1', 'file_2', 'file_3', 'file_4', 'file_5']
1850
1853
 
1851
1854
  FileUtils.mkdir_p('/this/path/should/be/here')
1852
1855
  test.each do |f|
@@ -1866,7 +1869,7 @@ class FakeFSTest < Test::Unit::TestCase
1866
1869
  end
1867
1870
 
1868
1871
  def test_directory_read_past_length
1869
- test = ['.', '..', 'file_1', 'file_2', 'file_3', 'file_4', 'file_5' ]
1872
+ test = ['.', '..', 'file_1', 'file_2', 'file_3', 'file_4', 'file_5']
1870
1873
 
1871
1874
  FileUtils.mkdir_p('/this/path/should/be/here')
1872
1875
  test.each do |f|
@@ -1894,7 +1897,7 @@ class FakeFSTest < Test::Unit::TestCase
1894
1897
  end
1895
1898
 
1896
1899
  def test_directory_rewind
1897
- test = ['.', '..', 'file_1', 'file_2', 'file_3', 'file_4', 'file_5' ]
1900
+ test = ['.', '..', 'file_1', 'file_2', 'file_3', 'file_4', 'file_5']
1898
1901
 
1899
1902
  FileUtils.mkdir_p('/this/path/should/be/here')
1900
1903
  test.each do |f|
@@ -1903,15 +1906,15 @@ class FakeFSTest < Test::Unit::TestCase
1903
1906
 
1904
1907
  dir = Dir.new('/this/path/should/be/here')
1905
1908
 
1906
- d = dir.read
1907
- d = dir.read
1909
+ dir.read
1910
+ dir.read
1908
1911
  assert dir.pos == 2
1909
1912
  dir.rewind
1910
1913
  assert dir.pos == 0
1911
1914
  end
1912
1915
 
1913
1916
  def test_directory_seek
1914
- test = ['.', '..', 'file_1', 'file_2', 'file_3', 'file_4', 'file_5' ]
1917
+ test = ['.', '..', 'file_1', 'file_2', 'file_3', 'file_4', 'file_5']
1915
1918
 
1916
1919
  FileUtils.mkdir_p('/this/path/should/be/here')
1917
1920
  test.each do |f|
@@ -1928,11 +1931,11 @@ class FakeFSTest < Test::Unit::TestCase
1928
1931
  def test_directory_class_delete
1929
1932
  FileUtils.mkdir_p('/this/path/should/be/here')
1930
1933
  Dir.delete('/this/path/should/be/here')
1931
- assert File.exists?('/this/path/should/be/here') == false
1934
+ assert File.exist?('/this/path/should/be/here') == false
1932
1935
  end
1933
1936
 
1934
1937
  def test_directory_class_delete_does_not_act_on_non_empty_directory
1935
- test = ['.', '..', 'file_1', 'file_2', 'file_3', 'file_4', 'file_5' ]
1938
+ test = ['.', '..', 'file_1', 'file_2', 'file_3', 'file_4', 'file_5']
1936
1939
 
1937
1940
  FileUtils.mkdir_p('/this/path/should/be/here')
1938
1941
  test.each do |f|
@@ -1951,7 +1954,7 @@ class FakeFSTest < Test::Unit::TestCase
1951
1954
  end
1952
1955
 
1953
1956
  def test_directory_entries
1954
- test = ['.', '..', 'file_1', 'file_2', 'file_3', 'file_4', 'file_5' ]
1957
+ test = ['.', '..', 'file_1', 'file_2', 'file_3', 'file_4', 'file_5']
1955
1958
 
1956
1959
  FileUtils.mkdir_p('/this/path/should/be/here')
1957
1960
 
@@ -1965,7 +1968,7 @@ class FakeFSTest < Test::Unit::TestCase
1965
1968
  end
1966
1969
 
1967
1970
  def test_directory_entries_works_with_trailing_slash
1968
- test = ['.', '..', 'file_1', 'file_2', 'file_3', 'file_4', 'file_5' ]
1971
+ test = ['.', '..', 'file_1', 'file_2', 'file_3', 'file_4', 'file_5']
1969
1972
 
1970
1973
  FileUtils.mkdir_p('/this/path/should/be/here')
1971
1974
 
@@ -1985,7 +1988,7 @@ class FakeFSTest < Test::Unit::TestCase
1985
1988
  end
1986
1989
 
1987
1990
  def test_directory_foreach
1988
- test = ['.', '..', 'file_1', 'file_2', 'file_3', 'file_4', 'file_5' ]
1991
+ test = ['.', '..', 'file_1', 'file_2', 'file_3', 'file_4', 'file_5']
1989
1992
 
1990
1993
  FileUtils.mkdir_p('/this/path/should/be/here')
1991
1994
 
@@ -2003,7 +2006,7 @@ class FakeFSTest < Test::Unit::TestCase
2003
2006
  end
2004
2007
 
2005
2008
  def test_directory_foreach_relative_paths
2006
- test = ['.', '..', 'file_1', 'file_2', 'file_3', 'file_4', 'file_5' ]
2009
+ test = ['.', '..', 'file_1', 'file_2', 'file_3', 'file_4', 'file_5']
2007
2010
 
2008
2011
  FileUtils.mkdir_p('/this/path/should/be/here')
2009
2012
 
@@ -2024,37 +2027,37 @@ class FakeFSTest < Test::Unit::TestCase
2024
2027
 
2025
2028
  def test_directory_mkdir
2026
2029
  Dir.mkdir('/path')
2027
- assert File.exists?('/path')
2030
+ assert File.exist?('/path')
2028
2031
  end
2029
2032
 
2030
2033
  def test_directory_mkdir_nested
2031
- Dir.mkdir("/tmp")
2032
- Dir.mkdir("/tmp/stream20120103-11847-xc8pb.lock")
2033
- assert File.exists?("/tmp/stream20120103-11847-xc8pb.lock")
2034
+ Dir.mkdir('/tmp')
2035
+ Dir.mkdir('/tmp/stream20120103-11847-xc8pb.lock')
2036
+ assert File.exist?('/tmp/stream20120103-11847-xc8pb.lock')
2034
2037
  end
2035
2038
 
2036
2039
  def test_can_create_subdirectories_with_dir_mkdir
2037
2040
  Dir.mkdir 'foo'
2038
2041
  Dir.mkdir 'foo/bar'
2039
- assert Dir.exists?('foo/bar')
2042
+ assert Dir.exist?('foo/bar')
2040
2043
  end
2041
2044
 
2042
2045
  def test_can_create_absolute_subdirectories_with_dir_mkdir
2043
2046
  Dir.mkdir '/foo'
2044
2047
  Dir.mkdir '/foo/bar'
2045
- assert Dir.exists?('/foo/bar')
2048
+ assert Dir.exist?('/foo/bar')
2046
2049
  end
2047
2050
 
2048
2051
  def test_can_create_directories_starting_with_dot
2049
2052
  Dir.mkdir './path'
2050
- assert File.exists? './path'
2053
+ assert File.exist? './path'
2051
2054
  end
2052
2055
 
2053
2056
  def test_directory_mkdir_relative
2054
2057
  FileUtils.mkdir_p('/new/root')
2055
2058
  FileSystem.chdir('/new/root')
2056
2059
  Dir.mkdir('path')
2057
- assert File.exists?('/new/root/path')
2060
+ assert File.exist?('/new/root/path')
2058
2061
  end
2059
2062
 
2060
2063
  def test_directory_mkdir_not_recursive
@@ -2064,15 +2067,15 @@ class FakeFSTest < Test::Unit::TestCase
2064
2067
  end
2065
2068
 
2066
2069
  def test_mkdir_raises_error_if_already_created
2067
- Dir.mkdir "foo"
2070
+ Dir.mkdir 'foo'
2068
2071
 
2069
2072
  assert_raises(Errno::EEXIST) do
2070
- Dir.mkdir "foo"
2073
+ Dir.mkdir 'foo'
2071
2074
  end
2072
2075
  end
2073
2076
 
2074
2077
  def test_directory_open
2075
- test = ['.', '..', 'file_1', 'file_2', 'file_3', 'file_4', 'file_5' ]
2078
+ test = ['.', '..', 'file_1', 'file_2', 'file_3', 'file_4', 'file_5']
2076
2079
 
2077
2080
  FileUtils.mkdir_p('/this/path/should/be/here')
2078
2081
 
@@ -2085,7 +2088,7 @@ class FakeFSTest < Test::Unit::TestCase
2085
2088
  end
2086
2089
 
2087
2090
  def test_directory_open_block
2088
- test = ['.', '..', 'file_1', 'file_2', 'file_3', 'file_4', 'file_5' ]
2091
+ test = ['.', '..', 'file_1', 'file_2', 'file_3', 'file_4', 'file_5']
2089
2092
 
2090
2093
  FileUtils.mkdir_p('/this/path/should/be/here')
2091
2094
 
@@ -2103,142 +2106,141 @@ class FakeFSTest < Test::Unit::TestCase
2103
2106
  end
2104
2107
 
2105
2108
  def test_directory_exists
2106
- assert Dir.exists?('/this/path/should/be/here') == false
2109
+ assert Dir.exist?('/this/path/should/be/here') == false
2107
2110
  assert Dir.exist?('/this/path/should/be/here') == false
2108
2111
  FileUtils.mkdir_p('/this/path/should/be/here')
2109
- assert Dir.exists?('/this/path/should/be/here') == true
2112
+ assert Dir.exist?('/this/path/should/be/here') == true
2110
2113
  assert Dir.exist?('/this/path/should/be/here') == true
2111
2114
  end
2112
2115
 
2113
2116
  def test_tmpdir
2114
- assert Dir.tmpdir == "/tmp"
2117
+ assert Dir.tmpdir == '/tmp'
2115
2118
  end
2116
2119
 
2117
2120
  def test_rename_renames_a_file
2118
- FileUtils.touch("/foo")
2119
- File.rename("/foo", "/bar")
2120
- assert File.file?("/bar")
2121
+ FileUtils.touch('/foo')
2122
+ File.rename('/foo', '/bar')
2123
+ assert File.file?('/bar')
2121
2124
  end
2122
2125
 
2123
2126
  def test_rename_returns
2124
- FileUtils.touch("/foo")
2125
- assert_equal 0, File.rename("/foo", "/bar")
2127
+ FileUtils.touch('/foo')
2128
+ assert_equal 0, File.rename('/foo', '/bar')
2126
2129
  end
2127
2130
 
2128
2131
  def test_rename_renames_two_files
2129
- FileUtils.touch("/foo")
2130
- FileUtils.touch("/bar")
2131
- File.rename("/foo", "/bar")
2132
- assert File.file?("/bar")
2132
+ FileUtils.touch('/foo')
2133
+ FileUtils.touch('/bar')
2134
+ File.rename('/foo', '/bar')
2135
+ assert File.file?('/bar')
2133
2136
  end
2134
2137
 
2135
2138
  def test_rename_renames_a_directories
2136
- Dir.mkdir("/foo")
2137
- File.rename("/foo", "/bar")
2138
- assert File.directory?("/bar")
2139
+ Dir.mkdir('/foo')
2140
+ File.rename('/foo', '/bar')
2141
+ assert File.directory?('/bar')
2139
2142
  end
2140
2143
 
2141
2144
  def test_rename_renames_two_directories
2142
- Dir.mkdir("/foo")
2143
- Dir.mkdir("/bar")
2144
- File.rename("/foo", "/bar")
2145
- assert File.directory?("/bar")
2145
+ Dir.mkdir('/foo')
2146
+ Dir.mkdir('/bar')
2147
+ File.rename('/foo', '/bar')
2148
+ assert File.directory?('/bar')
2146
2149
  end
2147
2150
 
2148
2151
  def test_rename_file_to_directory_raises_error
2149
- FileUtils.touch("/foo")
2150
- Dir.mkdir("/bar")
2152
+ FileUtils.touch('/foo')
2153
+ Dir.mkdir('/bar')
2151
2154
  assert_raises(Errno::EISDIR) do
2152
- File.rename("/foo", "/bar")
2155
+ File.rename('/foo', '/bar')
2153
2156
  end
2154
2157
  end
2155
2158
 
2156
2159
  def test_rename_directory_to_file_raises_error
2157
- Dir.mkdir("/foo")
2158
- FileUtils.touch("/bar")
2160
+ Dir.mkdir('/foo')
2161
+ FileUtils.touch('/bar')
2159
2162
  assert_raises(Errno::ENOTDIR) do
2160
- File.rename("/foo", "/bar")
2163
+ File.rename('/foo', '/bar')
2161
2164
  end
2162
2165
  end
2163
2166
 
2164
-
2165
2167
  def test_rename_with_missing_source_raises_error
2166
2168
  assert_raises(Errno::ENOENT) do
2167
- File.rename("/no_such_file", "/bar")
2169
+ File.rename('/no_such_file', '/bar')
2168
2170
  end
2169
2171
  end
2170
2172
 
2171
2173
  def test_rename_with_missing_dest_directory_raises_error
2172
- FileUtils.touch("/foo")
2174
+ FileUtils.touch('/foo')
2173
2175
  assert_raises(Errno::ENOENT) do
2174
- File.rename("/foo", "/bar/foo")
2176
+ File.rename('/foo', '/bar/foo')
2175
2177
  end
2176
2178
  end
2177
2179
 
2178
2180
  def test_hard_link_creates_file
2179
- FileUtils.touch("/foo")
2181
+ FileUtils.touch('/foo')
2180
2182
 
2181
- File.link("/foo", "/bar")
2182
- assert File.exists?("/bar")
2183
+ File.link('/foo', '/bar')
2184
+ assert File.exist?('/bar')
2183
2185
  end
2184
2186
 
2185
2187
  def test_hard_link_with_missing_file_raises_error
2186
2188
  assert_raises(Errno::ENOENT) do
2187
- File.link("/foo", "/bar")
2189
+ File.link('/foo', '/bar')
2188
2190
  end
2189
2191
  end
2190
2192
 
2191
2193
  def test_hard_link_with_existing_destination_file
2192
- FileUtils.touch("/foo")
2193
- FileUtils.touch("/bar")
2194
+ FileUtils.touch('/foo')
2195
+ FileUtils.touch('/bar')
2194
2196
 
2195
2197
  assert_raises(Errno::EEXIST) do
2196
- File.link("/foo", "/bar")
2198
+ File.link('/foo', '/bar')
2197
2199
  end
2198
2200
  end
2199
2201
 
2200
2202
  def test_hard_link_returns_0_when_successful
2201
- FileUtils.touch("/foo")
2203
+ FileUtils.touch('/foo')
2202
2204
 
2203
- assert_equal 0, File.link("/foo", "/bar")
2205
+ assert_equal 0, File.link('/foo', '/bar')
2204
2206
  end
2205
2207
 
2206
2208
  def test_hard_link_returns_duplicate_file
2207
- File.open("/foo", "w") { |x| x << "some content" }
2209
+ File.open('/foo', 'w') { |x| x << 'some content' }
2208
2210
 
2209
- File.link("/foo", "/bar")
2210
- assert_equal "some content", File.read("/bar")
2211
+ File.link('/foo', '/bar')
2212
+ assert_equal 'some content', File.read('/bar')
2211
2213
  end
2212
2214
 
2213
2215
  def test_hard_link_with_directory_raises_error
2214
- Dir.mkdir "/foo"
2216
+ Dir.mkdir '/foo'
2215
2217
 
2216
2218
  assert_raises(Errno::EPERM) do
2217
- File.link("/foo", "/bar")
2219
+ File.link('/foo', '/bar')
2218
2220
  end
2219
2221
  end
2220
2222
 
2221
2223
  def test_file_stat_returns_file_stat_object
2222
- FileUtils.touch("/foo")
2223
- assert_equal File::Stat, File.stat("/foo").class
2224
+ FileUtils.touch('/foo')
2225
+ assert_equal File::Stat, File.stat('/foo').class
2224
2226
  end
2225
2227
 
2226
2228
  def test_can_delete_file_with_delete
2227
- FileUtils.touch("/foo")
2229
+ FileUtils.touch('/foo')
2228
2230
 
2229
- File.delete("/foo")
2231
+ File.delete('/foo')
2230
2232
 
2231
- assert !File.exists?("/foo")
2233
+ assert !File.exist?('/foo')
2232
2234
  end
2233
2235
 
2234
2236
  def test_can_delete_multiple_files_with_delete
2235
- FileUtils.touch("/foo")
2236
- FileUtils.touch("/bar")
2237
+ FileUtils.touch('/foo')
2238
+ FileUtils.touch('/bar')
2237
2239
 
2238
- File.delete("/foo", "/bar")
2240
+ File.delete('/foo', '/bar')
2239
2241
 
2240
- assert !File.exists?("/foo")
2241
- assert !File.exists?("/bar")
2242
+ assert !File.exist?('/foo')
2243
+ assert !File.exist?('/bar')
2242
2244
  end
2243
2245
 
2244
2246
  def test_delete_returns_zero_when_no_filename_given
@@ -2246,104 +2248,104 @@ class FakeFSTest < Test::Unit::TestCase
2246
2248
  end
2247
2249
 
2248
2250
  def test_delete_returns_number_one_when_given_one_arg
2249
- FileUtils.touch("/foo")
2251
+ FileUtils.touch('/foo')
2250
2252
 
2251
- assert_equal 1, File.delete("/foo")
2253
+ assert_equal 1, File.delete('/foo')
2252
2254
  end
2253
2255
 
2254
2256
  def test_delete_returns_number_two_when_given_two_args
2255
- FileUtils.touch("/foo")
2256
- FileUtils.touch("/bar")
2257
+ FileUtils.touch('/foo')
2258
+ FileUtils.touch('/bar')
2257
2259
 
2258
- assert_equal 2, File.delete("/foo", "/bar")
2260
+ assert_equal 2, File.delete('/foo', '/bar')
2259
2261
  end
2260
2262
 
2261
2263
  def test_delete_raises_error_when_first_file_does_not_exist
2262
2264
  assert_raises Errno::ENOENT do
2263
- File.delete("/foo")
2265
+ File.delete('/foo')
2264
2266
  end
2265
2267
  end
2266
2268
 
2267
2269
  def test_unlink_removes_only_one_file_content
2268
- File.open("/foo", "w") { |f| f << "some_content" }
2269
- File.link("/foo", "/bar")
2270
+ File.open('/foo', 'w') { |f| f << 'some_content' }
2271
+ File.link('/foo', '/bar')
2270
2272
 
2271
- File.unlink("/bar")
2272
- assert_equal "some_content", File.read("/foo")
2273
+ File.unlink('/bar')
2274
+ assert_equal 'some_content', File.read('/foo')
2273
2275
  end
2274
2276
 
2275
2277
  def test_link_reports_correct_stat_info_after_unlinking
2276
- File.open("/foo", "w") { |f| f << "some_content" }
2277
- File.link("/foo", "/bar")
2278
+ File.open('/foo', 'w') { |f| f << 'some_content' }
2279
+ File.link('/foo', '/bar')
2278
2280
 
2279
- File.unlink("/bar")
2280
- assert_equal 1, File.stat("/foo").nlink
2281
+ File.unlink('/bar')
2282
+ assert_equal 1, File.stat('/foo').nlink
2281
2283
  end
2282
2284
 
2283
2285
  def test_delete_works_with_symlink
2284
- FileUtils.touch("/foo")
2285
- File.symlink("/foo", "/bar")
2286
+ FileUtils.touch('/foo')
2287
+ File.symlink('/foo', '/bar')
2286
2288
 
2287
- File.unlink("/bar")
2289
+ File.unlink('/bar')
2288
2290
 
2289
- assert File.exists?("/foo")
2290
- assert !File.exists?("/bar")
2291
+ assert File.exist?('/foo')
2292
+ assert !File.exist?('/bar')
2291
2293
  end
2292
2294
 
2293
2295
  def test_delete_works_with_symlink_source
2294
- FileUtils.touch("/foo")
2295
- File.symlink("/foo", "/bar")
2296
+ FileUtils.touch('/foo')
2297
+ File.symlink('/foo', '/bar')
2296
2298
 
2297
- File.unlink("/foo")
2299
+ File.unlink('/foo')
2298
2300
 
2299
- assert !File.exists?("/foo")
2301
+ assert !File.exist?('/foo')
2300
2302
  end
2301
2303
 
2302
2304
  def test_file_seek_returns_0
2303
- File.open("/foo", "w") do |f|
2305
+ File.open('/foo', 'w') do |f|
2304
2306
  f << "one\ntwo\nthree"
2305
2307
  end
2306
2308
 
2307
- file = File.open("/foo", "r")
2309
+ file = File.open('/foo', 'r')
2308
2310
 
2309
2311
  assert_equal 0, file.seek(1)
2310
2312
  end
2311
2313
 
2312
2314
  def test_file_seek_seeks_to_location
2313
- File.open("/foo", "w") do |f|
2314
- f << "123"
2315
+ File.open('/foo', 'w') do |f|
2316
+ f << '123'
2315
2317
  end
2316
2318
 
2317
- file = File.open("/foo", "r")
2319
+ file = File.open('/foo', 'r')
2318
2320
  file.seek(1)
2319
- assert_equal "23", file.read
2321
+ assert_equal '23', file.read
2320
2322
  end
2321
2323
 
2322
2324
  def test_file_seek_seeks_to_correct_location
2323
- File.open("/foo", "w") do |f|
2324
- f << "123"
2325
+ File.open('/foo', 'w') do |f|
2326
+ f << '123'
2325
2327
  end
2326
2328
 
2327
- file = File.open("/foo", "r")
2329
+ file = File.open('/foo', 'r')
2328
2330
  file.seek(2)
2329
- assert_equal "3", file.read
2331
+ assert_equal '3', file.read
2330
2332
  end
2331
2333
 
2332
2334
  def test_file_seek_can_take_negative_offset
2333
- File.open("/foo", "w") do |f|
2334
- f << "123456789"
2335
+ File.open('/foo', 'w') do |f|
2336
+ f << '123456789'
2335
2337
  end
2336
2338
 
2337
- file = File.open("/foo", "r")
2339
+ file = File.open('/foo', 'r')
2338
2340
 
2339
2341
  file.seek(-1, IO::SEEK_END)
2340
- assert_equal "9", file.read
2342
+ assert_equal '9', file.read
2341
2343
 
2342
2344
  file.seek(-2, IO::SEEK_END)
2343
- assert_equal "89", file.read
2345
+ assert_equal '89', file.read
2344
2346
 
2345
2347
  file.seek(-3, IO::SEEK_END)
2346
- assert_equal "789", file.read
2348
+ assert_equal '789', file.read
2347
2349
  end
2348
2350
 
2349
2351
  def test_should_have_constants_inherited_from_descending_from_io
@@ -2353,11 +2355,11 @@ class FakeFSTest < Test::Unit::TestCase
2353
2355
  end
2354
2356
 
2355
2357
  def test_filetest_exists_return_correct_values
2356
- FileUtils.mkdir_p("/path/to/dir")
2357
- assert FileTest.exist?("/path/to/")
2358
+ FileUtils.mkdir_p('/path/to/dir')
2359
+ assert FileTest.exist?('/path/to/')
2358
2360
 
2359
- FileUtils.rmdir("/path/to/dir")
2360
- assert !FileTest.exist?("/path/to/dir")
2361
+ FileUtils.rmdir('/path/to/dir')
2362
+ assert !FileTest.exist?('/path/to/dir')
2361
2363
  end
2362
2364
 
2363
2365
  def test_filetest_directory_returns_correct_values
@@ -2369,10 +2371,10 @@ class FakeFSTest < Test::Unit::TestCase
2369
2371
  end
2370
2372
 
2371
2373
  def test_filetest_file_returns_correct_values
2372
- FileUtils.mkdir_p("/path/to")
2374
+ FileUtils.mkdir_p('/path/to')
2373
2375
 
2374
2376
  path = '/path/to/file.txt'
2375
- File.open(path, 'w') { |f| f.write "Yatta!" }
2377
+ File.open(path, 'w') { |f| f.write 'Yatta!' }
2376
2378
  assert FileTest.file?(path)
2377
2379
 
2378
2380
  FileUtils.rm path
@@ -2393,10 +2395,10 @@ class FakeFSTest < Test::Unit::TestCase
2393
2395
  end
2394
2396
 
2395
2397
  def test_pathname_exists_returns_correct_value
2396
- FileUtils.touch "foo"
2397
- assert Pathname.new("foo").exist?
2398
+ FileUtils.touch 'foo'
2399
+ assert Pathname.new('foo').exist?
2398
2400
 
2399
- assert !Pathname.new("bar").exist?
2401
+ assert !Pathname.new('bar').exist?
2400
2402
  end
2401
2403
 
2402
2404
  def test_pathname_method_is_faked
@@ -2429,73 +2431,73 @@ class FakeFSTest < Test::Unit::TestCase
2429
2431
 
2430
2432
  def test_split
2431
2433
  assert File.respond_to? :split
2432
- filename = "/this/is/what/we/expect.txt"
2433
- path,filename = File.split(filename)
2434
- assert_equal path, "/this/is/what/we"
2435
- assert_equal filename, "expect.txt"
2434
+ filename = '/this/is/what/we/expect.txt'
2435
+ path, filename = File.split(filename)
2436
+ assert_equal path, '/this/is/what/we'
2437
+ assert_equal filename, 'expect.txt'
2436
2438
  end
2437
2439
 
2438
2440
  #########################
2439
2441
  def test_file_default_mode
2440
- FileUtils.touch "foo"
2441
- assert_equal File.stat("foo").mode, (0100000 + 0666 - File.umask)
2442
+ FileUtils.touch 'foo'
2443
+ assert_equal File.stat('foo').mode, (0100000 + 0666 - File.umask)
2442
2444
  end
2443
2445
 
2444
2446
  def test_dir_default_mode
2445
- Dir.mkdir "bar"
2446
- assert_equal File.stat("bar").mode, (0100000 + 0777 - File.umask)
2447
+ Dir.mkdir 'bar'
2448
+ assert_equal File.stat('bar').mode, (0100000 + 0777 - File.umask)
2447
2449
  end
2448
2450
 
2449
2451
  def test_file_default_uid_and_gid
2450
- FileUtils.touch "foo"
2451
- assert_equal File.stat("foo").uid, Process.uid
2452
- assert_equal File.stat("foo").gid, Process.gid
2452
+ FileUtils.touch 'foo'
2453
+ assert_equal File.stat('foo').uid, Process.uid
2454
+ assert_equal File.stat('foo').gid, Process.gid
2453
2455
  end
2454
2456
 
2455
2457
  def test_file_chmod_of_file
2456
- FileUtils.touch "foo"
2457
- File.chmod 0600, "foo"
2458
- assert_equal File.stat("foo").mode, 0100600
2459
- File.new("foo").chmod 0644
2460
- assert_equal File.stat("foo").mode, 0100644
2458
+ FileUtils.touch 'foo'
2459
+ File.chmod 0600, 'foo'
2460
+ assert_equal File.stat('foo').mode, 0100600
2461
+ File.new('foo').chmod 0644
2462
+ assert_equal File.stat('foo').mode, 0100644
2461
2463
  end
2462
2464
 
2463
2465
  def test_file_chmod_of_dir
2464
- Dir.mkdir "bar"
2465
- File.chmod 0777, "bar"
2466
- assert_equal File.stat("bar").mode, 0100777
2467
- File.new("bar").chmod 01700
2468
- assert_equal File.stat("bar").mode, 0101700
2466
+ Dir.mkdir 'bar'
2467
+ File.chmod 0777, 'bar'
2468
+ assert_equal File.stat('bar').mode, 0100777
2469
+ File.new('bar').chmod 01700
2470
+ assert_equal File.stat('bar').mode, 0101700
2469
2471
  end
2470
2472
 
2471
2473
  def test_file_chown_of_file
2472
- FileUtils.touch "foo"
2473
- File.chown 1337, 1338, "foo"
2474
- assert_equal File.stat("foo").uid, 1337
2475
- assert_equal File.stat("foo").gid, 1338
2474
+ FileUtils.touch 'foo'
2475
+ File.chown 1337, 1338, 'foo'
2476
+ assert_equal File.stat('foo').uid, 1337
2477
+ assert_equal File.stat('foo').gid, 1338
2476
2478
  end
2477
2479
 
2478
2480
  def test_file_chown_of_dir
2479
- Dir.mkdir "bar"
2480
- File.chown 1337, 1338, "bar"
2481
- assert_equal File.stat("bar").uid, 1337
2482
- assert_equal File.stat("bar").gid, 1338
2481
+ Dir.mkdir 'bar'
2482
+ File.chown 1337, 1338, 'bar'
2483
+ assert_equal File.stat('bar').uid, 1337
2484
+ assert_equal File.stat('bar').gid, 1338
2483
2485
  end
2484
2486
 
2485
2487
  def test_file_chown_of_file_nil_user_group
2486
- FileUtils.touch "foo"
2487
- File.chown 1337, 1338, "foo"
2488
- File.chown nil, nil, "foo"
2489
- assert_equal File.stat("foo").uid, 1337
2490
- assert_equal File.stat("foo").gid, 1338
2488
+ FileUtils.touch 'foo'
2489
+ File.chown 1337, 1338, 'foo'
2490
+ File.chown nil, nil, 'foo'
2491
+ assert_equal File.stat('foo').uid, 1337
2492
+ assert_equal File.stat('foo').gid, 1338
2491
2493
  end
2492
2494
 
2493
2495
  def test_file_chown_of_file_negative_user_group
2494
- FileUtils.touch "foo"
2495
- File.chown 1337, 1338, "foo"
2496
- File.chown -1, -1, "foo"
2497
- assert_equal File.stat("foo").uid, 1337
2498
- assert_equal File.stat("foo").gid, 1338
2496
+ FileUtils.touch 'foo'
2497
+ File.chown 1337, 1338, 'foo'
2498
+ File.chown(-1, -1, 'foo')
2499
+ assert_equal File.stat('foo').uid, 1337
2500
+ assert_equal File.stat('foo').gid, 1338
2499
2501
  end
2500
2502
 
2501
2503
  def test_file_instance_chown_nil_user_group
@@ -2515,7 +2517,7 @@ class FakeFSTest < Test::Unit::TestCase
2515
2517
  assert_equal File.stat('foo').uid, 1337
2516
2518
  assert_equal File.stat('foo').gid, 1338
2517
2519
  file = File.new('foo')
2518
- file.chown -1, -1
2520
+ file.chown(-1, -1)
2519
2521
  file.close
2520
2522
  assert_equal File.stat('foo').uid, 1337
2521
2523
  assert_equal File.stat('foo').gid, 1338
@@ -2532,35 +2534,35 @@ class FakeFSTest < Test::Unit::TestCase
2532
2534
  def test_file_stat_comparable
2533
2535
  a_time = Time.new
2534
2536
 
2535
- same1 = File.new("s1", "w")
2536
- same2 = File.new("s2", "w")
2537
- different1 = File.new("d1", "w")
2538
- different2 = File.new("d2", "w")
2537
+ same1 = File.new('s1', 'w')
2538
+ same2 = File.new('s2', 'w')
2539
+ different1 = File.new('d1', 'w')
2540
+ different2 = File.new('d2', 'w')
2539
2541
 
2540
- FileSystem.find("s1").mtime = a_time
2541
- FileSystem.find("s2").mtime = a_time
2542
+ FileSystem.find('s1').mtime = a_time
2543
+ FileSystem.find('s2').mtime = a_time
2542
2544
 
2543
- FileSystem.find("d1").mtime = a_time
2544
- FileSystem.find("d2").mtime = a_time + 1
2545
+ FileSystem.find('d1').mtime = a_time
2546
+ FileSystem.find('d2').mtime = a_time + 1
2545
2547
 
2546
2548
  assert same1.mtime == same2.mtime
2547
2549
  assert different1.mtime != different2.mtime
2548
2550
 
2549
2551
  assert same1.stat == same2.stat
2550
- assert (same1.stat <=> same2.stat) == 0
2552
+ assert((same1.stat <=> same2.stat) == 0)
2551
2553
 
2552
2554
  assert different1.stat != different2.stat
2553
- assert (different1.stat <=> different2.stat) == -1
2555
+ assert((different1.stat <=> different2.stat) == -1)
2554
2556
  end
2555
2557
 
2556
2558
  def test_file_binread_works
2557
- File.open("testfile", 'w') do |f|
2559
+ File.open('testfile', 'w') do |f|
2558
2560
  f << "This is line one\nThis is line two\nThis is line three\nAnd so on...\n"
2559
2561
  end
2560
2562
 
2561
- assert_equal File.binread("testfile"), "This is line one\nThis is line two\nThis is line three\nAnd so on...\n"
2562
- assert_equal File.binread("testfile", 20), "This is line one\nThi"
2563
- assert_equal File.binread("testfile", 20, 10), "ne one\nThis is line "
2563
+ assert_equal File.binread('testfile'), "This is line one\nThis is line two\nThis is line three\nAnd so on...\n"
2564
+ assert_equal File.binread('testfile', 20), "This is line one\nThi"
2565
+ assert_equal File.binread('testfile', 20, 10), "ne one\nThis is line "
2564
2566
  end
2565
2567
 
2566
2568
  def here(fname)
@@ -2584,11 +2586,11 @@ class FakeFSTest < Test::Unit::TestCase
2584
2586
  assert_equal FileUtils.compare_file(file1, file2), true
2585
2587
  assert_equal FileUtils.compare_file(file1, file3), false
2586
2588
  assert_raises Errno::ENOENT do
2587
- FileUtils.compare_file(file1, "file4.txt")
2589
+ FileUtils.compare_file(file1, 'file4.txt')
2588
2590
  end
2589
2591
  end
2590
2592
 
2591
- if RUBY_VERSION >= "1.9.1"
2593
+ if RUBY_VERSION >= '1.9.1'
2592
2594
  def test_absolute_path_with_absolute_path
2593
2595
  assert_equal '/foo/bar', File.absolute_path('/foo/bar')
2594
2596
  end
@@ -2602,21 +2604,20 @@ class FakeFSTest < Test::Unit::TestCase
2602
2604
  end
2603
2605
 
2604
2606
  def test_absolute_path_with_relative_path_with_dir_name
2605
- assert_equal "/dir/foo/bar", File.absolute_path('foo/bar', '/dir')
2607
+ assert_equal '/dir/foo/bar', File.absolute_path('foo/bar', '/dir')
2606
2608
  end
2607
2609
  end
2608
2610
 
2609
-
2610
- if RUBY_VERSION >= "1.9.2"
2611
+ if RUBY_VERSION >= '1.9.2'
2611
2612
  def test_file_size
2612
- File.open("foo", 'w') do |f|
2613
+ File.open('foo', 'w') do |f|
2613
2614
  f << 'Yada Yada'
2614
2615
  assert_equal 9, f.size
2615
2616
  end
2616
2617
  end
2617
2618
 
2618
2619
  def test_fdatasync
2619
- File.open("foo", 'w') do |f|
2620
+ File.open('foo', 'w') do |f|
2620
2621
  f << 'Yada Yada'
2621
2622
  assert_nothing_raised do
2622
2623
  f.fdatasync
@@ -2625,7 +2626,7 @@ class FakeFSTest < Test::Unit::TestCase
2625
2626
  end
2626
2627
 
2627
2628
  def test_autoclose
2628
- File.open("foo", 'w') do |f|
2629
+ File.open('foo', 'w') do |f|
2629
2630
  assert_equal true, f.autoclose?
2630
2631
  f.autoclose = false
2631
2632
  assert_equal false, f.autoclose?
@@ -2633,15 +2634,15 @@ class FakeFSTest < Test::Unit::TestCase
2633
2634
  end
2634
2635
 
2635
2636
  def test_to_path
2636
- File.new("foo", 'w') do |f|
2637
- assert_equal "foo", f.to_path
2637
+ File.new('foo', 'w') do |f|
2638
+ assert_equal 'foo', f.to_path
2638
2639
  end
2639
2640
  end
2640
2641
  end
2641
2642
 
2642
- if RUBY_VERSION >= "1.9.3"
2643
+ if RUBY_VERSION >= '1.9.3'
2643
2644
  def test_advise
2644
- File.open("foo", 'w') do |f|
2645
+ File.open('foo', 'w') do |f|
2645
2646
  assert_nothing_raised do
2646
2647
  f.advise(:normal, 0, 0)
2647
2648
  end
@@ -2654,7 +2655,7 @@ class FakeFSTest < Test::Unit::TestCase
2654
2655
  f.write 'Yatta!'
2655
2656
  end
2656
2657
 
2657
- assert_equal 'ASCII-8BIT', File.read(path, :mode => 'rb').encoding.to_s
2658
+ assert_equal 'ASCII-8BIT', File.read(path, mode: 'rb').encoding.to_s
2658
2659
  end
2659
2660
 
2660
2661
  def test_file_read_respects_args_and_hashes
@@ -2663,23 +2664,23 @@ class FakeFSTest < Test::Unit::TestCase
2663
2664
  f.write 'Yatta!'
2664
2665
  end
2665
2666
 
2666
- result = File.read(path, 2, 1, :mode => 'rb')
2667
+ result = File.read(path, 2, 1, mode: 'rb')
2667
2668
  assert_equal 'at', result
2668
2669
  assert_equal 'ASCII-8BIT', result.encoding.to_s
2669
2670
  end
2670
2671
 
2671
2672
  def test_file_write_can_write_a_file
2672
- File.write("testfile", "0123456789")
2673
- assert_equal File.read("testfile"), "0123456789"
2673
+ File.write('testfile', '0123456789')
2674
+ assert_equal File.read('testfile'), '0123456789'
2674
2675
  end
2675
2676
 
2676
2677
  def test_file_write_returns_the_length_written
2677
- assert_equal File.write("testfile", "0123456789"), 10
2678
+ assert_equal File.write('testfile', '0123456789'), 10
2678
2679
  end
2679
2680
 
2680
2681
  def test_file_write_truncates_file_if_offset_not_given
2681
- File.open("foo", 'w') do |f|
2682
- f << "foo"
2682
+ File.open('foo', 'w') do |f|
2683
+ f << 'foo'
2683
2684
  end
2684
2685
 
2685
2686
  File.write('foo', 'bar')
@@ -2687,8 +2688,8 @@ class FakeFSTest < Test::Unit::TestCase
2687
2688
  end
2688
2689
 
2689
2690
  def test_file_write_writes_at_offset_and_does_not_truncate
2690
- File.open("foo", 'w') do |f|
2691
- f << "foo"
2691
+ File.open('foo', 'w') do |f|
2692
+ f << 'foo'
2692
2693
  end
2693
2694
 
2694
2695
  File.write('foo', 'bar', 3)
@@ -2697,17 +2698,17 @@ class FakeFSTest < Test::Unit::TestCase
2697
2698
 
2698
2699
  def test_can_read_binary_data_in_binary_mode
2699
2700
  File.open('foo', 'wb') { |f| f << "\u0000\u0000\u0000\u0003\u0000\u0003\u0000\xA3\u0000\u0000\u0000y\u0000\u0000\u0000\u0000\u0000" }
2700
- assert_equal "\x00\x00\x00\x03\x00\x03\x00\xA3\x00\x00\x00y\x00\x00\x00\x00\x00".force_encoding('ASCII-8BIT'), File.open("foo", "rb").read
2701
+ assert_equal "\x00\x00\x00\x03\x00\x03\x00\xA3\x00\x00\x00y\x00\x00\x00\x00\x00".force_encoding('ASCII-8BIT'), File.open('foo', 'rb').read
2701
2702
  end
2702
2703
 
2703
2704
  def test_can_read_binary_data_in_non_binary_mode
2704
2705
  File.open('foo_non_bin', 'wb') { |f| f << "\u0000\u0000\u0000\u0003\u0000\u0003\u0000\xA3\u0000\u0000\u0000y\u0000\u0000\u0000\u0000\u0000" }
2705
- assert_equal "\x00\x00\x00\x03\x00\x03\x00\xA3\x00\x00\x00y\x00\x00\x00\x00\x00".force_encoding('UTF-8'), File.open("foo_non_bin", "r").read
2706
+ assert_equal "\x00\x00\x00\x03\x00\x03\x00\xA3\x00\x00\x00y\x00\x00\x00\x00\x00".force_encoding('UTF-8'), File.open('foo_non_bin', 'r').read
2706
2707
  end
2707
2708
 
2708
2709
  def test_can_read_binary_data_using_binread
2709
2710
  File.open('foo', 'wb') { |f| f << "\u0000\u0000\u0000\u0003\u0000\u0003\u0000\xA3\u0000\u0000\u0000y\u0000\u0000\u0000\u0000\u0000" }
2710
- assert_equal "\x00\x00\x00\x03\x00\x03\x00\xA3\x00\x00\x00y\x00\x00\x00\x00\x00".force_encoding('ASCII-8BIT'), File.binread("foo")
2711
+ assert_equal "\x00\x00\x00\x03\x00\x03\x00\xA3\x00\x00\x00y\x00\x00\x00\x00\x00".force_encoding('ASCII-8BIT'), File.binread('foo')
2711
2712
  end
2712
2713
  end
2713
2714
  end