Sha256: 2c723ea6b349947d38e0be47784eb3cd7f68637257820fd74685ebc61fa20423

Contents?: true

Size: 1.64 KB

Versions: 5

Compression:

Stored size: 1.64 KB

Contents

# -*- encoding: utf-8 -*-

require File.join(File.dirname(__FILE__), "/spec_helper")

describe MetaInspector::ExceptionLog do
  let(:logger) { MetaInspector::ExceptionLog.new }

  describe "storing exceptions" do
    it "should store exceptions" do
      expect {
        logger << StandardError.new("an error message")
      }.to change { logger.exceptions.length }.from(0).to(1)
    end

    it "should return stored exceptions" do
      first   = StandardError.new("first message")
      second  = StandardError.new("second message")

      logger << first
      logger << second

      logger.exceptions.should == [first, second]
    end
  end

  describe "ok?" do
    it "should be true if no exceptions stored" do
      logger.should be_ok
    end

    it "should be false if some exception stored" do
      logger << StandardError.new("some message")
      logger.should_not be_ok
    end
  end

  describe "warn_level" do
    it "should be quiet by default" do
      MetaInspector::ExceptionLog.new.warn_level.should be_nil
    end

    it "should warn about the error if warn_level is :warn" do
      verbose_logger = MetaInspector::ExceptionLog.new(warn_level: :warn)
      exception      = StandardError.new("an error message")

      verbose_logger.should_receive(:warn).with(exception)
      verbose_logger << exception
    end

    it "should raise exceptions when warn_level is :raise" do
      raiser_logger = MetaInspector::ExceptionLog.new(warn_level: :raise)
      exception     = StandardError.new("this should be raised")

      expect {
        raiser_logger << exception
      }.to raise_exception(StandardError, "this should be raised")
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
metainspector-2.0.0 spec/exception_log_spec.rb
metainspector-1.17.3 spec/exception_log_spec.rb
metainspector-1.17.2 spec/exception_log_spec.rb
metainspector-1.17.1 spec/exception_log_spec.rb
metainspector-1.17.0 spec/exception_log_spec.rb