Sha256: 2ea4580f129c54908968b1256676c3830c122f2b5b127a7e82d3d573b7b7be25

Contents?: true

Size: 1.42 KB

Versions: 9

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(Integer){|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

9 entries across 9 versions & 5 rubygems

Version Path
honeybadger-4.5.3 vendor/bundle/ruby/2.6.0/gems/lumberjack-1.0.13/spec/formatter_spec.rb
alimentos-alu0100945645-0.1.0 vendor/bundle/ruby/2.3.0/gems/lumberjack-1.0.13/spec/formatter_spec.rb
alimentos-alu0100945645-1.0.0 vendor/bundle/ruby/2.3.0/gems/lumberjack-1.0.13/spec/formatter_spec.rb
lumberjack-1.0.13 spec/formatter_spec.rb
comiditaULL-0.1.1 vendor/bundle/ruby/2.3.0/gems/lumberjack-1.0.12/spec/formatter_spec.rb
comidita_ull-0.1.1 vendor/bundle/ruby/2.3.0/gems/lumberjack-1.0.12/spec/formatter_spec.rb
comidita_ull-0.1.0 vendor/bundle/ruby/2.3.0/gems/lumberjack-1.0.12/spec/formatter_spec.rb
lumberjack-1.0.12 spec/formatter_spec.rb
lumberjack-1.0.11 spec/formatter_spec.rb