title: With Minitest+Guard+Spork, all test suites and support files are being reloaded on each run
body: <p>I'm running into a problem where everything in my test setup, including Spork's prefork block, is being reloaded and invoked on each run. It is taking 5-8 seconds for a test to fire off after guard picks up a change even though this is a new project so there are minimal tests and I even have an SSD.</p>
  
  <p>Before I realized everything was reloading, I profiled it using the technique described by Jo Liss <a href="http://www.opinionatedprogrammer.com/2011/02/profiling-spork-for-faster-start-up-time/" rel="nofollow">here</a> and I've included those hanging requires but obviously that didn't help since it's all being reloaded anyway. However, that's when I noticed this:</p>
  
  <blockquote>
    <p>Loaded Suite
    test,test/controllers,test/controllers/manage,test/factories,test/functional/manage,test/helpers,test/helpers/manage,test/integration,test/models,test/support</p>
  </blockquote>
  
  <p>I'm not seeing why it would reload everything. This is my first attempt at setting up minitest+spork+guard (i should have just gone with rspec, sigh) so I'm hoping it's something stupid. I'm including everything in hopes that someone has run into it or can easily spot what I've missed. Thanks in advance! </p>
  
  <p>My files include:</p>
  
  <blockquote>
    <p><strong>test_helper.rb</strong></p>
  </blockquote>
  
  <pre><code>require 'spork'
  Spork.prefork do
    #MiniTest::Rails.override_testunit!
    ENV["RAILS_ENV"] = "test"
    require File.expand_path('../../config/environment', __FILE__)
    require 'guard'
    require 'guard/interactors/readline'
    require 'guard/ui'
    require 'guard/interactors/coolline'
    require 'guard/interactor'
    require 'guard/dsl'
    require 'guard/notifiers/rb_notifu'
    require 'guard/notifier'
    require 'guard/minitest/notifier'
    require 'guard/minitest/runners/default_runner'
    Dir[File.expand_path('test/support/*.rb')].each { |file| require file }
    require "mocha"
    Spork.trap_method(Rails::Application, :reload_routes!)
    Spork.trap_method(Rails::Application::RoutesReloader, :reload!)
  end
  </code></pre>
  
  <blockquote>
    <p><strong>Guardfile</strong></p>
  </blockquote>
  
  <pre><code>guard 'bundler' do
    watch('Gemfile')
    # Uncomment next line if Gemfile contain `gemspec' command
    # watch(/^.+\.gemspec/)
  end
  guard 'spork', :wait =&gt; 65, :test_unit =&gt; false, :minitest =&gt; true, :minitest_env =&gt; { 'RAILS_ENV' =&gt; 'test' }, :bundler =&gt; true do
    watch('config/application.rb')
    watch('config/environment.rb')
    watch(%r{^config/environments/.+\.rb$})
    watch(%r{^config/initializers/.+\.rb$})
    watch('Gemfile')
    watch('Gemfile.lock')
    watch('test/test_helper.rb') { "test" }
  end
  
  guard 'minitest' do
    watch(%r|^test/test_helper\.rb|)         { "test" }
    watch(%r|^test/support/(.*)\.rb|)         { "test" }
    watch(%r{^test/.+_test\.rb$})
    watch(%r|^app/models/(.*)\.rb|)          {|m| ["test/models/#{m[1]}_test.rb", "test/integration/#{m[1]}_test.rb"] }
    watch(%r|^app/controllers/(.*)\.rb|)     {|m| ["test/controllers/#{m[1]}_test.rb", "test/integration/#{m[1]}_test.rb"] }
    watch(%r|^app/views/(.*)\.html|)         {|m| "test/integration/#{m[1]}_test.rb" }
    watch(%r|^app/objects/(.*)\.rb|)         {|m| "test/objects/#{m[1]}_object_test.rb" }
  end
  
  guard 'livereload' do
    watch(%r{app/.+\.(erb|haml)})
    watch(%r{app/helpers/.+\.rb})
    watch(%r{(public/|app/assets).+\.(css|js|html)})
    watch(%r{(app/assets/.+\.css)\.scss}) { |m| m[1] }
    watch(%r{(app/assets/.+\.js)\.coffee}) { |m| m[1] }
    watch(%r{config/locales/.+\.yml})
  end
  </code></pre>
  
  <blockquote>
    <p><strong>support/minitest.rb</strong></p>
  </blockquote>
  
  <pre><code>#require "minitest/autorun"
  require "minitest/rails"
  require "minitest/spec"
  require "minitest/pride"
  require "minitest/rails/shoulda"
  require "minitest/autorun"
  require "capybara/rails"
  
  class RequestSpec &lt; MiniTest::Spec
    include Rails.application.routes.url_helpers
    include Capybara::DSL
    include Rails.application.routes.url_helpers
  end
  
  MiniTest::Spec.register_spec_type /integration$/i, RequestSpec
  #MiniTest::Spec.register_spec_type /object$/, MiniTest::Spec
  
  class MiniTest::Rails::Controller
    include Devise::TestHelpers
  end
  </code></pre>
  
  <blockquote>
    <p><strong>support/turn.rb</strong></p>
  </blockquote>
  
  <pre><code>require 'turn'
  require 'turn/autorun'
  require 'turn/colorize'
  require 'turn/reporter'
  require 'turn/reporters/pretty_reporter'
  Turn.config do |c|
    c.natural = true
    c.ansi = true
    c.format = :pretty
  end
  </code></pre>
  
  <blockquote>
    <p><strong>Gemfile</strong></p>
  </blockquote>
  
  <pre><code>source 'https://rubygems.org'
  
  # core
  gem 'rails', '3.2.8'
  gem 'thin'
  
  
  # infrastructure
  gem 'heroku'
  gem 'foreman', :groups =&gt; [:development, :test]
  
  # application monitoring
  gem 'airbrake'
  gem 'newrelic_rpm'
  
  
  # view engine
  gem 'haml', '&gt;= 3.1.7'
  gem 'haml-rails', '&gt;= 0.3.5'
  gem 'redcarpet' # markdown
  
  
  # data persistence
  gem 'mongoid', '&gt;= 3.0.5'
  gem 'redis'
  gem 'redis-store'
  gem 'redis-rails'
  
  
  # email
  gem 'sendgrid'
  gem 'mailcatcher', :group =&gt; [:development]
  
  
  # authentication and authorization
  gem 'devise', '&gt;= 2.1.2'
  gem 'omniauth', '&gt;= 1.0'
  #gem 'authority'
  gem 'cancan'
  gem 'rolify', '&gt;= 3.2.0'
  
  
  # view helpers
  gem 'bootstrap-generators', '~&gt; 2.1', :group =&gt; [:development]
  gem 'jquery-rails'
  gem 'simple_form', '&gt;= 2.0.2'
  gem 'rails3-jquery-autocomplete'
  
  
  # file attachments
  gem 'rmagick'
  gem 'fog'
  gem 'carrierwave'
  gem 'carrierwave-mongoid', :require =&gt; 'carrierwave/mongoid'
  
  
  # url helpers
  gem 'mongoid_slug'
  
  
  # console tools
  gem 'ansi',             :groups =&gt; [:development, :test]
  gem 'rack-livereload',  :groups =&gt; [:development]
  gem 'pry-rails',        :groups =&gt; [:development]
  gem 'growl',            :groups =&gt; [:development, :test]
  gem 'turn',             :groups =&gt; [:test]
  gem 'awesome_print'
  gem 'progress_bar',     :groups =&gt; [:test]
  
  
  # supporting libraries
  gem 'bson_ext'
  gem 'nokogiri',                  :group =&gt; :test
  gem 'ruby_parser', '&gt;= 2.3.1',   :group =&gt; :test
  gem 'rb-fsevent', '~&gt; 0.9.1',    :group =&gt; :development
  
  
  # assets
  gem 'less-rails',                 :group =&gt; :assets
  gem 'therubyracer', '&gt;= 0.10.2',  :group =&gt; :assets
  gem 'uglifier', '&gt;= 1.0.3',       :group =&gt; :assets
  
  
  # guard
  gem 'guard',                     :group =&gt; :development
  gem 'guard-livereload',          :group =&gt; :development
  gem 'guard-spork',               :group =&gt; :development
  gem 'guard-minitest',            :group =&gt; :development
  gem 'guard-bundler',             :group =&gt; :development
  
  
  # minitest
  gem 'spork-minitest',           :group =&gt; :test
  gem 'minitest-rails',           :group =&gt; :test
  gem 'minitest-rails-shoulda',   :group =&gt; :test,  :git =&gt; 'git://github.com/rawongithub/minitest-rails-shoulda.git' 
  gem 'capybara_minitest_spec',   :group =&gt; :test
  
  
  # mocking
  gem 'mocha', :group =&gt; :test
  
  
  # http testing
  gem 'vcr',      :group =&gt; :test
  gem 'webmock',  :group =&gt; :test
  
  
  # factories
  gem 'factory_girl_rails'
  </code></pre>