Module: LineByLine
- Defined in:
- lib/linebyline.rb
Defined Under Namespace
Modules: Assertions Classes: Checker, NotSame
Constant Summary collapse
- VERSION =
'1.0.0'
Instance Method Summary collapse
-
#compare_buffers!(expected, actual) ⇒ Object
Compares two passed String or IO objects for equal content.
Instance Method Details
#compare_buffers!(expected, actual) ⇒ Object
Compares two passed String or IO objects for equal content. If the contents does not match, a NotSame exception will be raised, and it’s NotSame#message will contain a very specific description of the mismatch, including the line number and offset into the line.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/linebyline.rb', line 56 def compare_buffers!(expected, actual) if expected.object_id == actual.object_id raise NotSame, /The passed IO objects were the same thing/ end # Wrap the passed strings in IOs if necessary reference_io, io_under_test = [expected, actual].map do | str_or_io | str_or_io.respond_to?(:gets) ? str_or_io : StringIO.new(str_or_io) end # There are subtle differences in how IO is handled on dfferent platforms (Darwin) lineno = 0 loop do # Increment the line counter lineno += 1 checker = Checker.new(lineno, reference_io.gets, io_under_test.gets) if checker.eof? return else checker.register_mismatches! raise NotSame, checker.failure if checker.failure end end end |