Sha256: 49e2fbcaaf6feb0af79140f632b40fdc1440941adf789d566b59879c8f81df03

Contents?: true

Size: 1.42 KB

Versions: 25

Compression:

Stored size: 1.42 KB

Contents

require 'spec_helper'

describe Lumberjack::Formatter do

  let(:formatter){ Lumberjack::Formatter.new }
  
  it "should have a default set of formatters" do
    formatter.format("abc").should == "abc"
    formatter.format([1, 2, 3]).should == "[1, 2, 3]"
    formatter.format(ArgumentError.new("boom")).should == "ArgumentError: boom"
  end
  
  it "should be able to add a formatter object for a class" do
    formatter.add(Numeric, lambda{|obj| "number: #{obj}"})
    formatter.format(10).should == "number: 10"
  end
  
  it "should be able to add a formatter block for a class" do
    formatter.add(Numeric){|obj| "number: #{obj}"}
    formatter.format(10).should == "number: 10"
  end
  
  it "should be able to remove a formatter for a class" do
    formatter.remove(String)
    formatter.format("abc").should == "\"abc\""
  end
  
  it "should be able to chain add and remove calls" do
    formatter.remove(String).should == formatter
    formatter.add(String, Lumberjack::Formatter::StringFormatter.new).should == formatter
  end
  
  it "should format an object based on the class hierarchy" do
    formatter.add(Numeric){|obj| "number: #{obj}"}
    formatter.add(Fixnum){|obj| "fixed number: #{obj}"}
    formatter.format(10).should == "fixed number: 10"
    formatter.format(10.1).should == "number: 10.1"
  end
  
  it "should have a default formatter" do
    formatter.remove(Object)
    formatter.format(:test).should == ":test"
  end

end

Version data entries

25 entries across 23 versions & 7 rubygems

Version Path
gameboard-3.1.0 vendor/bundle/ruby/2.3.0/gems/lumberjack-1.0.10/spec/formatter_spec.rb
gameboard-3.0.0 vendor/bundle/ruby/2.3.0/gems/lumberjack-1.0.10/spec/formatter_spec.rb
honeybadger-2.4.0 vendor/gems/ruby/2.1.0/gems/lumberjack-1.0.9/spec/formatter_spec.rb
honeybadger-2.4.0 vendor/gems/ruby/1.9.1/gems/lumberjack-1.0.9/spec/formatter_spec.rb
honeybadger-2.4.0 vendor/gems/ruby/2.2.0/gems/lumberjack-1.0.9/spec/formatter_spec.rb
lumberjack-1.0.10 spec/formatter_spec.rb
mastermind_adeybee-0.1.4 vendor/bundle/ruby/2.2.0/gems/lumberjack-1.0.9/spec/formatter_spec.rb
mastermind_adeybee-0.1.3 vendor/bundle/ruby/2.2.0/gems/lumberjack-1.0.9/spec/formatter_spec.rb
mastermind_adeybee-0.1.2 vendor/bundle/ruby/2.2.0/gems/lumberjack-1.0.9/spec/formatter_spec.rb
mastermind_adeybee-0.1.1 vendor/bundle/ruby/2.2.0/gems/lumberjack-1.0.9/spec/formatter_spec.rb
geminfo-0.1.0 path/gems/lumberjack-1.0.9/spec/formatter_spec.rb
lumberjack-1.0.9 spec/formatter_spec.rb
lumberjack-1.0.8 spec/formatter_spec.rb
lumberjack-1.0.7 spec/formatter_spec.rb
lumberjack-1.0.6 spec/formatter_spec.rb
lumberjack-1.0.5 spec/formatter_spec.rb
lumberjack_aziz_light-1.0.6 spec/formatter_spec.rb
lumberjack_aziz_light-1.0.5 spec/formatter_spec.rb
lumberjack-1.0.4 spec/formatter_spec.rb
sidekiq-statsd-0.1.1 vendor/ruby/1.9.1/gems/lumberjack-1.0.3/spec/formatter_spec.rb