Sha256: dea269dc0463630051f0875c0489fd575ed90b193061f46273b3b9773f3e6822

Contents?: true

Size: 1.52 KB

Versions: 1

Compression:

Stored size: 1.52 KB

Contents

require 'helper'
require 'stringio'

class TestLinebyline < Test::Unit::TestCase
  include LineByLine
  
  def test_nothing_raises
    a = "foo"
    ref = StringIO.new(a)
    another = StringIO.new(a)
    
    compare_buffers! ref, another
  end
  
  def test_works_with_string_and_io
    assert_mismatch  'foo', 'foobar' do | msg |
      assert_match /Lines have different lengths \(3 expected, but was 6\)/, msg
    end
  end
  
  def test_raises_on_mismatch
    same = StringIO.new('dude')
    assert_mismatch  same, same do | msg |
      assert_match /The passed IO objects were the same thing/, msg
    end
    
    assert_mismatch  StringIO.new("foo"), StringIO.new("bar") do | msg |
      assert_match /Line mismatch at column 1 at line 1/, msg
    end
    
    assert_mismatch  StringIO.new("foobar"), StringIO.new("foo") do | msg |
      assert_match /Lines have different lengths \(6 expected, but was 3\) at line 1/, msg
    end
    
    assert_mismatch  StringIO.new("foo"), StringIO.new("foobar") do | msg |
      assert_match /Lines have different lengths \(3 expected, but was 6\) at line 1/, msg
    end
    
    assert_mismatch  StringIO.new("foo\nbar\n"), StringIO.new("foo\nbar\nbaz") do | msg |
      assert_match /Reference buffer ended, but the output still has data at line 3/, msg
    end
    
  end
  
  def assert_mismatch(ref, output)
    begin
      compare_buffers! ref, output
      flunk "These buffers are not the same and LineByLine should have raise"
    rescue LineByLine::NotSame => e
      yield e.message
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
linebyline-1.0.0 test/test_linebyline.rb