Sha256: dae1ea8dcebc098179d865f52e68daa8aa62a7fde5ce2f8cb8cb1a864b442658

Contents?: true

Size: 1.46 KB

Versions: 16

Compression:

Stored size: 1.46 KB

Contents

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

class TC_FileHead < Test::Unit::TestCase
  def self.startup
    Dir.chdir('test') if File.exist?('test')
    File.open('test_file1.txt', 'w'){ |fh| 25.times{ |n| fh.puts "line#{n+1}" } }
  end

  def setup
    @test_file = 'test_file1.txt'
    @expected_head1 = ["line1\n","line2\n","line3\n","line4\n","line5\n"]
    @expected_head1.push("line6\n","line7\n","line8\n","line9\n","line10\n")
    @expected_head2 = ["line1\n","line2\n","line3\n","line4\n","line5\n"]
  end

  def test_head_basic
    assert_respond_to(File, :head)
    assert_nothing_raised{ File.head(@test_file) }
    assert_nothing_raised{ File.head(@test_file, 5) }
    assert_nothing_raised{ File.head(@test_file){} }
  end

  def test_head_expected_results
    assert_kind_of(Array, File.head(@test_file))
    assert_equal(@expected_head1, File.head(@test_file))
    assert_equal(@expected_head2, File.head(@test_file, 5))
  end

  def test_head_expected_errors
    assert_raises(ArgumentError){ File.head(@test_file, 5, "foo") }
    assert_raises(Errno::ENOENT){ File.head("bogus") }
  end

  def teardown
    @test_file = nil
  end

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

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
ptools-1.3.7 test/test_head.rb
ptools-1.3.6 test/test_head.rb
ptools-1.3.5 test/test_head.rb
ptools-1.3.4 test/test_head.rb
ptools-1.3.3 test/test_head.rb
ptools-1.3.2 test/test_head.rb
ptools-1.3.2-universal-mingw32 test/test_head.rb
ptools-1.3.1 test/test_head.rb
ptools-1.3.0 test/test_head.rb
ptools-1.2.7 test/test_head.rb
ptools-1.2.6 test/test_head.rb
ptools-1.2.6-universal-mingw32 test/test_head.rb
ptools-1.2.5-universal-mingw32 test/test_head.rb
ptools-1.2.4 test/test_head.rb
ptools-1.2.4-universal-mingw32 test/test_head.rb
ptools-1.2.3 test/test_head.rb