# 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