rails/rails — Issue #4780: assert_response: show response.body on fail
Author: sunaku
Created: 2012-01-31 08:14:12+00:00
State: open

Hello,

I prefer to see the response body when an assert_response fails because it helps me debug, so I added the following to my `test/test_helper.rb` according to [a tip I found on APIdock](http://apidock.com/rails/ActionController/Assertions/ResponseAssertions/assert_response#859-Good-way-to-see-what-went-wrong):

```ruby
class ActionController::TestCase
# Show response body as reason when assert_response() fails.
def assert_response type, message = response.body
super type, message
end
end
```

However, to my great frustration, this did not work. I went level by level up the inheritance tree and finally found the culprit: a bug in the `build_message` in [Ruby 1.9.2's copy of test/unit](http://ruby-doc.org/stdlib-1.9.2/libdoc/test/unit/rdoc/Test/Unit/Assertions.html). But I use Ruby 1.9.3, which [no longer defines](http://ruby-doc.org/stdlib-1.9.3/libdoc/test/unit/rdoc/Test/Unit/Assertions.html) that `build_message` method, so I'm not sure if Rails includes a copy of Ruby 1.9.2's test/unit assertions source code or something.

Anyway now I really had to monkey patch that method in my `test/test_helper.rb` to get things working:

```ruby
# XXX: the default build_message has a bug where it omits the given head param
module Test::Unit::Assertions
alias _19e6c663_2dfc_4095_b40d_c0ff2857f7a7 build_message
def build_message head, template=nil, *arguments
[_19e6c663_2dfc_4095_b40d_c0ff2857f7a7(head, template, *arguments), head].join("\n")
end
end
```

O_o