Sha256: 7b74816a2e8ad9d1127f822b4407863064388c7c00e42933ffbc7211f2bdc63d

Contents?: true

Size: 1.32 KB

Versions: 1

Compression:

Stored size: 1.32 KB

Contents

require "spec_helper"
require "logger"

module Mblox
  class << self
    def reset_configuration
      @config = Configuration.new
    end
  end
end

describe "logger" do
  before(:each) do
    Mblox.reset_configuration
  end

  after(:all) do
    set_configuration
  end

  it "should allow log level info" do
    Mblox.config.log_at :info
    Mblox.config.logger = ::Logger.new('/dev/null')
    expect { Mblox.log "Some info" }.to_not raise_error
  end

  it "should default to log level debug" do
    expect(Mblox.config.log_level).to eq(:debug)
    expect { Mblox.log "Some debug info" }.to_not raise_error
  end

  it "should not allow log level news when the logger is created after log level is set" do
    Mblox.config.log_at :news
    expect { Mblox.config.logger = ::Logger.new("STDOUT")}.to raise_error(ArgumentError, "Mblox log level must be set to :fatal, :error, :warn, :info or :debug")
    expect { Mblox.log "Some news" }.to_not raise_error
  end

  it "should not allow log level news when the logger is created before log level is set and should remain in a valid state" do
    Mblox.config.logger = ::Logger.new("/dev/null")
    expect { Mblox.config.log_at :news }.to raise_error(ArgumentError, "Mblox log level must be set to :fatal, :error, :warn, :info or :debug")
    expect { Mblox.log "Some news" }.to_not raise_error
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mblox-0.0.1 spec/log_spec.rb