Sha256: 6ed00b682862fe1274482b4edc6e2873bc56d1bafb87a9255464b1c9d0fd4b79

Contents?: true

Size: 1.68 KB

Versions: 12

Compression:

Stored size: 1.68 KB

Contents

require 'spec_helper'

class InnocentVictim
  include RightSupport::Log::Mixin
end

describe RightSupport::Log::Mixin do
  context 'when mixed into a base class' do
    before(:each) do
      @victim = InnocentVictim.new
    end

    it 'provides a class-level accessor' do
      @victim.class.should respond_to(:logger)
      @victim.class.should respond_to(:logger=)
    end

    it 'provides an instance-level accessor' do
      @victim.should respond_to(:logger)
    end

    context :logger do
      context 'without a logger' do
        before(:each) do
          @victim.class.logger = nil
        end

        it 'uses the default logger' do
          flexmock(RightSupport::Log::Mixin.default_logger).should_receive(:info).twice.and_return(true)
          @victim.class.logger.info('lalalala').should be_true
          @victim.logger.info('lalalala').should be_true
        end
      end

      context 'with class logger' do
        before(:each) do
          @logger = mock_logger
          @victim.class.logger = @logger
        end

        it 'uses class logger' do
          @logger.should_receive(:info).and_return(true).twice
          @victim.class.logger.info('lalalala').should be_true
          @victim.logger.info('lalalala').should be_true
        end

        context 'with instance logger' do
          before(:each) do
            @instance_logger = mock_logger
            @victim.logger = @instance_logger
          end

          it 'uses instance logger' do
            @instance_logger.should_receive(:info).and_return(true).once
            @logger.should_receive(:info).never
            @victim.logger.info('lalalala').should be_true
          end
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
right_support-2.8.12 spec/log/mixin_spec.rb
right_support-2.8.11 spec/log/mixin_spec.rb
right_support-2.8.10 spec/log/mixin_spec.rb
right_support-2.8.9 spec/log/mixin_spec.rb
right_support-2.8.8 spec/log/mixin_spec.rb
right_support-2.8.7 spec/log/mixin_spec.rb
right_support-2.8.6 spec/log/mixin_spec.rb
right_support-2.8.3 spec/log/mixin_spec.rb
right_support-2.8.2 spec/log/mixin_spec.rb
right_support-2.8.1 spec/log/mixin_spec.rb
right_support-2.8.0 spec/log/mixin_spec.rb
right_support-2.7.0 spec/log/mixin_spec.rb