Sha256: f4f091de59e40d0ca2fdcd2cd25eea6675d87bdfc8e648463b02ba8cfb5757bb

Contents?: true

Size: 1.03 KB

Versions: 5

Compression:

Stored size: 1.03 KB

Contents

# encoding: utf-8

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

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
nanoc-3.6.6 test/cli/test_cleaning_stream.rb
nanoc-3.6.5 test/cli/test_cleaning_stream.rb
nanoc-3.6.4 test/cli/test_cleaning_stream.rb
nanoc-3.6.3 test/cli/test_cleaning_stream.rb
nanoc-3.6.2 test/cli/test_cleaning_stream.rb