Rspec Lintable Matcher

Ryan Sonnek bio photo By Ryan Sonnek Comment

Awhile back, I released an Rspec matcher that validated controller responses returned linkable Javascript using the JSLint library.

Today, I have the opportunity to resurrect that work and update it significantly to work with the great Jshint library. The rspec-lintable gem adds a convenient be_lintable matcher for your controller specs to easily ensure that your Javascript responses are syntactically valid.

describe "#show" do
  before { get :show, format: :js }
  it { should be_lintable }

All options and configuration for the be_lintable matcher are done via the standard Jshint .jshintrc configuration file.

This matcher gives you a whole lot of bang for your buck. It doesn’t actually exercise the Javascript like a full integration test, but in my experience, linting the response is a great smoke test that actually catches quite a few issues that can break an end users browsers (especially if they’re running IE).

Enjoy and send me any feedback if you have suggestions or issues!