Skip to content

Commit 4a1051d

Browse files
committed
feat: Add request spec for error pages
Rambulanceで生成されるエラーページ(404, 422, 500)が正しく 表示されることを確認するためのリクエストスペックを追加します。 各エラーを意図的に発生させるためのテスト用ルーティングを定義し、 それぞれのリクエストで期待されるステータスコードが返却されることを検証します。#
1 parent 4df3a8a commit 4a1051d

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

spec/requests/errors_spec.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,30 @@
33
RSpec.describe "Errors", type: :request do
44
include Rambulance::TestHelper
55

6+
before do
7+
# テスト用のルーティングを直接定義
8+
Rails.application.routes.draw do
9+
get '/trigger_403', to: ->(env) { raise ActionController::Forbidden }
10+
get '/trigger_422', to: ->(env) { raise ActionController::InvalidAuthenticityToken }
11+
get '/trigger_500', to: ->(env) { raise "This is a test 500 error" }
12+
end
13+
14+
# ビューのレンダリングをスタブして、レイアウト起因のエラーを回避
15+
allow_any_instance_of(Rambulance::ExceptionsApp).to receive(:render).and_wrap_original do |m, *args|
16+
options = args.last.is_a?(Hash) ? args.pop : {}
17+
m.call(*args, **options.merge(layout: false))
18+
end
19+
end
20+
21+
after do
22+
# テスト後に追加したルーティングを元に戻す
23+
Rails.application.reload_routes!
24+
end
25+
626
describe "Error requests" do
727
it 'renders the 404 error page' do
828
with_exceptions_app do
29+
# どのルーティングにもマッチしないパスをリクエスト
930
get '/does_not_exist'
1031
end
1132
expect(response.status).to eq(404)
@@ -27,5 +48,6 @@
2748
expect(response.status).to eq(500)
2849
expect(response.body).to include("子どものためのプログラミング道場")
2950
end
51+
3052
end
3153
end

0 commit comments

Comments
 (0)