test/unit/file_mio_test.rb in masterview-0.3.2 vs test/unit/file_mio_test.rb in masterview-0.3.3
- old
+ new
@@ -41,11 +41,11 @@
#------------------------------------------------------------------------------
# Test Cases
#------------------------------------------------------------------------------
# ensure that sandbox limits writing to files outside of root path even if dot dot exists in path
- def test_sandbox_dotdot
+ def test_sandbox_dotdot
assert_raise(InvalidIOPathError){ f = IOMgr.template.path( '../bad') }
assert_raise(InvalidIOPathError){ f = IOMgr.template.path( 'bad/../dog/../../foo') }
assert_raise(InvalidIOPathError){ f = IOMgr.template.path( 'bad/../../foo') }
assert_raise(InvalidIOPathError){ f = IOMgr.template.path( 'bad/cat/../../../dog') }
assert_raise(InvalidIOPathError){ f = IOMgr.template.path( '/bad/foo') }
@@ -95,12 +95,12 @@
File.open( HelloWorldFullPath, 'w' ){ |file| file.write(file_content) }
verify_mio_handler_read( HelloWorldPath, HelloWorldFullPath, file_content, IOMgr.template )
file_content_changed = "foo\nbar"
File.open( HelloWorldFullPath, 'w' ){ |file| file.write(file_content_changed) }
- #verify_mio_handler_read( HelloWorldPath, file_content, IOMgr.template ) # still hitting cache #todo turn this on when caching is ready for testing
- verify_mio_handler_read_no_cache( HelloWorldPath, HelloWorldFullPath, file_content_changed, IOMgr.template )
+ #verify_mio_handler_read( HelloWorldPath, file_content, IOMgr.template ) # still hitting cache #todo turn this on when caching is ready for testing
+ verify_mio_handler_read_no_cache( HelloWorldPath, HelloWorldFullPath, file_content_changed, IOMgr.template )
end
def test_write_string
TestWritePathname.delete if TestWritePathname.exist?
@@ -128,11 +128,11 @@
def test_write_strings_and_block
TestWritePathname.delete if TestWritePathname.exist?
file_content_strings = [ 'hello', 'world']
file_content = file_content_strings.join('')
- IOMgr.template.path( TestWritePath).write do |f|
+ IOMgr.template.path( TestWritePath).write do |f|
file_content_strings.each { |str| f.write(str) }
end
verify_mio_handler_read( TestWritePath, TestWriteFullPath, file_content, IOMgr.template )
end
@@ -156,10 +156,26 @@
assert_equal false, IOMgr.template.path( TestWritePath).exist?
IOMgr.template.path( TestWritePath).write(file_content)
assert_equal true, IOMgr.template.path( TestWritePath).exist?
end
+ def test_remove
+ file_content = "foo"
+
+ TestFileMIOTemplatePathname.rmtree if TestFileMIOTemplatePathname.exist?
+ IOMgr.template.path( TestWritePath).write(file_content)
+ assert_equal true, IOMgr.template.path( TestWritePath).exist?
+ IOMgr.template.path(TestWritePath).remove
+ assert_equal false, IOMgr.template.path( TestWritePath).exist?
+ end
+
+ def test_remove_file_doesnt_exist
+ TestFileMIOTemplatePathname.rmtree if TestFileMIOTemplatePathname.exist?
+ assert_equal false, IOMgr.template.path( TestWritePath).exist?
+ assert_raise(Errno::ENOENT){ IOMgr.template.path(TestWritePath).remove }
+ end
+
def test_identical
file_content = "hello\nworld"
file_content_foo = "foo"
TestWritePathname.delete if TestWritePathname.exist?
@@ -241,11 +257,11 @@
assert_equal 'sub/two/apple.txt', found[0].pathname.to_s
assert_equal 'sub/two/bar.txt', found[1].pathname.to_s
assert_equal 'sub/two/baz.txt', found[2].pathname.to_s
end
- def test_findfiles_single_dir_pattern
+ def test_findfiles_single_dir_pattern
TestFileMIOTemplatePathname.rmtree if TestFileMIOTemplatePathname.exist?
IOMgr.template.path( 'sub/two/apple.txt').write('foo')
IOMgr.template.path( 'sub/two/bar.log').write('foo')
File.open(TestFileMIOTemplatePathname+'sub/two/baz.txt', 'w'){ |file| file.write('foo') }
found = IOMgr.template.find(:path => 'sub/two', :pattern => '*.txt')
@@ -255,11 +271,11 @@
assert_equal (TestFileMIOTemplatePathname+'sub/two/apple.txt').to_s, found[0].full_pathname.to_s
assert_equal 'sub/two/apple.txt', found[0].pathname.to_s
assert_equal 'sub/two/baz.txt', found[1].pathname.to_s
end
- def test_findfiles_multi_dir_root
+ def test_findfiles_multi_dir_root
TestFileMIOTemplatePathname.rmtree if TestFileMIOTemplatePathname.exist?
IOMgr.template.path( 'one/two/three.txt').write('foo')
IOMgr.template.path( 'sub/two/apple.txt').write('foo')
IOMgr.template.path( 'sub/two/bar.log').write('foo')
File.open(TestFileMIOTemplatePathname+'sub/two/baz.txt', 'w'){ |file| file.write('foo') }
@@ -274,11 +290,11 @@
assert_equal 'sub/two/apple.txt', found[1].pathname.to_s
assert_equal 'sub/two/bar.log', found[2].pathname.to_s
assert_equal 'sub/two/baz.txt', found[3].pathname.to_s
end
- def test_findfiles_multi_dir_pattern
+ def test_findfiles_multi_dir_pattern
TestFileMIOTemplatePathname.rmtree if TestFileMIOTemplatePathname.exist?
IOMgr.template.path( 'one/two/three.txt').write('foo')
IOMgr.template.path( 'sub/two/apple.txt').write('foo')
IOMgr.template.path( 'sub/two/bar.log').write('foo')
File.open(TestFileMIOTemplatePathname+'sub/two/baz.txt', 'w'){ |file| file.write('foo') }
@@ -291,10 +307,10 @@
assert_equal 'one/two/three.txt', found[0].pathname.to_s
assert_equal 'sub/two/apple.txt', found[1].pathname.to_s
assert_equal 'sub/two/baz.txt', found[2].pathname.to_s
end
- def test_findfiles_multi_dir_pattern_deep
+ def test_findfiles_multi_dir_pattern_deep
TestFileMIOTemplatePathname.rmtree if TestFileMIOTemplatePathname.exist?
IOMgr.template.path( 'one/two/three.txt').write('foo')
IOMgr.template.path( 'sub/two/apple.txt').write('foo')
IOMgr.template.path( 'sub/two/bar.log').write('foo')
File.open(TestFileMIOTemplatePathname+'sub/two/baz.txt', 'w'){ |file| file.write('foo') }