Sha256: 8ae868ea78c651f08d226461da5372e95df5f8d26cc38b2889146f7bac6be0fd

Contents?: true

Size: 764 Bytes

Versions: 7

Compression:

Stored size: 764 Bytes

Contents

require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')

module SafetyProc
  class << self
    attr_accessor :called
  end
end

describe "Safety Proc" do
  describe "a proc that will throw an exception" do
    before do
      SafetyProc.called = false
      @proc = -> do 
        SafetyProc.called = true
        raise 'k'
      end
    end

    it "should trap the exception yet still call the method" do
      @proc.call_safely
      SafetyProc.called.must_equal true
    end
  end

  describe "a proc with a block to call on error" do
    before do
      SafetyProc.called = false
    end

    it "call the block" do
      @proc = -> { raise 'k' }.call_safely { SafetyProc.called = true }
      SafetyProc.called.must_equal true
    end
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
subtle-0.3.8 spec/subtle/safety_proc_spec.rb
subtle-0.3.6 spec/subtle/safety_proc_spec.rb
subtle-0.3.5 spec/subtle/safety_proc_spec.rb
subtle-0.3.4 spec/subtle/safety_proc_spec.rb
smoke_monster-0.3.3 spec/smoke_monster/safety_proc_spec.rb
smoke_monster-0.3.2 spec/smoke_monster/safety_proc_spec.rb
smoke_monster-0.3.0 spec/smoke_monster/safety_proc_spec.rb