Sha256: 01b9c7b794186c572aa7717e84b6b2673b0656b2c17ff935c250e62bcac51b49
Contents?: true
Size: 1.62 KB
Versions: 32
Compression:
Stored size: 1.62 KB
Contents
##################################################################### # test_wc.rb # # Test case for the File.wc method. This test should be run via # the 'rake test_wc' task. ##################################################################### require 'test/unit' require 'ptools' class TC_FileWC < Test::Unit::TestCase def self.startup Dir.chdir('test') if File.exists?('test') File.open('test_file1.txt', 'w'){ |fh| 25.times{ |n| fh.puts "line#{n+1}" } } end def setup @test_file = 'test_file1.txt' end def test_wc_basic assert_respond_to(File, :wc) assert_nothing_raised{ File.wc(@test_file) } assert_nothing_raised{ File.wc(@test_file, 'bytes') } assert_nothing_raised{ File.wc(@test_file, 'chars') } assert_nothing_raised{ File.wc(@test_file, 'words') } assert_nothing_raised{ File.wc(@test_file, 'LINES') } end def test_wc_results assert_kind_of(Array, File.wc(@test_file)) assert_equal([166,166,25,25], File.wc(@test_file)) assert_equal(166, File.wc(@test_file,'bytes'), "Wrong number of bytes") assert_equal(166, File.wc(@test_file,'chars'), "Wrong number of chars") assert_equal(25, File.wc(@test_file,'words'), "Wrong number of words") assert_equal(25, File.wc(@test_file,'lines'), "Wrong number of lines") end def test_wc_expected_errors assert_raises(ArgumentError){ File.wc } assert_raises(ArgumentError){ File.wc(@test_file, "bogus") } end def teardown @test_file = nil end def self.shutdown File.delete('test_file1.txt') if File.exists?('test_file1.txt') end end
Version data entries
32 entries across 32 versions & 2 rubygems