Sha256: 51d4f413497e3c17d646ffa4e9e97a86b2f7f5a8031d8619878bee8239d0435d

Contents?: true

Size: 1.62 KB

Versions: 17

Compression:

Stored size: 1.62 KB

Contents

# encoding: utf-8
require 'spec_helper'

describe Actions::HandleError do
  context '#initialize' do
    it 'requires an exception' do
      expect {
        Actions::HandleError.new(Exceptions::DefaultError.new('message'))
      }.not_to raise_error
    end
  end

  context '#run' do
    it 'handles errors' do
      action = Actions::HandleError.new(RuntimeError.new)

      silence(:stderr) do
        begin
          action.run
        rescue SystemExit => e
          @err = e
        end
      end

      expect(@err).to be_kind_of(SystemExit)
      expect(@err.status).to be(99)
    end

    it 'parses original message with json' do
      action = Actions::HandleError.new(RuntimeError.new(JSON.dump(name: 'asdf')))

      silence(:stderr) do
        begin
          action.run
        rescue SystemExit => e
          @err = e
        end
      end

      expect(@err).to be_kind_of(SystemExit)
      expect(@err.status).to be(99)
    end

    it 'returns an empty hash on parse error' do
      action = Actions::HandleError.new(RuntimeError.new('asdf'))

      silence(:stderr) do
        begin
          action.run
        rescue SystemExit => e
          @err = e
        end
      end

      expect(@err).to be_kind_of(SystemExit)
      expect(@err.status).to be(99)
    end

    it 'returns an empty hash if result is not a hash' do
      action = Actions::HandleError.new(RuntimeError.new(JSON.dump(['asdf'])))

      silence(:stderr) do
        begin
          action.run
        rescue SystemExit => e
          @err = e
        end
      end

      expect(@err).to be_kind_of(SystemExit)
      expect(@err.status).to be(99)
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
proxy_tester-0.1.10 spec/actions/handle_error_spec.rb
proxy_tester-0.1.8 spec/actions/handle_error_spec.rb
proxy_tester-0.1.6 spec/actions/handle_error_spec.rb
proxy_tester-0.1.5 spec/actions/handle_error_spec.rb
proxy_tester-0.1.4 spec/actions/handle_error_spec.rb
proxy_tester-0.1.3 spec/actions/handle_error_spec.rb
proxy_tester-0.1.2 spec/actions/handle_error_spec.rb
proxy_tester-0.1.1 spec/actions/handle_error_spec.rb
proxy_tester-0.1.0 spec/actions/handle_error_spec.rb
proxy_tester-0.0.9 spec/actions/handle_error_spec.rb
proxy_tester-0.0.8 spec/actions/handle_error_spec.rb
proxy_tester-0.0.7 spec/actions/handle_error_spec.rb
proxy_tester-0.0.6 spec/actions/handle_error_spec.rb
proxy_tester-0.0.5 spec/actions/handle_error_spec.rb
proxy_tester-0.0.4 spec/actions/handle_error_spec.rb
proxy_tester-0.0.3 spec/actions/handle_error_spec.rb
proxy_tester-0.0.2 spec/actions/handle_error_spec.rb