Sha256: 246988be8bc55d199d3b6c8d4c8cacb062efe610c3a7daf51876d7400bb7a188

Contents?: true

Size: 1.21 KB

Versions: 3

Compression:

Stored size: 1.21 KB

Contents

require File.dirname(__FILE__) + '/../test_helper'

class MyClass
  def logged_method
    logger.debug 'message'
  end
end

module MyModule; end

class LogMethodsTest < Test::Unit::TestCase
  context "An instance of MyClass, with loggable mix-in" do

    setup    { @logger = mock() }
    teardown { MyClass.logger = nil}

    should "have a logger stub by default" do
      MyClass.logger.should be_instance_of(Logger)
    end

    should "not fail when an instance calls an uninitialized logger" do
      m = MyClass.new
      lambda { m.logged_method }.should_not raise_error
    end

    should "allow the asssignment of a logger" do
      MyClass.logger = @logger
      MyClass.logger.should == @logger
    end

    should "allow access to the logger from an instance" do
      MyClass.logger = @logger
      MyClass.new.logger.should == @logger
    end

  end

  context "MyModule, with loggable mix-in" do

    should "have a logger stub by default" do
      MyModule.logger = nil
      MyModule.logger.should be_kind_of(Logger)
    end

    should "be able to log messages" do
      logger = mock()
      logger.expects(:debug).with('blip')
      
      MyModule.logger = logger
      MyModule.logger.debug('blip')
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
mediashelf-loggable-0.4.2 test/examples/log_methods_test.rb
mediashelf-loggable-0.4.1 test/examples/log_methods_test.rb
mediashelf-loggable-0.4.0 test/examples/log_methods_test.rb