Sha256: 4b3642ad2eea8ef13f34c96c3c23e24423149ce584d7ef2ea975e48994d5d597

Contents?: true

Size: 1.35 KB

Versions: 9

Compression:

Stored size: 1.35 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

9 entries across 9 versions & 1 rubygems

Version Path
ptools-1.3.1 test/test_touch.rb
ptools-1.3.0 test/test_touch.rb
ptools-1.2.7 test/test_touch.rb
ptools-1.2.6 test/test_touch.rb
ptools-1.2.6-universal-mingw32 test/test_touch.rb
ptools-1.2.5-universal-mingw32 test/test_touch.rb
ptools-1.2.4 test/test_touch.rb
ptools-1.2.4-universal-mingw32 test/test_touch.rb
ptools-1.2.3 test/test_touch.rb