aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/testing/assertions/response.rb
diff options
context:
space:
mode:
authorKir Shatrov <shatrov@me.com>2016-09-12 17:56:38 -0400
committerKir Shatrov <shatrov@me.com>2016-09-14 11:30:09 -0400
commitbc3b0e729282b6474f217806c14f293584dd8c97 (patch)
tree65c9914c4270ed1c49fb6ea27c9929da7d07a907 /actionpack/lib/action_dispatch/testing/assertions/response.rb
parentcf5f55cd30aef0f90300c7c8f333060fe258cd8a (diff)
downloadrails-bc3b0e729282b6474f217806c14f293584dd8c97.tar.gz
rails-bc3b0e729282b6474f217806c14f293584dd8c97.tar.bz2
rails-bc3b0e729282b6474f217806c14f293584dd8c97.zip
Improve assert_response helper
When the check is failed, print the actual response body if it's not too large. This could improve productivity when writing new tests. Before: ``` ThemeEditorIntegrationTest#test_whatever Expected response to be a <200: ok>, but was a <422: Unprocessable Entity>. Expected: 200 Actual: 422 ``` After: ``` ThemeEditorIntegrationTest#test_whatever Expected response to be a <200: ok>, but was a <422: Unprocessable Entity>. Expected: 200 Actual: 422 Response body: {"errors":["Invalid settings object for section '1'"]} ```
Diffstat (limited to 'actionpack/lib/action_dispatch/testing/assertions/response.rb')
-rw-r--r--actionpack/lib/action_dispatch/testing/assertions/response.rb7
1 files changed, 6 insertions, 1 deletions
diff --git a/actionpack/lib/action_dispatch/testing/assertions/response.rb b/actionpack/lib/action_dispatch/testing/assertions/response.rb
index a00602ed70..a2eaccd9ef 100644
--- a/actionpack/lib/action_dispatch/testing/assertions/response.rb
+++ b/actionpack/lib/action_dispatch/testing/assertions/response.rb
@@ -79,7 +79,12 @@ module ActionDispatch
def generate_response_message(expected, actual = @response.response_code)
"Expected response to be a <#{code_with_name(expected)}>,"\
" but was a <#{code_with_name(actual)}>"
- .concat location_if_redirected
+ .concat(location_if_redirected).concat(response_body_if_short)
+ end
+
+ def response_body_if_short
+ return "" if @response.body.size > 500
+ "\nResponse body: #{@response.body}"
end
def location_if_redirected