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

Version Path
r10k-3.15.0 spec/unit/logging/terminaloutputter_spec.rb
akerl-r10k-3.14.2.1 spec/unit/logging/terminaloutputter_spec.rb
r10k-3.14.2 spec/unit/logging/terminaloutputter_spec.rb
r10k-3.14.1 spec/unit/logging/terminaloutputter_spec.rb
r10k-3.14.0 spec/unit/logging/terminaloutputter_spec.rb
r10k-3.13.0 spec/unit/logging/terminaloutputter_spec.rb
r10k-3.12.1 spec/unit/logging/terminaloutputter_spec.rb
r10k-3.12.0 spec/unit/logging/terminaloutputter_spec.rb
r10k-3.11.0 spec/unit/logging/terminaloutputter_spec.rb
r10k-3.10.0 spec/unit/logging/terminaloutputter_spec.rb
r10k-3.9.3 spec/unit/logging/terminaloutputter_spec.rb
r10k-3.9.2 spec/unit/logging/terminaloutputter_spec.rb
r10k-3.9.1 spec/unit/logging/terminaloutputter_spec.rb
r10k-3.9.0 spec/unit/logging/terminaloutputter_spec.rb
r10k-3.8.0 spec/unit/logging/terminaloutputter_spec.rb
r10k-3.7.0 spec/unit/logging/terminaloutputter_spec.rb
r10k-3.6.0 spec/unit/logging/terminaloutputter_spec.rb
r10k-2.6.9 spec/unit/logging/terminaloutputter_spec.rb
r10k-3.5.2 spec/unit/logging/terminaloutputter_spec.rb
r10k-3.5.1 spec/unit/logging/terminaloutputter_spec.rb