Spork の prefork ブロックを含むテスト セットアップのすべてが、実行のたびにリロードされ、呼び出されるという問題が発生しています。これは新しいプロジェクトであっても、ガードが変更を検出してからテストが開始されるまでに 5 ~ 8 秒かかるため、最小限のテストしかなく、SSD も使用しています。
すべてがリロードされていることに気付く前に、ここでJo Liss によって説明されている手法を使用してプロファイリングし、これらのハングした要求を含めましたが、とにかくすべてがリロードされているため、明らかに役に立ちませんでした. しかし、その時、私はこれに気づきました:
Loaded Suite テスト、テスト/コントローラー、テスト/コントローラー/管理、テスト/工場、テスト/機能/管理、テスト/ヘルパー、テスト/ヘルパー/管理、テスト/統合、テスト/モデル、テスト/サポート
なぜすべてをリロードするのかわかりません。これは、minitest+spork+guard をセットアップする最初の試みです (rspec を使用するべきでした、ため息)。誰かがそれに遭遇したり、私が見逃したものを簡単に見つけたりできることを願って、すべてを含めています. 前もって感謝します!
私のファイルは次のとおりです。
test_helper.rb
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
ガードファイル
guard 'bundler' do
watch('Gemfile')
# Uncomment next line if Gemfile contain `gemspec' command
# watch(/^.+\.gemspec/)
end
guard 'spork', :wait => 65, :test_unit => false, :minitest => true, :minitest_env => { 'RAILS_ENV' => 'test' }, :bundler => 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
サポート/ minitest.rb
#require "minitest/autorun"
require "minitest/rails"
require "minitest/spec"
require "minitest/pride"
require "minitest/rails/shoulda"
require "minitest/autorun"
require "capybara/rails"
class RequestSpec < 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
サポート/turn.rb
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
Gemfile
source 'https://rubygems.org'
# core
gem 'rails', '3.2.8'
gem 'thin'
# infrastructure
gem 'heroku'
gem 'foreman', :groups => [:development, :test]
# application monitoring
gem 'airbrake'
gem 'newrelic_rpm'
# view engine
gem 'haml', '>= 3.1.7'
gem 'haml-rails', '>= 0.3.5'
gem 'redcarpet' # markdown
# data persistence
gem 'mongoid', '>= 3.0.5'
gem 'redis'
gem 'redis-store'
gem 'redis-rails'
# email
gem 'sendgrid'
gem 'mailcatcher', :group => [:development]
# authentication and authorization
gem 'devise', '>= 2.1.2'
gem 'omniauth', '>= 1.0'
#gem 'authority'
gem 'cancan'
gem 'rolify', '>= 3.2.0'
# view helpers
gem 'bootstrap-generators', '~> 2.1', :group => [:development]
gem 'jquery-rails'
gem 'simple_form', '>= 2.0.2'
gem 'rails3-jquery-autocomplete'
# file attachments
gem 'rmagick'
gem 'fog'
gem 'carrierwave'
gem 'carrierwave-mongoid', :require => 'carrierwave/mongoid'
# url helpers
gem 'mongoid_slug'
# console tools
gem 'ansi', :groups => [:development, :test]
gem 'rack-livereload', :groups => [:development]
gem 'pry-rails', :groups => [:development]
gem 'growl', :groups => [:development, :test]
gem 'turn', :groups => [:test]
gem 'awesome_print'
gem 'progress_bar', :groups => [:test]
# supporting libraries
gem 'bson_ext'
gem 'nokogiri', :group => :test
gem 'ruby_parser', '>= 2.3.1', :group => :test
gem 'rb-fsevent', '~> 0.9.1', :group => :development
# assets
gem 'less-rails', :group => :assets
gem 'therubyracer', '>= 0.10.2', :group => :assets
gem 'uglifier', '>= 1.0.3', :group => :assets
# guard
gem 'guard', :group => :development
gem 'guard-livereload', :group => :development
gem 'guard-spork', :group => :development
gem 'guard-minitest', :group => :development
gem 'guard-bundler', :group => :development
# minitest
gem 'spork-minitest', :group => :test
gem 'minitest-rails', :group => :test
gem 'minitest-rails-shoulda', :group => :test, :git => 'git://github.com/rawongithub/minitest-rails-shoulda.git'
gem 'capybara_minitest_spec', :group => :test
# mocking
gem 'mocha', :group => :test
# http testing
gem 'vcr', :group => :test
gem 'webmock', :group => :test
# factories
gem 'factory_girl_rails'