Showing view spec exceptions
April 19th, 2011
When an exception is raised during rendering of a view it is wrapped inside an ActionView::Template::Error which is then reraised.
This leads to unhelpful failure messages in view specs, along the lines of
contact/index.html.haml renders a form to send feedback
Failure/Error: it "renders a form to send feedback" do render
ActionView::Template::Error
# ./app/views/contact/index.html.haml:19
# ./spec/views/contact/index.html.haml_spec.rb:10:in `block (2 levels) in '
This little monkey patch
module RSpec module Core class Example def set_exception(exception) if exception.is_a?(ActionView::Template::Error) @exception ||= exception.original_exception else @exception ||= exception end end end end end
ensures that the original exception is the one that is displayed.
Sorry, comments are closed for this article.