Sha256: 33d0f2720e0c6cc4bb69931d5983cfbbafbac3d38ae7f8e3d4e873666bfd4031

Contents?: true

Size: 692 Bytes

Versions: 8

Compression:

Stored size: 692 Bytes

Contents

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

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
radiant-0.6.5.1 vendor/rails/activesupport/test/core_ext/file_test.rb
radiant-0.6.5 vendor/rails/activesupport/test/core_ext/file_test.rb
radiant-0.6.6 vendor/rails/activesupport/test/core_ext/file_test.rb
radiant-0.6.7 vendor/rails/activesupport/test/core_ext/file_test.rb
radiant-0.6.8 vendor/rails/activesupport/test/core_ext/file_test.rb
radiant-0.6.9 vendor/rails/activesupport/test/core_ext/file_test.rb
spree-0.0.9 vendor/rails/activesupport/test/core_ext/file_test.rb
spree-0.2.0 vendor/rails/activesupport/test/core_ext/file_test.rb