Sha256: a0b1ede94c38610787eeab176388ceb810750b8ad9175630c1d843b8694bf3d7

Contents?: true

Size: 1.23 KB

Versions: 3

Compression:

Stored size: 1.23 KB

Contents

require ::File.expand_path('../../spec_helper', __FILE__)
require 'stringio'

describe RightSupport::Log::StepLevelLogger do
  context 'with a decorated logger' do
    let(:buffer) { ::StringIO.new }

    let(:decorated_logger) { ::Logger.new(buffer) }

    def try_all_levels(l)
      l.debug('debug')
      l.info('info')
      l.warn('warn')
      l.error('error')
      l.fatal('fatal')
    end

    context 'with default level' do
      subject { described_class.new(decorated_logger) }

      it 'passes all messages' do
        try_all_levels(subject)
        buffer.string.should =~ /debug.+info.+warn.+error.+fatal/m
      end
    end

    context 'with error level' do
      subject do
        s = described_class.new(decorated_logger)
        s.level = ::Logger::ERROR
        s
      end

      it 'passes error and fatal messages' do
        try_all_levels(subject)
        buffer.string.should_not =~ /debug/
        buffer.string.should_not =~ /info/
        buffer.string.should_not =~ /warn/
        buffer.string.should =~ /error.+fatal/m
      end

      it 'does not change level of decorated logger' do
        try_all_levels(decorated_logger)
        buffer.string.should =~ /debug.+info.+warn.+error.+fatal/m
      end
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
right_support-2.11.3 spec/log/step_level_logger_spec.rb
right_support-2.11.2 spec/log/step_level_logger_spec.rb
right_support-2.10.1 spec/log/step_level_logger_spec.rb