Sha256: 087c0976e8ef153b002d70e360685e921027e325aa932115e83099593279d326

Contents?: true

Size: 901 Bytes

Versions: 2

Compression:

Stored size: 901 Bytes

Contents

# frozen_string_literal: true

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 PermanentFileSystemError, 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

2 entries across 2 versions & 1 rubygems

Version Path
ftpd-2.0.1 spec/translate_exceptions_spec.rb
ftpd-2.0.0 spec/translate_exceptions_spec.rb