Asserting files are not different in Test::Unit?

(David Brady) #1

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.

Thoughts?

-dB

···

--
David Brady
ruby_talk@shinybit.com
I'm feeling really surreal today... OR AM I?

(Jeff Wood) #2

Hows about

assert( FileUtils.compare_file('somefile', 'somefile') )

j.

···

On 8/26/05, David Brady <ruby_talk@shinybit.com> 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.

Thoughts?

-dB

--
David Brady
ruby_talk@shinybit.com
I'm feeling really surreal today... OR AM I?

--
"So long, and thanks for all the fish"

Jeff Wood

(Austin Ziegler) #3

You could use Diff::LCS, available on RubyForge.

-austin

···

On 8/26/05, David Brady <ruby_talk@shinybit.com> wrote:

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.

--
Austin Ziegler * halostatue@gmail.com
               * Alternate: austin@halostatue.ca

(Esteban Manchado Velázquez) #4

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,

···

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.

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