Module: FileUtils::TmpFile::Etest

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

Instance Method Summary collapse

Instance Method Details

#test_tmpfileObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/vex/base/filesystem/tmp_file.rb', line 44

def test_tmpfile
  assert File.exist?(__FILE__)

  # so something successfully via a tmp file
  FileUtils.fast_copy __FILE__, "tmp/copy.dat"
  assert File.exist?("tmp/copy.dat")
  
  FileUtils.tmpfile "tmp/copy.dat" do |dest|
    false
  end

  assert_equal File.size(__FILE__), File.size("tmp/copy.dat")

  FileUtils.tmpfile "tmp/copy.dat" do |dest|
    File.write(dest, "hey")
  end

  assert_equal 3, File.size("tmp/copy.dat")

  FileUtils.fast_copy __FILE__, "tmp/copy.dat"
  assert_equal File.size(__FILE__), File.size("tmp/copy.dat")

  FileUtils.tmpfile "tmp/copy.dat" do |dest|
    File.write(dest, "hey")
    false
  end
  
  assert_equal File.size(__FILE__), File.size("tmp/copy.dat")

  FileUtils.tmpfile "tmp/copy.dat" do |dest|
    File.write(dest, "hey")
    nil
  end

  assert_equal 3, File.size("tmp/copy.dat")

  r = FileUtils.tmpfile "tmp/copy.dat" do |dest|
    File.write(dest, "hey")
    "fourfour"
  end

  assert_equal "fourfour", r
end