title: Rails, Minitest and Guard - Why is rb-fsevent taking up over 100% CPU?
body: <p>I'm running guard in my Rails app and the test suite (minutest) has recently stopped working properly.</p>
  
  <p>If I'm lucky, it'll run all of the tests once, maybe twice. After that, it takes so long to respond to even one small test file being changed that using the gem becomes futile.</p>
  
  <p>When following <code>top</code> while the tests run, I can see there's a ruby process that's taking up over 100% of the CPU <strong>constantly</strong>. Even once all tests are run and I haven't made any changes to the file.</p>
  
  <p><img src="https://i.stack.imgur.com/DMGtE.png" alt="Output from top"></p>
  
  <p>The ruby process is:</p>
  
  <pre><code>/Users/Bodacious/.rvm/gems/ruby-2.0.0-p247@MyApp/gems/rb-fsevent-0.9.3/bin/fsevent_watch --latency 0.1 /Users/Bodaiou/Clients/MyApp
  </code></pre>
  
  <p>(process <strong>31332</strong>) in the screenshot attached.</p>
  
  <p>Ruby 2.0.0-p247</p>
  
  <p>Here's my setup:</p>
  
  <pre><code># Gemfile (with irrelevant gems removed)
  gem 'rails', '4.0.0'
  group :test do
    gem 'launchy'
    gem "mocha", require: false
    gem 'database_cleaner'
    gem 'selenium-webdriver'
    gem 'capybara-webkit' # for headless javascript tests
    gem 'timecop'
    gem "minitest-focus"
  end
  
  group :development, :test do
    gem "minitest-rails"
    gem "minitest-rails-capybara"
    gem 'zeus'
    gem 'guard'
    gem 'guard-minitest'
    gem 'factory_girl_rails'
  end
  
  
  # Guardfile
  guard :minitest, all_on_start: false do
    # Rails 4
    watch(%r{^app/(.+)\.rb})                               { |m| "test/#{m[1]}_test.rb" }
    watch(%r{^app/controllers/application_controller\.rb}) { 'test/controllers' }
    watch(%r{^app/controllers/(.+)_controller\.rb})        { |m| "test/integration/#{m[1]}_test.rb" }
    watch(%r{^app/views/(.+)_mailer/.+})                   { |m| "test/mailers/#{m[1]}_mailer_test.rb" }
    watch(%r{^lib/(.+)\.rb})                               { |m| "test/lib/#{m[1]}_test.rb" }
    watch(%r{^test/.+_test\.rb})
    watch(%r{^test/test_helper\.rb})                       { 'test' }
  
    ignore(%r{^tmp/})
  
  end
  
  # test_helper
  ENV["RAILS_ENV"] = "test"
  require File.expand_path("../../config/environment", __FILE__)
  
  require 'rails/test_help'
  require 'minitest/autorun'
  require 'minitest/pride'
  require "minitest/rails/capybara"
  
  require "mocha/setup"
  
  # Sidekiq https://github.com/mperham/sidekiq/wiki/Testing
  require 'sidekiq/testing'
  Sidekiq::Testing.fake!
  
  Dir[Rails.root.join('test', 'support', '*.rb')].each do |file|
    require file
  end
  
  
  class MiniTest::Spec
    include FactoryGirl::Syntax::Methods
    include AllTestHelper
  
  end
  
  
  class ActiveSupport::TestCase
    include FactoryGirl::Syntax::Methods
    include AllTestHelper
  end
  
  class Capybara::Rails::TestCase
    include Rails.application.routes.url_helpers 
    include Capybara::DSL
    include Capybara::Assertions
    include IntegrationTestHelper
  
    # Called before each Feature spec
    before :each do
    end
  
    # Called after each Feature spec
    after :each do
      Capybara.reset_sessions!
    end
  end
  </code></pre>
  
  <p>Gem Versions:    </p>
  
  <ul>
  <li>minitest (4.7.5)</li>
  <li>minitest-capybara (0.5.0)</li>
  <li>minitest-focus (1.1.0)</li>
  <li>minitest-metadata (0.4.0)</li>
  <li>minitest-rails (0.9.2)</li>
  <li>minitest-rails-capybara (0.10.0)</li>
  <li>mobvious-rails (0.1.2)</li>
  <li>mocha (0.14.0)</li>
  <li>guard (2.2.4)</li>
  <li>guard-minitest (2.1.2)</li>
  <li>rb-fsevent (0.9.3)</li>
  </ul>