Skip to content

Commit 9b25662

Browse files
committed
test: エラーページ(404, 422, 500, 400)のリクエストスペックを追加
エラーページが正しく表示されることを検証する、 リクエストスペックを追加・改善しました。 - ErrorsHelperを読み込み、具体的な文言ではなく ヘルパーの実行結果を検証することで、将来の文言変更に 強いテストに変更。 - これまでテストできていなかった400エラー(else句)の テストケースも追加完了。
1 parent 37ed1c4 commit 9b25662

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

spec/requests/errors_spec.rb

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
RSpec.describe "Errors", type: :request do
44
include Rambulance::TestHelper
5+
include ErrorsHelper
56

67
before do
78
# テスト用のルーティングを直接定義
89
Rails.application.routes.draw do
9-
get '/trigger_403', to: ->(env) { raise ActionController::Forbidden }
10+
get '/trigger_400', to: ->(env) { raise ActionController::BadRequest }
1011
get '/trigger_422', to: ->(env) { raise ActionController::InvalidAuthenticityToken }
1112
get '/trigger_500', to: ->(env) { raise "This is a test 500 error" }
1213
end
@@ -30,24 +31,34 @@
3031
get '/does_not_exist'
3132
end
3233
expect(response.status).to eq(404)
33-
expect(response.body).to include("子どものためのプログラミング道場")
34+
expect(response.body).to include(error_title(404))
35+
expect(response.body).to include(error_desc(404))
3436
end
3537

3638
it 'renders the 422 error page' do
3739
with_exceptions_app do
3840
get '/trigger_422'
3941
end
4042
expect(response.status).to eq(422)
41-
expect(response.body).to include("子どものためのプログラミング道場")
43+
expect(response.body).to include(error_title(422))
44+
expect(response.body).to include(error_desc(422))
4245
end
4346

4447
it 'renders the 500 error page' do
4548
with_exceptions_app do
4649
get '/trigger_500'
4750
end
4851
expect(response.status).to eq(500)
49-
expect(response.body).to include("子どものためのプログラミング道場")
52+
expect(response.body).to include(error_title(500))
53+
expect(response.body).to include(error_desc(500))
54+
end
55+
it 'renders the 400 error page' do
56+
with_exceptions_app do
57+
get '/trigger_400'
58+
end
59+
expect(response.status).to eq(400)
60+
expect(response.body).to include(error_title(400))
61+
expect(response.body).to include(error_desc(400))
5062
end
51-
5263
end
5364
end

0 commit comments

Comments
 (0)