Sha256: caf3dceb3667b91ba33a11de6007a9dc60dc22ba249598da46f60828f54e085f
Contents?: true
Size: 1.31 KB
Versions: 9
Compression:
Stored size: 1.31 KB
Contents
require 'spec_helper' describe ActionController, :type => :controller do controller do def index raise ArgumentError.new end end before do routes.draw { get 'index' => "anonymous#index" } end describe "when a controller raises an error" do it 'returns a 500 response when a general error is raised' do get :index expect(response.status).to eq(500) expect(JSON.parse(response.body)['error']).to eq('ArgumentError') end it 'returns a custom error message when available' do allow(controller).to receive(:index).and_raise(ArgumentError.new('some error')) get :index expect(response.status).to eq(500) expect(JSON.parse(response.body)['error']).to eq('some error') end it 'returns a 404 response when a record is not found' do allow(controller).to receive(:index).and_raise(ActiveRecord::RecordNotFound.new) get :index expect(response.status).to eq(404) expect(JSON.parse(response.body)['error']).to eq('ActiveRecord::RecordNotFound') end it 'returns a 403 response when Forbidden' do allow(controller).to receive(:index).and_raise(Exceptionally::Forbidden.new) get :index expect(response.status).to eq(403) expect(JSON.parse(response.body)['error']).to eq('Forbidden') end end end
Version data entries
9 entries across 9 versions & 1 rubygems