From 4f0fa13eb85994b747c1eb253e346b76b98b5c5b Mon Sep 17 00:00:00 2001 From: Lin Jen-Shin Date: Fri, 11 Aug 2017 20:50:35 +0800 Subject: Show error message for API 500 error in tests, and document have_gitlab_http_status --- doc/development/testing.md | 9 +++++++++ lib/api/helpers.rb | 10 +++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/doc/development/testing.md b/doc/development/testing.md index ea94c87d8c6..ac1865f6682 100644 --- a/doc/development/testing.md +++ b/doc/development/testing.md @@ -270,6 +270,15 @@ complexity of RSpec expectations.They should be placed under a certain type of specs only (e.g. features, requests etc.) but shouldn't be if they apply to multiple type of specs. +#### have_gitlab_http_status + +Prefer `have_gitlab_http_status` over `have_http_status` because the former +could also show the response body whenever the status mismatched. This would +be very useful whenever some tests start breaking and we would love to know +why without editing the source and rerun the tests. + +This is especially useful whenever it's showing 500 internal server error. + ### Shared contexts All shared contexts should be be placed under `spec/support/shared_contexts/`. diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb index 99b8b62691f..3582ed81b0f 100644 --- a/lib/api/helpers.rb +++ b/lib/api/helpers.rb @@ -257,7 +257,15 @@ module API message << " " << trace.join("\n ") API.logger.add Logger::FATAL, message - rack_response({ 'message' => '500 Internal Server Error' }.to_json, 500) + + response_message = + if Rails.env.test? + message + else + '500 Internal Server Error' + end + + rack_response({ 'message' => response_message }.to_json, 500) end # project helpers -- cgit v1.2.1