Sha256: 8d60f6b99507f088d489aa21afcff578512b9cb7ddb561a72d37a32d7f6af5a5

Contents?: true

Size: 1.27 KB

Versions: 2

Compression:

Stored size: 1.27 KB

Contents

# -*- rspec -*-

BEGIN {
	require 'pathname'
	basedir = Pathname( __FILE__ ).dirname.parent.parent
	$LOAD_PATH.unshift( basedir.to_s ) unless $LOAD_PATH.include?( basedir.to_s )
}

require 'tempfile'
require 'rspec'
require 'spec/lib/helpers'
require 'loggability/logger'
require 'loggability/formatter'
require 'loggability/formatter/default'


describe Loggability::Formatter do

	it "loads plugins out of loggability/formatter" do
		Loggability::Formatter.derivative_dirs.should == ['loggability/formatter']
	end


	it "formats messages with the pattern it's constructed with" do
		formatter = Loggability::Formatter.new( '[%5$s] %7$s' )
		formatter.call( 'INFO', Time.at(1336286481), nil, 'Foom.' ).should =~
			/\[INFO\] Foom./
	end

	it "formats exceptions into useful messages" do
		formatter = Loggability::Formatter.new( '[%5$s] %7$s' )
		msg = nil

		begin
			raise ArgumentError, "invalid argument"
		rescue => err
			msg = formatter.call( 'INFO', Time.at(1336286481), nil, err )
		end

		msg.should =~ /\[INFO\] ArgumentError: invalid argument/i
	end

	it "formats regular objects into useful messages" do
		formatter = Loggability::Formatter.new( '[%5$s] %7$s' )
		formatter.call( 'INFO', Time.at(1336286481), nil, Object.new ).should =~
			/\[INFO\] #<Object:0x\p{XDigit}+>/i
	end

end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
loggability-0.0.2 spec/loggability/formatter_spec.rb
loggability-0.0.1 spec/loggability/formatter_spec.rb