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 3
3
RSpec . describe "Errors" , type : :request do
4
4
include Rambulance ::TestHelper
5
5
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
+
6
26
describe "Error requests" do
7
27
it 'renders the 404 error page' do
8
28
with_exceptions_app do
29
+ # どのルーティングにもマッチしないパスをリクエスト
9
30
get '/does_not_exist'
10
31
end
11
32
expect ( response . status ) . to eq ( 404 )
27
48
expect ( response . status ) . to eq ( 500 )
28
49
expect ( response . body ) . to include ( "子どものためのプログラミング道場" )
29
50
end
51
+
30
52
end
31
53
end
You can’t perform that action at this time.
0 commit comments