Sha256: 0aab61fefbc8906c61a140e851736a09783685614478357d30488b5a1a073258

Contents?: true

Size: 1.04 KB

Versions: 8

Compression:

Stored size: 1.04 KB

Contents

# -*- rspec -*-

require_relative '../helpers'

require 'tempfile'
require 'rspec'

require 'loggability/logger'
require 'loggability/formatter'
require 'loggability/formatter/default'


describe Loggability::Formatter do

	it "formats messages with the pattern it's constructed with" do
		formatter = Loggability::Formatter.new( '[%5$s] %7$s' )
		result = formatter.call( 'INFO', Time.at(1336286481), nil, 'Foom.' )
		expect( result ).to match(/\[INFO\] Foom./i)
	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

		expect( msg ).to match(/\[INFO\] ArgumentError: invalid argument/i)
	end

	it "formats regular objects into useful messages" do
		formatter = Loggability::Formatter.new( '[%5$s] %7$s' )
		result = formatter.call( 'INFO', Time.at(1336286481), nil, Object.new )

		expect( result ).to match(/\[INFO\] #<Object:0x[[:xdigit:]]+>/i)
	end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
loggability-0.11.0 spec/loggability/formatter_spec.rb
loggability-0.10.1 spec/loggability/formatter_spec.rb
loggability-0.10.0 spec/loggability/formatter_spec.rb
loggability-0.9.0 spec/loggability/formatter_spec.rb
loggability-0.9.0.pre.73 spec/loggability/formatter_spec.rb
loggability-0.8.1 spec/loggability/formatter_spec.rb
loggability-0.8.0 spec/loggability/formatter_spec.rb
loggability-0.8.0.pre.65 spec/loggability/formatter_spec.rb