blob: 11025388762aed985fe6d176e4d468716a34394b (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
require File.dirname(__FILE__) + '/../abstract_unit'
class AtomicWriteTest < Test::Unit::TestCase
def test_atomic_write_without_errors
contents = "Atomic Text"
File.atomic_write(file_name, Dir.pwd) do |file|
file.write(contents)
assert !File.exist?(file_name)
end
assert File.exist?(file_name)
assert_equal contents, File.read(file_name)
ensure
File.unlink(file_name) rescue nil
end
def test_atomic_write_doesnt_write_when_block_raises
File.atomic_write(file_name) do |file|
file.write("testing")
raise "something bad"
end
rescue
assert !File.exist?(file_name)
end
def file_name
"atomic.file"
end
end
|