spec/requests/error_page_spec.rb in rambulance-0.1.2 vs spec/requests/error_page_spec.rb in rambulance-0.2.0
- old
+ new
@@ -1,73 +1,89 @@
# encoding: UTF-8
require 'spec_helper'
-feature 'Error pages' do
+feature 'Error page' do
shared_examples_for "an action that renders 500 page if the template is missing" do
- scenario 'Unprocessable entity due to ActionController:InvalidAuthenticityToken but without its template' do
+ scenario 'displays 500 page and return 422 Bad Request status' do
visit '/users/new'
- page.status_code.should == 422
- page.body.should have_content "Error page"
- page.body.should have_content "Something went wrong."
+ 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 'with the default exceptions app', if: !ENV["CUSTOM_EXCEPTIONS_APP"] do
+ 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 'Internal server error due to RuntimeError' do
+ scenario 'displays 500 page due to RuntimeError' do
visit '/users/1'
- page.status_code.should == 500
- page.body.should have_content "Error page"
- page.body.should have_content "Something went wrong."
+ 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 'Not found due to CustomException' do
+ scenario 'displays 404 page due to CustomException' do
visit '/users'
- page.status_code.should == 404
- page.body.should have_content "Error page"
- page.body.should have_content "Page not found."
+ 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 'Not found due to ActinoController::RoutingError' do
+ scenario 'displays 404 page due to ActionController::RoutingError' do
visit '/doesnt_exist'
- page.status_code.should == 404
- page.body.should have_content "Error page"
- page.body.should have_content "Page not found."
+ 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'
- page.body.should have_content "Application page"
+ expect(page.body).to have_content "Application page"
end
end
end
- context "With a custom exception app", if: ENV["CUSTOM_EXCEPTIONS_APP"] do
+ 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 'Not found due to ActinoController::RoutingError' do
+ scenario 'displays 404 page due to ActinoController::RoutingError' do
visit '/doesnt_exist'
- page.status_code.should == 404
- page.body.should have_content "Error page"
- page.body.should have_content "Page not found."
+ 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 'Internal server error due to RuntimeError' do
+ scenario 'displays 500 page due to RuntimeError' do
visit '/users/1'
- page.status_code.should == 500
- page.body.should have_content "Custom error page"
+ expect(page.status_code).to eq(500)
+ expect(page.body).to have_content "Custom error page"
end
end
end