Sha256: 21cd750b510b955819d34b54e774c7e2bec0f45039be7df2b0f09ad74328cae5

Contents?: true

Size: 1.42 KB

Versions: 7

Compression:

Stored size: 1.42 KB

Contents

#####################################################################
# test_touch.rb
#
# Test case for the File.touch method. This test should be run
# via the 'rake test_touch task'.
#####################################################################
require 'test-unit'
require 'ptools'

class TC_FileTouch < Test::Unit::TestCase
  def self.startup
    @@dirname = File.dirname(__FILE__)
    @@xfile = File.join(@@dirname, 'test_file1.txt')
    File.open(@@xfile, 'w'){ |fh| 10.times{ |n| fh.puts "line #{n}" } }
  end

  def setup
    @test_file = File.join(@@dirname, 'delete.this')
    @xfile = File.join(@@dirname, 'test_file1.txt')
  end

  def test_touch_basic
    assert_respond_to(File, :touch)
    assert_nothing_raised{ File.touch(@test_file) }
  end

  def test_touch_expected_results
    assert_equal(File, File.touch(@test_file))
    assert_equal(true, File.exist?(@test_file))
    assert_equal(0, File.size(@test_file))
  end

  def test_touch_existing_file
    stat = File.stat(@xfile)
    sleep 1
    assert_nothing_raised{ File.touch(@xfile) }
    assert_equal(true, File.size(@xfile) == stat.size)
    assert_equal(false, File.mtime(@xfile) == stat.mtime)
  end

  def test_touch_expected_errors
    assert_raises(ArgumentError){ File.touch }
  end

  def teardown
    File.delete(@test_file) if File.exist?(@test_file)
    @test_file = nil
  end

  def self.shutdown
    File.delete(@@xfile) if File.exist?(@@xfile)
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
ptools-1.3.7 test/test_touch.rb
ptools-1.3.6 test/test_touch.rb
ptools-1.3.5 test/test_touch.rb
ptools-1.3.4 test/test_touch.rb
ptools-1.3.3 test/test_touch.rb
ptools-1.3.2 test/test_touch.rb
ptools-1.3.2-universal-mingw32 test/test_touch.rb