Sha256: 085852f71e32f15d0aaa0c1e8173e4c7fa51fb880e48777c20f7b21b2c4ffeb4

Contents?: true

Size: 1.3 KB

Versions: 3

Compression:

Stored size: 1.3 KB

Contents

require 'spec_helper'

describe "configuring error backends" do
  it "adds the error backend class to the config" do
    some_backend_class = Struct.new(:save)
    Failsafe.error_backends << some_backend_class
    Failsafe.error_backends.should include some_backend_class
  end
end

describe Failsafe, ".failsafe" do
  class DangerousClass
    def boom_boom
      raise RuntimeError.new "room!"
    end
  end

  before { Failsafe.error_backends << MockFailureBackend }
  let(:danger) { DangerousClass.new }

  subject { Failsafe.failsafe { danger.boom_boom } }

  it "does not raise an error when wrapped with failsafe" do
    expect {
      subject
    }.not_to raise_error
  end

  it "notifies backends of the exception" do
    MockFailureBackend.any_instance.expects(:save)
    subject
  end
end

describe "disabling failsafe" do
  it "is not disabled by default" do
    Failsafe.should_not be_disabled
  end

  context "when false" do
    before { Failsafe.disabled = false }

    it "allows exception to bubble up" do
      expect {
        Failsafe.failsafe { raise 'boom' }
      }.not_to raise_error
    end
  end

  context "when true" do
    before { Failsafe.disabled = true }

    it "allows errors to bubble up" do
      expect {
        Failsafe.failsafe { raise 'boom' }
      }.to raise_error
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
failsafe-0.2.1 spec/failsafe_spec.rb
failsafe-0.2.0 spec/failsafe_spec.rb
failsafe-0.1.0 spec/failsafe_spec.rb