File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed
Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change 33RSpec . 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 )
2748 expect ( response . status ) . to eq ( 500 )
2849 expect ( response . body ) . to include ( "子どものためのプログラミング道場" )
2950 end
51+
3052 end
3153end
You can’t perform that action at this time.
0 commit comments