Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 62ad7c3

Browse files
committed
エラーページ(404/500/422)のリクエストテストを追加
1 parent 677d005 commit 62ad7c3

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

config/routes.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,10 @@
106106
# Check development sent emails
107107
mount LetterOpenerWeb::Engine, at: "/letter_opener" if Rails.env.development?
108108
mount Rambulance::Engine => "/"
109+
110+
if Rails.env.development? || Rails.env.test?
111+
get "/trigger_500", to: ->(env) { raise "Triggering 500 error" }
112+
get "/trigger_422", to: "errors#unprocessable_entity"
113+
end
114+
109115
end

spec/requests/errors_spec.rb

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,25 @@
44
include Rambulance::TestHelper
55

66
describe "Error requests" do
7-
it 'should render a corresponding error page' do
7+
it 'renders the 404 error page' do
88
with_exceptions_app do
99
get '/does_not_exist'
1010
end
11+
expect(response.status).to eq(404)
12+
end
1113

12-
assert_equal 404, response.status
14+
it 'renders the 422 error page' do
15+
with_exceptions_app do
16+
get '/trigger_422'
17+
end
18+
expect(response.status).to eq(422)
19+
end
20+
21+
it 'renders the 500 error page' do
22+
with_exceptions_app do
23+
get '/trigger_500'
24+
end
25+
expect(response.status).to eq(500)
1326
end
1427
end
1528
end

0 commit comments

Comments
 (0)