title: How to integrate rubocop with Rake?
body: <p><a href="https://github.com/bbatsov/rubocop" rel="noreferrer">rubocop</a> is a code style checker for Ruby. A similar tool to rubocop, Cane, can be <a href="https://github.com/square/cane#integrating-with-rake" rel="noreferrer">integrated with Rake</a>. I prefer rubocop to Cane since rubocop makes checks based on the <a href="https://github.com/bbatsov/ruby-style-guide" rel="noreferrer">Ruby Style Guide</a> and it seems to <a href="https://stackoverflow.com/a/15007900/789593">spot more problems</a>. To automate the process of style checking I would like to integrate rubocop with Rake so that the build fails if code quality is lacking.</p>
  
  <p>Gem already supports <a href="http://guides.rubygems.org/make-your-own-gem/#writing-tests" rel="noreferrer">adding tests</a> to packages via Rake. I would like to do the same with style checks so that style checks are run along with the tests. How can I do this?</p>
  
  <p>If it helps to start with a Rakefile here is one:</p>
  
  <pre><code># -*- coding: utf-8; mode: ruby -*-
  
  require 'bundler/gem_tasks'
  require 'rake/testtask'
  
  Rake::TestTask.new do |t|
    t.libs &lt;&lt; 'test'
    t.test_files = FileList['test/unit/test*.rb']
  end
  
  desc 'Run tests'
  task default: :test
  </code></pre>