警卫需要太长时间才能进行测试

时间:2013-08-06 20:50:31

标签: ruby-on-rails guard minitest spork

我正在使用Mac OS 10.8.4上的MiniTest套件开发Rails应用程序,Spork和Guard在文件更改时运行我的测试,但Guard对文件系统更改的响应时间过长。通常,测试将立即针对前几个文件更改事件运行,但随后它们开始滞后一分钟或更长时间。测试似乎总是在最终运行,但不足以真正帮助加快我的工作流程。

当我第一次设置所有内容时,我没有遇到任何问题,而且我不知道可能会发生什么变化导致此问题。我已经尝试了各种各样的东西来让事情再次快速运行:强制轮询而不是使用rb-fsevent;关掉Spork;禁用其他警卫;使用保护测试而不是保护 - 最小;按this page重新编译Ruby;使用和不使用bundle exec ...

运行Guard

我完全失去并准备放弃。有什么想法吗?

这是我的Gemfile:

source 'http://rubygems.org'
ruby '2.0.0'
gem 'rack', '1.4.1'
gem 'rails', '~> 3.2.8'
gem 'jquery-rails', '2.3.0'
gem 'jquery-ui-rails'
gem 'kaminari'
gem 'dynamic_form'
gem 'cocaine', '0.3.2'
gem 'paperclip', '2.4.3'
gem 'braintree'
gem 'thin'
gem 'devise'
gem 'aws-s3'
gem 'rack-ssl'
gem 'rack-rewrite'
gem 'simple_form'
gem 'delayed_job'
gem 'delayed_job_active_record'
gem 'recaptcha', :require => 'recaptcha/rails'
gem 'redcarpet'
gem 'twilio-ruby'
gem 'koala'
gem 'newrelic_rpm'
gem 'airbrake'

group :assets do
  gem 'sass-rails'
  gem 'coffee-rails'
  gem 'uglifier'
end

group :staging, :test, :development do
  gem 'faker'
end

group :staging, :production do
  gem 'workless', '~> 1.1.3'
end

group :development, :staging, :production do
  gem 'pg'
end

group :test do
  gem 'sqlite3'
  gem 'selenium-webdriver'
  gem 'rr', :require => false
  gem 'capybara'
  gem 'database_cleaner'
  gem 'timecop'
  gem 'mocha'
end

group :test, :development do
  gem 'pry-byebug'
  gem 'guard'
  gem 'spork'
  gem 'spork-testunit'
  gem 'guard-spork'
  gem 'guard-minitest', '0.5.0'
  gem 'guard-rake'
  gem 'guard-livereload'
  gem 'terminal-notifier-guard', :require => false
  gem 'rb-inotify', require: false
  gem 'rb-fsevent', require: false
  gem 'rb-fchange', require: false
end

我的Guardfile:

interactor :off
notification :terminal_notifier, :sticky => true

guard 'spork', :wait => 60, :test_unit_env => { 'RAILS_ENV' => 'test' } 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, :drb => true, :all_on_start => false, :bundler => false do
  watch(%r{^lib/(.+)\.rb$})     { |m| "test/#{m[1]}_test.rb" }
  watch(%r{^test/functional/.+_test\.rb$})
  watch(%r{^test/unit/.+_test\.rb$})
  watch('test/test_helper.rb')  { "test" }
  watch(%r{^app/models/(.+)\.rb$})                   { |m| "test/unit/#{m[1]}_test.rb" }
  watch(%r{^app/controllers/(.+)\.rb$})              { |m| "test/functional/#{m[1]}_test.rb" }
  watch('app/controllers/application_controller.rb') { ["test/functional", "test/integration"] }
  watch('app/helpers/student_filter_helper.rb') { "test/unit/helpers/student_filter_helper_test.rb" }
end

guard 'rake', :drb => true, :task => 'test:scripts', :run_on_start => false do
  watch(%r{^app/assets/javascripts/(.+)\.[js|coffee]})
  watch(%r{^test/javascript/(.+)\.[js|coffee]})
end

guard 'livereload' do
  watch(%r{app/views/.+\.(erb|html)$})
  watch(%r{(app|vendor)(/assets/\w+/(.+\.(css|scss))).*}) { |m| "/assets/#{m[3]}" }
end

和test_helper.rb:

# -*- encoding : utf-8 -*-
require 'rubygems'
require 'spork'

Spork.prefork do
  require 'rubygems'
  ENV["RAILS_ENV"] = "test"
  require File.expand_path('../../config/environment', __FILE__)
  require 'rails/test_help'
  require 'capybara/rails'
  require 'database_cleaner'
  require 'rr'
  require 'ostruct'

  class ActionController::TestCase
    DatabaseCleaner.strategy = :truncation
    include Devise::TestHelpers
    def setup
      DatabaseCleaner.start
    end
    def teardown
      super
      DatabaseCleaner.clean
      Timecop.return
    end
  end

  class ActionDispatch::IntegrationTest
    self.use_transactional_fixtures = false
    include Capybara::DSL
    Capybara.default_driver = :selenium
    DatabaseCleaner.strategy = :truncation

    def setup
      super
      DatabaseCleaner.clean
    end

    def teardown
      super
      DatabaseCleaner.clean
      Timecop.return
    end

  end

  class MockTwilioClient
    def method_missing(*args)
      self
    end
  end

end

Spork.each_run do
  require "#{Rails.root}/test/test_support"
  ActiveSupport::Dependencies.clear
end

0 个答案:

没有答案