Sha256: d40d762af2bda3102285dd2c99e175264fe5aa1c11e468527c6bf770a8b10f72

Contents?: true

Size: 1.5 KB

Versions: 1

Compression:

Stored size: 1.5 KB

Contents

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

require 'test/unit'
require 'ptools'

class TC_FileTouch < Test::Unit::TestCase
   def self.startup
      Dir.chdir('test') if File.exists?('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.exists?(@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.exists?(@test_file)
      @test_file = nil
   end

   def self.shutdown
      File.delete('test_file1.txt') if File.exists?('test_file1.txt')
   end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ptools-1.2.2-universal-mingw32 test/test_touch.rb