Lindo makes Rails testing easier

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_tagequivalent) 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:

gem install 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 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.

Published on