2012-03-23 18 views
4

私のrspecテストが遅く実行されている理由を理解するのに助けが必要です。毎回スパークのレールを初期化してゆっくりと実行する

私はspork、guard、およびrspecを実行しています。しかし、sporkは毎回レールを再初期化しているようです。私はこの問題をデバッグする方法を考え出すのが難しいです。私は使用している宝石がこれを引き起こしていると思われますが、証拠はありません。

私はそれがリロードされると考える理由は次のとおりです。

  • それは先割れスプーンの内部で実行したり、外部の
  • は、私は(SOLR宝石に関連する)は、この警告を取得するために同じ時間を要しているI :: activesupportの内部InstanceMethodsモジュールを懸念が院生はもはやできなくなります:私は、サーバー

    すべてのスペックを実行

    DEPRECATION警告 レールを実行すると取得自動的にded。インスタンスメソッドを直接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 

    end 
end 

Spork.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" 

end 

group :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' 

end 

group :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' 
end 


gem '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#readme 

guard '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 } 
end 

guard '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 

ガード端子出力は

[email protected] ~/project $ bundle exec guard 
Guard uses NotifySend to send notifications. 
Guard is now watching at '/home/dougt/project' 
Starting Spork for RSpec 
Using RSpec, Rails 
Preloading Rails environment 
Loading 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 started 
Guard::RSpec is running, with RSpec 2! 
Running all specs 
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) 
/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:4 

Finished in 7.71 seconds 
Running: spec/models/todo_file_spec.rb 
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) 
/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 seconds 
21 examples, 0 failures 
+0

あなたの 'Guardfile'を投稿してください。 – James

+0

ガードファイルを追加しました – Doug

+1

スペックをどのくらい正確に実行していますか?ガードを起動する方法と、スペックを実行するときに表示されるガードを表示します。これをデバッグするには、より多くの端末出力が必要です。実際にsporkを再読み込みしている場合は、 'Reloading Spork for RSpec'がガードの出力に表示されるはずです。 – James

答えて

5

あなたは先割れスプーンをプロファイリングし、preforkのブロック内のものを必要とする結果を使用することができます

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

もありますDeviseと、おそらくリロードを呼び出す他の宝石との問題、これらのメソッドは、あなたの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!) 
    ... 
+0

私はこれらの3行をプリフォークに追加しようとしましたが、結果は変わりませんでした。 – Doug

+0

実際、そのリンクを読むことは多くの助けになりました。毎回たくさんのものが積み込まれていました。 – Doug

関連する問題