こんにちは!
Rspecで自分でカスタムした500ページが表示されるかどうかのテストを書きたいのですが、
うまくいかず質問させていただきました!
発生しているエラー
Exception: Exception # ./spec/requests/errors_spec.rb:38:in `block (2 levels) in <top (required)>'
下記のerrors_spec.rbで意図的にExceptionエラーを発生させているのですが、RSpecがここで止まってしまって、これ以降の処理を実行してくれない状況です。
前提とソースコード
エラーハンドリングは以下の手順で行っています。
config/initializers/exceptions_app.rb
Rails.configuration.exceptions_app = ->(env) { ErrorsController.action(:show).call(env) }
app/controllers/errors_controller.rb
class ErrorsController < ActionController::Base rescue_from Exception, with: :render_500 rescue_from ActiveRecord::RecordNotFound, with: :render_404 rescue_from ActionController::RoutingError, with: :render_404 def show exception = request.env["action_dispatch.exception"] raise exception end private def locale_ja? params[:locale] == "ja" || I18n.default_locale == :ja end def render_500 if locale_ja? render template: "errors/500.ja", status: 500, layout: "application", content_type: "text/html" else render template: "errors/500.en", status: 500, layout: "application", content_type: "text/html" end end
errors_spec.rb
it "renders 500" do allow_any_instance_of(ErrorsController).to receive(:show).and_return(raise Exception) expect(response).to render_template("errors/500.ja") end
なにかいいアディアがございましたらご教授ください!
よろしくお願いします!
回答1件
あなたの回答
tips
プレビュー