Sha256: d24522893fea6e12360558b3283ea2d31ab53ac6b2fb5dbf766399eab5606441

Contents?: true

Size: 1.92 KB

Versions: 26

Compression:

Stored size: 1.92 KB

Contents

require 'spec_helper'

describe Errplane::BlackBox do
  before do
    begin
      1/0
    rescue Exception => e
      @exception = e
    end
  end

  describe ".new" do
    it "should create a new BlackBox" do
      black_box = Errplane::BlackBox.new
    end

    it "should accept an exception as a parameter" do

      black_box = Errplane::BlackBox.new(:exception => @exception)
      black_box.should_not be_nil
    end
  end

  describe "#to_json" do
    it "should return a JSON string" do
      black_box = Errplane::BlackBox.new(:exception => @exception)
      json = JSON.parse(black_box.to_json)

      json["message"].should == "divided by 0"
      json["time"].should_not be_nil
      json["backtrace"].should_not be_nil
    end

    it "should include a custom hash if defined in the errplane config" do
      Errplane.configure do |config|
        config.define_custom_exception_data do |black_box|
          if black_box.exception.class ==  ZeroDivisionError
            black_box.hash = "some_hash"
            black_box.custom_data[:extra_info] = "blah"
          end
        end
      end

      black_box = Errplane::BlackBox.new(:exception => @exception)
      json = JSON.parse(black_box.to_json)
      json["hash"].should == "some_hash"
      json["custom_data"]["extra_info"].should == "blah"
    end

    describe "environment variables" do
      it "should be filtered based on the contents of environment_variable_filters" do
        Errplane.configure do |config|
          config.environment_variable_filters = [/password/i]
        end

        black_box = Errplane::BlackBox.new(
          :exception => @exception,
          :environment_variables => {
            "IMPORTANT_PASSWORD" => "sesame",
            "EDITOR" => "vim"
        })

        json = JSON.parse(black_box.to_json)
        json["environment_variables"].size.should == 1
        json["environment_variables"].should == {"EDITOR" => "vim"}
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
errplane-1.0.0 spec/unit/black_box_spec.rb
errplane-0.6.10 spec/unit/black_box_spec.rb
errplane-0.6.9 spec/unit/black_box_spec.rb
errplane-0.6.8 spec/unit/black_box_spec.rb
errplane-0.6.7 spec/unit/black_box_spec.rb
errplane-0.6.6 spec/unit/black_box_spec.rb
errplane-0.6.5 spec/unit/black_box_spec.rb
errplane-0.6.4 spec/unit/black_box_spec.rb
errplane-0.6.3 spec/unit/black_box_spec.rb
errplane-0.6.2 spec/unit/black_box_spec.rb
errplane-0.6.1 spec/unit/black_box_spec.rb
errplane-0.6.0 spec/unit/black_box_spec.rb
errplane-0.5.30 spec/unit/black_box_spec.rb
errplane-0.5.29 spec/unit/black_box_spec.rb
errplane-0.5.28 spec/unit/black_box_spec.rb
errplane-0.5.27 spec/unit/black_box_spec.rb
errplane-0.5.26 spec/unit/black_box_spec.rb
errplane-0.5.25 spec/unit/black_box_spec.rb
errplane-0.5.24 spec/unit/black_box_spec.rb
errplane-0.5.23 spec/unit/black_box_spec.rb