So I have a function that generates like 300 lines of text and I want to 
unit test it.  If it fails, it barfs a dozen pages of text then says 
there's a difference in there somewhere and we wish you the best of luck 
trying to find it.

So, yeah.

I'd like to break this out into a line-by-line test.  The following code 
doesn't work because each_line is a generator function, not an array:

  def test.to_html
    # test the Calendar.to_html method
    cal = Calendar.new(@date_test)
    line_no = 0
    @html_reference.each_line.zip(cal.to_html.each_line).each do |test_line|
      line_no += 1
      assert_equal( test_line[0], cal_line[1], "Calendar#to_html output 
incorrect at line #{line_no}"
      # Test::Unit will then emit the reference line and the failed test 
line.
    end

Okay, so I want these each_lines done up as arrays.

      ref_lines = []; @html_reference.each_line {|line| ref_lines << line }
      cal_lines = []; cal.to_html.each_line {|line| cal_lines << line }
      line_no = 0
      ref_lines.zip(cal_lines).each do |test_line|
        line_no += 1
        assert_equal( test_line[0], test_line[1], "Calendar.to_html 
incorrect on line #{line_no}")
      end

This smells very kludgy and procedural.  I'm using an index/counter 
variable, explicit Array declarations, and zipping two arrays together 
only to split them apart again.  Ugh!

Can someone help me make this more elegant?  C++ has pooped Ruby's pants.

-dB

-- 
David Brady
ruby_talk / shinybit.com
C++ Guru. Ruby nuby.  Apply salt as needed.