# encoding: UTF-8 require 'spec_helper' feature 'Error page' do shared_examples_for "an action that renders 500 page if the template is missing" do scenario 'displays 500 page and return 422 Bad Request status' do visit '/users/new' expect(page.status_code).to eq(422) expect(page.body).to have_content "Error page" expect(page.body).to have_content "Something went wrong." end end context 'generated by the default exceptions app', if: !ENV["CUSTOM_EXCEPTIONS_APP"] do it_behaves_like "an action that renders 500 page if the template is missing" scenario 'displays 500 page due to RuntimeError' do visit '/users/1' expect(page.status_code).to eq(500) expect(page.body).to have_content "Error page" expect(page.body).to have_content "Something went wrong." end scenario 'displays 404 page due to CustomException' do visit '/users' expect(page.status_code).to eq(404) expect(page.body).to have_content "Error page" expect(page.body).to have_content "Page not found." end scenario 'displays 404 page due to ActionController::RoutingError' do visit '/doesnt_exist' expect(page.status_code).to eq(404) expect(page.body).to have_content "Error page" expect(page.body).to have_content "Page not found." end scenario 'displays 400 page when malformed parameters' do page.driver.post '/users?x[y]=1&x[y][][w]=2' expect(page.status_code).to eq(400) expect(page.body).to have_content "Error page" expect(page.body).to have_content "Bad request." end scenario 'displays 404 page for non-existing page when malformed parameters' do page.driver.post '/doesnt_exist?x[y]=1&x[y][][w]=2' expect(page.status_code).to eq(404) expect(page.body).to have_content "Error page" expect(page.body).to have_content "Page not found." end context "with a custom layout name" do before do @org, Rambulance.layout_name = Rambulance.layout_name, "application" end after { Rambulance.layout_name = @org } scenario 'uses the custom layout' do visit '/doesnt_exist' expect(page.body).to have_content "Application page" end end end context "generated by a custom exception app", if: ENV["CUSTOM_EXCEPTIONS_APP"] do it_behaves_like "an action that renders 500 page if the template is missing" scenario 'displays 404 page due to ActinoController::RoutingError' do visit '/doesnt_exist' expect(page.status_code).to eq(404) expect(page.body).to have_content "Error page" expect(page.body).to have_content "Page not found." end scenario 'displays 500 page due to RuntimeError' do visit '/users/1' expect(page.status_code).to eq(500) expect(page.body).to have_content "Custom error page" end end end