Sha256: 522dfc99aba4aaba92d76a9a7ae7c539d59239e15a104f877122706b6421a1aa

Contents?: true

Size: 1.4 KB

Versions: 3

Compression:

Stored size: 1.4 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
    Dir.chdir('test') if File.exist?('test')
    File.open('test_file1.txt', 'w'){ |fh| 10.times{ |n| fh.puts "line #{n}" } }
  end

  def setup
    @test_file = 'delete.this'
    @xfile = '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('test_file1.txt') if File.exist?('test_file1.txt')
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ptools-1.3.1-universal-mingw32 test/test_touch.rb
ptools-1.3.0-universal-mingw32 test/test_touch.rb
ptools-1.2.7-universal-mingw32 test/test_touch.rb