Module: FileUtils::FastCopy::Etest

Defined in:
lib/vex/base/filesystem/fast_copy.rb

Instance Method Summary collapse

Instance Method Details

#test_fast_copyObject



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/vex/base/filesystem/fast_copy.rb', line 33

def test_fast_copy
  File.unlink("tmp/somedata.dat") if File.exist?("tmp/somedata.dat")

  assert !File.exist?("tmp/somedata.dat")
  FileUtils.fast_copy __FILE__, "tmp/somedata.dat"
  assert_equal File.read("tmp/somedata.dat"), File.read(__FILE__)

  File.unlink("tmp/somedata.dat")
  File.touch("tmp/somedata.dat")
  assert_not_equal File.size("tmp/somedata.dat"), File.size(__FILE__)
  FileUtils.fast_copy __FILE__, "tmp/somedata.dat"
  assert_equal File.size("tmp/somedata.dat"), File.size(__FILE__)
end

#test_fast_copy_failuresObject



47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/vex/base/filesystem/fast_copy.rb', line 47

def test_fast_copy_failures
  assert_raise(Errno::ENOENT) {  
    FileUtils.fast_copy "fixtures/somedata.dat.nonexisting", "tmp/somedata.dat"
  }

  assert_raise(Errno::ENOENT) {  
    FileUtils.fast_copy "fixtures/somedata.dat.nonexisting", "tmp"
  }

  assert_raise(Errno::ENOENT) {  
    FileUtils.fast_copy __FILE__, "tmp/nonexisting/dir"
  }
end

#test_fast_copy_slowObject



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/vex/base/filesystem/fast_copy.rb', line 61

def test_fast_copy_slow
  File.touch("tmp/somedata.dat")
  assert File.exist?("tmp/somedata.dat")

  File.stubs(:stat).with(__FILE__).returns({ :file => true, :dev => 1 }.slop)
  File.stubs(:stat).with("tmp/somedata.dat").returns({ :file => true, :dev => 2 }.slop)

  FileUtils.expects(:copy).with(__FILE__, "tmp/somedata.dat")
  FileUtils.fast_copy __FILE__, "tmp/somedata.dat"

  File.unlink("tmp/somedata.dat")
end