2

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

当我第一次设置所有东西时,我没有遇到任何问题,而且我不知道是什么改变导致了这个问题。我已经尝试了各种方法来让事情再次快速运行:强制轮询而不是使用 rb-fsevent;关闭Spork;禁用其他守卫;使用 guard-test 代替 guard-minitest;按此页面重新编译 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
4

0 回答 0