Sha256: cc9bd2cf61be479a9abbebe6e94c924f534db40865ada142266f1cce36573f04

Contents?: true

Size: 1.15 KB

Versions: 2

Compression:

Stored size: 1.15 KB

Contents

# encoding: utf-8

require 'spec_helper'

describe Rbm::Exceptional do
  describe '#errors_with_message' do
    specify 'rescue an exception if message match' do
      e_socket = -> {
        begin; fail 'Timeout socket'; rescue errors_with_message(/socket/); end
      }
      expect(&e_socket).to_not raise_exception
    end

    specify 'do not rescue an exception if no message match' do
      e_none_socket = -> {
        begin; fail 'Timeout without correct token'; rescue errors_with_message(/socket/); end
      }
      expect(&e_none_socket).to raise_exception(RuntimeError, 'Timeout without correct token')
    end
  end

  describe NestedException do
    specify 'wraps $! exception' do
      begin
        fail 'OriginalException'
      rescue => e_original
        begin
          raise NestedException, e_original.message + '::NestingException'
        rescue => e_nesting
          e_nesting.should respond_to :original
          e_nesting.original.should be e_original
          e_nesting.message.should          == 'OriginalException::NestingException'
          e_nesting.original.message.should == 'OriginalException'
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rubymisc-0.2.0 spec/rubymisc/exceptional_spec.rb
rubymisc-0.1.0 spec/rubymisc/exceptional_spec.rb