On Sat, Aug 27, 2005 at 07:24:48AM +0900, David Brady wrote:
> I am writing some document generation classes now, and testing them with 
> Test::Unit.  The documents are 20-50k in size, and as a good initial 
> test I'd like to simply generate a document and compare it against the 
> output of the existing document generator.
> 
> What are some good Rubyish ways of doing this?
> 
> Is there a Ruby Way to diff text files?
> 
> Is there a Ruby Way to assert that two text files are the same?
> 
> I suppose I could just write a wrapper to a system call to diff.
> 
> Alternately, I could wrapper a method in Test::Unit to read a file into 
> a gigantic string, and assert_equal that against the contents of another 
> string.  The fail message from this, however, would not only be useless 
> (100k of text to the console!), but would blind the system to other fail 
> messages useless as well.

   I just did that a couple of days ago. Here is the code:



   def test_db
      outputDir         = 'test/erb-output'
      expectedOutputDir = 'test/expected-erb-output'
      FileUtils.mkpath(outputDir)
      # Do something to fill outputDir

      Find.find(expectedOutputDir) do |f|
         next if f.split(File::SEPARATOR).include? '.svn'   # Skip SVN dirs
         unless FileTest.directory? f
            outputFile = f.sub(expectedOutputDir, outputDir)
            assert(FileUtils.compare_file(f, outputFile), "test-erb1: #{f}")
         end
      end
      FileUtils.rm_rf(outputDir)
   end

HTH,

-- 
Esteban Manchado VeláÛquez <zoso / foton.es> - http://www.foton.es
EuropeSwPatentFree - http://EuropeSwPatentFree.hispalinux.es