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.