コントローラーのテストで例外が発生してテストが失敗する
解決
context に、 show_exceptions: true オプションを設定する。
context "failed", show_exceptions: true do ... end Rails アプリケーションの不安定なテストを撲滅したい 〜system spec のデバッグ方法とテストを不安定にさせる要因〜 - あらびき日記
事象
APIのレスポンスチェックのテストを作成したが、 api_get を実行した時点で例外が発生してテストが失敗する。
テスト
subject { api_get "/path/to/api" } context "failed" do before do # something for failed end example "XXXX のため、エラー" do subject expect(response).to have_http_status(:forbidden) end end エラー内容
Failure/Error: raise ForbiddenError HogeController::ForbiddenError: アクセス権限がありません # ./app/controllers/hoge_controller.rb:88:in `response_forbidden' # ./app/controllers/hoge_controller.rb:51:in `block_foreign_hosts' ... This post is licensed under CC BY 4.0 by the author.