Christian von Kleist
2008-Jan-14 06:34 UTC
Making failing view specs easier to troubleshoot
I just had a problem that had me stumped for an hour. All of a sudden all of my view specs were failing, and I couldn''t get good troubleshooting information from the rspec output. The output from running `rake specs` was a bunch of HTML from app/views/exceptions/internal_server_error.html.erb, but there wasn''t enough info there to diagnose my problem. It just said "Internal server error" and had no stack trace. (And no, using `rake specs --trace` wouldn''t help in this case.) The thing that had me absolutely stumped was that the views all worked fine when I ran `merb -e test` and checked them out with my browser. What could possibly have gone wrong? It turns out that I was using `session[]` in a before filter in my Application controller, but `session[]` is undefined when rspec runs. I finally figured out the problem by making internal_server_error.html.erb show detailed error messages, which is apparently off when running rspec. After I replaced ''if show_details'' with ''if true'', I finally got a stack trace in the HTML. Even then the output was hard to read, so I wrote the contents of @body to a file and opened that in my browser. That enabled me to see the small problem quickly. Maybe show_details should be set to true when running rspec, and maybe internal_server_error.html.erb could have a simple <pre> block with error messages and a stack trace inside. The latter would be redundant, but it would aid debugging enormously when reading rspec output in a console. http://merb.devjavu.com/ticket/451