Over a million developers have joined DZone.

Making Functional Test Failures Readable

·
making functional test failures readable

By zenspider on Rails

Tired of your rails functional test failures being completely unreadable? I'm not terribly fond of rails' assert_tag but it is better than nothing. However, I never like to read something like the following:


expected tag, but no tag found matching {:attributes=>{:action=>"/admin/themes/update/1"}, :tag=>"form"} in:
"".


Ugh! It just does nothing to help you and since it isn't expressed as a diff, unit_diff is no help in this arena. I have however figured out how to make it much more manageable with the following snippets:


class ApplicationController < ActionController::Base
 def initialize(testing=false)
 super()
 self.class.layout(nil) if testing
 end
 [...]
end

and then in your functional tests:

def setup
 @controller = MyController.new(true)
 [...]
end


Now your failures contain just the content from the page:


expected tag, but no tag found matching {:attributes=>{:action=>"/admin/themes/update/1"}, :tag=>"form"} in:
"\n
    \n
  • Name: Blue
  • \n
  • Folder: blue
  • \n
  • Description: A Plain blue theme
  • \n
  • Masthead: Blue
  • \n
  • Editor: n/a
  • \n
\n\nCancel Editing\n".
Topics:

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}