Sha256: c00fe615a4d0cb2eba1f852a22f8b0e00883a8d1c6d5f1fbdd047f2ad50fa287

Contents?: true

Size: 861 Bytes

Versions: 3

Compression:

Stored size: 861 Bytes

Contents

require File.expand_path('spec_helper', File.dirname(__FILE__))

module Ftpd
  describe TranslateExceptions do

    class FooError < StandardError ; end
    class BarError < StandardError ; end

    class Subject

      include TranslateExceptions

      def initialize
        translate_exception FooError
      end

      def raise_error(error, message)
        raise error, message
      end
      translate_exceptions :raise_error

    end

    let(:subject) {Subject.new}
    let(:message) {'An error happened'}

    it 'should translate a registered error' do
      expect {
        subject.raise_error(FooError, message)
      }.to raise_error FileSystemError, message
    end

    it 'should pass through an unregistered error' do
      expect {
        subject.raise_error(BarError, message)
      }.to raise_error BarError, message
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ftpd-0.2.0 spec/translate_exceptions_spec.rb
ftpd-0.1.1 spec/translate_exceptions_spec.rb
ftpd-0.1.0 spec/translate_exceptions_spec.rb