Sha256: 2795715c72f66994550a435c0789918675c7a6d61cbf2e70a4119f9e2495ac2f
Contents?: true
Size: 1.37 KB
Versions: 69
Compression:
Stored size: 1.37 KB
Contents
require 'spec_helper' require 'stringio' require 'r10k/logging/terminaloutputter' describe R10K::Logging::TerminalOutputter do let(:stream) { StringIO.new } let(:formatter) do Class.new(Log4r::Formatter) do def format(logevent) logevent.data end end end subject do described_class.new('test', stream, :level => 0, :formatter => formatter).tap do |o| o.use_color = true end end tests = [ [:debug2, :cyan], [:debug1, :cyan], [:debug, :green], [:info, nil], [:notice, nil], [:warn, :yellow], [:error, :red], [:fatal, :red], ] tests.each_with_index do |(level, color), index| # Note for the unwary - using a loop in this manner shows strange # behavior with variable closure. The describe block is needed to retain # the loop variables for each test; without this the let helpers are # overwritten and the last set of helpers are used for all tests. describe "at level #{level}" do let(:message) { "level #{level}: #{color}" } let(:event) do Log4r::LogEvent.new(index + 1, Log4r::Logger.new('test::logger'), nil, message) end it "logs messages as #{color ? color : "uncolored"}" do output = color.nil? ? message : message.send(color) subject.send(level, event) expect(stream.string).to eq output end end end end
Version data entries
69 entries across 69 versions & 2 rubygems