Sha256: d88f21be6ec6c0a53d29bd1c1c76ea14dd2ba1844aaf935287753fa88456a129

Contents?: true

Size: 1.21 KB

Versions: 12

Compression:

Stored size: 1.21 KB

Contents

class Nanoc::CLI::CleaningStreamTest < Nanoc::TestCase
  class Stream
    attr_accessor :called_methods

    def initialize
      @called_methods = Set.new
    end

    def method_missing(symbol, *_args)
      @called_methods << symbol
    end
  end

  def test_forward
    methods = [:write, :<<, :tty?, :flush, :tell, :print, :puts, :string, :reopen, :exist?, :exists?, :close]

    s = Stream.new
    cs = Nanoc::CLI::CleaningStream.new(s)

    cs.write('aaa')
    cs << 'bb'
    cs.tty?
    cs.flush
    cs.tell
    cs.print('cc')
    cs.puts('dd')
    cs.string
    cs.reopen('/dev/null', 'r')
    cs.exist?
    cs.exists?
    cs.close

    methods.each do |m|
      assert s.called_methods.include?(m), "expected #{m} to be called"
    end
  end

  def test_works_with_logger
    require 'logger'
    stream = StringIO.new
    cleaning_stream = Nanoc::CLI::CleaningStream.new(stream)
    logger = Logger.new(cleaning_stream)
    logger.info('Some info')
    logger.warn('Something could start going wrong!')
  end

  def test_broken_pipe
    stream = StringIO.new
    def stream.write(_s)
      raise Errno::EPIPE.new
    end

    cleaning_stream = Nanoc::CLI::CleaningStream.new(stream)
    cleaning_stream.write('lol')
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
nanoc-4.1.0rc2 test/cli/test_cleaning_stream.rb
nanoc-4.1.0rc1 test/cli/test_cleaning_stream.rb
nanoc-4.1.0b1 test/cli/test_cleaning_stream.rb
nanoc-4.1.0a1 test/cli/test_cleaning_stream.rb
nanoc-4.0.2 test/cli/test_cleaning_stream.rb
nanoc-4.0.1 test/cli/test_cleaning_stream.rb
nanoc-4.0.0 test/cli/test_cleaning_stream.rb
nanoc-4.0.0rc3 test/cli/test_cleaning_stream.rb
nanoc-4.0.0rc2 test/cli/test_cleaning_stream.rb
nanoc-4.0.0rc1 test/cli/test_cleaning_stream.rb
nanoc-4.0.0b4 test/cli/test_cleaning_stream.rb
nanoc-4.0.0b3 test/cli/test_cleaning_stream.rb