diff options
author | Kir Shatrov <shatrov@me.com> | 2016-09-12 17:56:38 -0400 |
---|---|---|
committer | Kir Shatrov <shatrov@me.com> | 2016-09-14 11:30:09 -0400 |
commit | bc3b0e729282b6474f217806c14f293584dd8c97 (patch) | |
tree | 65c9914c4270ed1c49fb6ea27c9929da7d07a907 /actionpack/lib/action_dispatch/testing/assertions | |
parent | cf5f55cd30aef0f90300c7c8f333060fe258cd8a (diff) | |
download | rails-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')
-rw-r--r-- | actionpack/lib/action_dispatch/testing/assertions/response.rb | 7 |
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 |