Lindo makes Rails testing easier
June 29, 2009
Lindo is a new Ruby gem we've released that makes Rails testing easier. If you're a regular user of assert_select (or rspec's have_tag equivalent) you probably find yourself frequently doing something like this when the assertion is failing and you 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 to a solution, but it can be tedious parsing through the huge amount of HTML that gets returned, often in a semi-unreadable format. Enter Lindo, which is available as both a Rails plugin and a Ruby gem:

script/plugin install http://github.com/adeptware/lindo/

or...

gem sources -a http://gems.github.com
sudo gem install adeptware-lindo

Lindo adds a vr method to your functional and integration 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 us a lot of time in figuring out why a specific assertion is failing. Instead of parsing through the HTML, we can view the entire page and immediately tell if something is missing or out of place. We often call vr even before writing assertions.

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.