ruby-on-rails – 每次Spork初始化导轨并慢慢运行

ruby-on-rails – 每次Spork初始化导轨并慢慢运行,第1张

概述我需要帮助搞清楚为什么我的rspec测试运行缓慢. 我正在运行spork,guard和rspec.但是,似乎spork每次都重新初始化rails.我很难搞清楚如何调试此问题.我怀疑我使用的一些宝石是造成这种但没有证据的. 我认为它正在重装的原因是: >在spork内部或外部运行需要相同的时间 >我得到了这个警告(与SOLR宝石相关),这是我跑步时得到的 rails服务器 运行所有规格 弃用警告:A 我需要帮助搞清楚为什么我的rspec测试运行缓慢.

我正在运行spork,guard和rspec.但是,似乎spork每次都重新初始化rails.我很难搞清楚如何调试此问题.我怀疑我使用的一些宝石是造成这种但没有证据的.

我认为它正在重装的原因是:

>在spork内部或外部运行需要相同的时间
>我得到了这个警告(与SolR宝石相关),这是我跑步时得到的
rails服务器

运行所有规格

弃用警告:ActiveSupport :: Concern中的InstanceMethods模块将不再自动包含在内.请直接在Sunspot :: Rails :: SolrInstrumentation中定义实例方法. (从/home/dougt/replyinline/config/environment.rb:5调用)

这是我的spec_helper.rb

require 'rubygems'require 'spork'#uncomment the following line to use spork with the deBUGger#require 'spork/ext/ruby-deBUG'Spork.prefork do  # Loading more in this block will cause your tests to run faster. However,# if you change any configuration or code from librarIEs loaded here,you'll  # need to restart spork for it take effect.# This file is copIEd to spec/ when you run 'rails generate rspec:install'  ENV["RAILS_ENV"] ||= 'test'  require file.expand_path("../../config/environment",__file__)  require 'rspec/rails'  # Requires supporting ruby files with custom matchers and macros,etc,# in spec/support/ and its subdirectorIEs.  Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f}  RSpec.configure do |config|    # == Mock Framework    #    # If you prefer to use mocha,flexmock or RR,uncomment the appropriate line:    #    # config.mock_with :mocha    # config.mock_with :flexmock    # config.mock_with :rr    config.mock_with :rspec    # Remove this line if you're not using ActiveRecord or ActiveRecord fixtures    config.fixture_path = "#{::Rails.root}/spec/fixtures"    # If you're not using ActiveRecord,or you'd prefer not to run each of your    # examples within a transaction,remove the following line or assign false    # instead of true.    config.use_transactional_fixtures = true    config.include Devise::TestHelpers,:type => :vIEw    #https://github.com/plataformatec/devise/wiki/How-To:-Controllers-and-VIEws-tests-with-Rails-3-(and-rspec)    config.extend ControllerMacros,:type => :controller    config.extend ControllerMacros,:type => :helper    config.extend ControllerMacros,:type => :vIEw  endendSpork.each_run do  # This code will be run each time you run your specs.  #https://github.com/sporkrb/spork/issues/37#   silence_warnings do#      Dir["#{Rails.root}/app/models/**/*.rb"].each {|f| load f}#  end#  load "#{Rails.root}/config/routes.rb"#  Dir["#{Rails.root}/app/**/*.rb"].each {|f| load f}end

的Gemfile

source 'http://rubygems.org'# Gems used only for assets and not required# in production environments by default.group :assets do  gem 'sass-rails','~> 3.2.3'  gem 'coffee-rails','~> 3.2.1'  gem 'uglifIEr','>= 1.0.3'#  gem "less-rails","~> 2.1.4"  gem 'twitter-bootstrap-rails',"~> 2.0.3"endgroup :test do  # Pretty printed test output  gem 'spork-rails'  gem 'rspec-rails','2.8'  gem 'guard-spork'  gem 'rspec'  gem 'growl'  gem 'rb-fsevent'  gem 'guard-spork'endgroup :development do  gem 'guard'  gem 'guard-rspec'  gem 'turn','~> 0.8.3',:require => false  gem 'webrat','0.7.3'  gem 'therubyracer'  gem 'progress_bar'  gem 'sunspot_solr'  gem 'minitest'  gem 'rspec-rails','2.8'endgem 'rails','3.2.2'gem 'jquery-rails'gem 'pg'# To use ActiveModel has_secure_password# gem 'bcrypt-ruby','~> 3.0.0'# Use unicorn as the web server# gem 'unicorn'# Deploy with CAPIstrano# gem 'cAPIstrano'# To use deBUGger# gem 'ruby-deBUG19',:require => 'ruby-deBUG'gem 'execJs'gem 'devise'gem "cancan"gem "oauth"gem "oauth2"gem "oauth-plugin",">= 0.4.0.rc2"gem "autotest"gem "autotest-rails-pure"gem "autotest-notification"gem 'uuIDtools'gem 'Json'gem 'twitter'gem 'ZenTest','4.6.0'gem 'mobylette'gem 'diff-lcs'gem 'twitter-text'gem 'chronic',:git => 'git://github.com/tarr11/chronic.git'gem 'sunspot_rails'gem 'delayed_job_active_record',"~> 0.3.2"gem 'delayed_task'gem 'codemirror-rails',"~> 2.22"gem 'thin'gem "paperclip","~> 2.0"gem 'aws-sdk'gem 'aws-s3'gem 'newrelic_rpm'gem 'airbrake'gem 'factory_girl_rails',"~> 1.2"gem 'diff_match_patch'gem 'draper'gem "email_veracity","~> 0.6.0"

Guardfile

# A sample Guardfile# More info at https://github.com/guard/guard#readmeguard 'spork',:cucumber_env => { 'RAILS_ENV' => 'test' },:rspec_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('spec/spec_helper.rb') { :rspec }  watch('test/test_helper.rb') { :test_unit }  watch(%r{features/support/}) { :cucumber }endguard 'rspec',:version => 2 do  watch(%r{^spec/.+_spec\.rb$})  watch(%r{^lib/(.+)\.rb$})     { |m| "spec/lib/#{m[1]}_spec.rb" }  watch('spec/spec_helper.rb')  { "spec" }  # Rails example  watch(%r{^app/(.+)\.rb$})                           { |m| "spec/#{m[1]}_spec.rb" }  watch(%r{^app/(.*)(\.erb|\.haml)$})                 { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }  watch(%r{^app/controllers/(.+)_(controller)\.rb$})  { |m| ["spec/routing/#{m[1]}_routing_spec.rb","spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb","spec/acceptance/#{m[1]}_spec.rb"] }  watch(%r{^spec/support/(.+)\.rb$})                  { "spec" }  watch('config/routes.rb')                           { "spec/routing" }  watch('app/controllers/application_controller.rb')  { "spec/controllers" }  # Capybara request specs  watch(%r{^app/vIEws/(.+)/.*\.(erb|haml)$})          { |m| "spec/requests/#{m[1]}_spec.rb" }end

保护终端输出

dougt@dougt-ThinkPad-W520 ~/project $bundle exec guardGuard uses NotifySend to send notifications.Guard is Now watching at '/home/dougt/project'Starting Spork for RSpecUsing RSpec,Railspreloading Rails environmentLoading Spork.prefork block...DEPRECATION WARNING: The InstanceMethods module insIDe ActiveSupport::Concern will be no longer included automatically. Please define instance methods directly in Sunspot::Rails::SolrInstrumentation instead. (called from <top (required)> at /home/dougt/project/config/environment.rb:5)Spork is ready and Listening on 8989!Spork server for RSpec successfully startedGuard::RSpec is running,with RSpec 2!Running all specsDEPRECATION WARNING: The InstanceMethods module insIDe ActiveSupport::Concern will be no longer included automatically. Please define instance methods directly in Sunspot::Rails::SolrInstrumentation instead. (called from <top (required)> at /home/dougt/project/config/environment.rb:5)/home/dougt/project/app/models/dropBox_token.rb:7: warning: already initialized constant ACCESS_TYPE/home/dougt/project/app/models/dropBox_token.rb:9: warning: already initialized constant DROPBox_SETTINGS*.........**.....................***....***.....................***......*......................*Pending:  UserMailer add some examples to (or delete) /home/dougt/project/spec/mailers/user_mailer_spec.rb    # No reason given    # ./spec/mailers/user_mailer_spec.rb:4  PersonNote add some examples to (or delete) /home/dougt/project/spec/models/person_note_spec.rb    # No reason given    # ./spec/models/person_note_spec.rb:4  Task add some examples to (or delete) /home/dougt/project/spec/models/task_spec.rb    # No reason given    # ./spec/models/task_spec.rb:4  Alert add some examples to (or delete) /home/dougt/project/spec/models/alert_spec.rb    # No reason given    # ./spec/models/alert_spec.rb:4  SlIDe add some examples to (or delete) /home/dougt/project/spec/models/slIDe_spec.rb    # No reason given    # ./spec/models/slIDe_spec.rb:4  BetaTester add some examples to (or delete) /home/dougt/project/spec/models/beta_tester_spec.rb    # No reason given    # ./spec/models/beta_tester_spec.rb:4  SlIDeContent add some examples to (or delete) /home/dougt/project/spec/models/slIDe_content_spec.rb    # No reason given    # ./spec/models/slIDe_content_spec.rb:4  Sharedfile add some examples to (or delete) /home/dougt/project/spec/models/shared_file_spec.rb    # No reason given    # ./spec/models/shared_file_spec.rb:4  fileActivity add some examples to (or delete) /home/dougt/project/spec/models/file_activity_spec.rb    # No reason given    # ./spec/models/file_activity_spec.rb:4  EmailHelper add some examples to (or delete) /home/dougt/project/spec/helpers/email_helper_spec.rb    # No reason given    # ./spec/helpers/email_helper_spec.rb:14  TodolinesHelper add some examples to (or delete) /home/dougt/project/spec/helpers/todo_lines_helper_spec.rb    # No reason given    # ./spec/helpers/todo_lines_helper_spec.rb:14  UserHelper add some examples to (or delete) /home/dougt/project/spec/helpers/user_helper_spec.rb    # No reason given    # ./spec/helpers/user_helper_spec.rb:14  Taskshelper add some examples to (or delete) /home/dougt/project/spec/helpers/tasks_helper_spec.rb    # No reason given    # ./spec/helpers/tasks_helper_spec.rb:14  todo_lines/show.HTML.erb add some examples to (or delete) /home/dougt/project/spec/vIEws/todo_lines/show.HTML.erb_spec.rb    # No reason given    # ./spec/vIEws/todo_lines/show.HTML.erb_spec.rb:4Finished in 7.71 secondsRunning: spec/models/todo_file_spec.rbDEPRECATION WARNING: The InstanceMethods module insIDe ActiveSupport::Concern will be no longer included automatically. Please define instance methods directly in Sunspot::Rails::SolrInstrumentation instead. (called from <top (required)> at /home/dougt/project/config/environment.rb:5)/home/dougt/project/app/models/dropBox_token.rb:7: warning: already initialized constant ACCESS_TYPE/home/dougt/project/app/models/dropBox_token.rb:9: warning: already initialized constant DROPBox_SETTINGS.....................Finished in 3.05 seconds21 examples,0 failures
解决方法 您可以对spork进行配置并使用结果来要求prefork块中的内容

http://www.opinionatedprogrammer.com/2011/02/profiling-spork-for-faster-start-up-time/

Devise以及可能还有其他gems调用reload也存在问题,可以通过在spec_helper prefork块中添加以下内容来捕获这些方法:

...  ENV["RAILS_ENV"] ||= 'test'        # For Devise  require "rails/application"  Spork.trap_method(Rails::Application,:reload_routes!)  Spork.trap_method(Rails::Application::RoutesReloader,:reload!)  ...
总结

以上是内存溢出为你收集整理的ruby-on-rails – 每次Spork初始化导轨并慢慢运行全部内容,希望文章能够帮你解决ruby-on-rails – 每次Spork初始化导轨并慢慢运行所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/langs/1280472.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-09
下一篇 2022-06-09

发表评论

登录后才能评论

评论列表(0条)

保存