Being at RubyConf this weekend has provided the necessary motivation for me to finally release a new Ruby gem I’ve been building. It’s an extraction from a project I’ve been working on for Relevance.
I’m a regular user of assert_select
in my functional tests. I find myself frequently doing something like this when the assertion is failing and I can’t figure out why:
def test_something post :something raise @response.body.inspect assert_select "div[id=header]" end
Inspecting the response body usually leads me to a solution, but it’s tedious parsing through the huge amount of HTML that gets returned, often in a semi-unreadable format. Enter the response_visualizer plugin (which has since been renamed Lindo):
script/plugin install http://github.com/adeptware/lindo/
Or clone the project directly:
git clone http://github.com/adeptware/lindo/
The plugin provides a vr
method to your functional tests. When this method is called, the response body is automatically opened in the default browser allowing for easy visual inspection of the page’s content:
post :new vr ...
If you’d prefer to jump straight to the source code, passing the :html
symbol will open the formatted HTML in the default text editor:
post :new vr(:html) ...
This has saved me a lot of time in figuring out why a specific assertion is failing. Instead of parsing through the HTML, I can view the entire page and immediately tell if something is missing or out of place. I find myself calling vr
even before I write my assertions now.
After installing, check out the README file for additional documentation. There is also a GitHub project if you’d like to contribute a patch or fork the code. Enjoy!
Very nice! Great work man.
Pingback: Ruby, Rails, Rails Plugin, JavaScript, CSS, TextMate « exceptionz
Phlip Plumlee has been recommending this technique for any UI development for years — using TDD to show the screen being developed during a test run to avoid having to exercise the whole app every time you want to see the changes you’ve made.
He calls the method reveal(). Thanks for making a Rails version. I wonder if there could be a way to make Ajax, etc. work?
http://c2.com/cgi/wiki?HttpUnitTutorial
And background on the principles he’s working from, which reading I really recommend:
http://c2.com/cgi/wiki?TestFirstUserInterfaces
http://industrialxp.org/community/bin/view/Main/TestFirstUserInterfaces
http://dotnetjunkies.com/WebLog/exortech/archive/2004/12/29/39634.aspx
Just installed response_visualizer in yet another project today. This is quickly becoming a must-have plugin!
Glad to hear it!