Sha256: 2d89cb09513b889d52816eb653ed3fe552e394be0530037e132d78bf25010125

Contents?: true

Size: 772 Bytes

Versions: 4

Compression:

Stored size: 772 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 = lambda 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 = lambda { raise 'k' }.call_safely { SafetyProc.called = true }
      SafetyProc.called.must_equal true
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
subtle-1.2.0 spec/subtle/safety_proc_spec.rb
subtle-1.1.1 spec/subtle/safety_proc_spec.rb
subtle-1.1.0 spec/subtle/safety_proc_spec.rb
subtle-1.0.0 spec/subtle/safety_proc_spec.rb