如果我很幸运,它会运行所有测试一次,也许两次.在那之后,即使一个小的测试文件被更改,使用gem变得徒劳也需要很长时间才能响应.
当测试运行时跟随顶部时,我可以看到有一个ruby进程不断占用cpu的100%以上.即使所有测试都运行完毕,我也没有对文件进行任何更改.
ruby过程是:
/Users/BodacIoUs/.rvm/gems/ruby-2.0.0-p247@MyApp/gems/rb-fsevent-0.9.3/bin/fsevent_watch --latency 0.1 /Users/BodaIoU/Clients/MyApp
附加的屏幕截图中的(过程31332).
Ruby 2.0.0-p247
这是我的设置:
# Gemfile (with irrelevant gems removed) gem 'rails','4.0.0' group :test do gem 'launchy' gem "mocha",require: false gem 'database_cleaner' gem 'selenium-webdriver' gem 'capybara-webkit' # for headless javascript tests gem 'timecop' gem "minitest-focus" end group :development,:test do gem "minitest-rails" gem "minitest-rails-capybara" gem 'zeus' gem 'guard' gem 'guard-minitest' gem 'factory_girl_rails' end # Guardfile guard :minitest,all_on_start: false do # Rails 4 watch(%r{^app/(.+)\.rb}) { |m| "test/#{m[1]}_test.rb" } watch(%r{^app/controllers/application_controller\.rb}) { 'test/controllers' } watch(%r{^app/controllers/(.+)_controller\.rb}) { |m| "test/integration/#{m[1]}_test.rb" } watch(%r{^app/views/(.+)_mailer/.+}) { |m| "test/mailers/#{m[1]}_mailer_test.rb" } watch(%r{^lib/(.+)\.rb}) { |m| "test/lib/#{m[1]}_test.rb" } watch(%r{^test/.+_test\.rb}) watch(%r{^test/test_helper\.rb}) { 'test' } ignore(%r{^tmp/}) end # test_helper ENV["RAILS_ENV"] = "test" require File.expand_path("../../config/environment",__FILE__) require 'rails/test_help' require 'minitest/autorun' require 'minitest/pride' require "minitest/rails/capybara" require "mocha/setup" # Sidekiq https://github.com/mperham/sidekiq/wiki/Testing require 'sidekiq/testing' Sidekiq::Testing.fake! Dir[Rails.root.join('test','support','*.rb')].each do |file| require file end class MiniTest::Spec include FactoryGirl::Syntax::Methods include AllTestHelper end class ActiveSupport::TestCase include FactoryGirl::Syntax::Methods include AllTestHelper end class Capybara::Rails::TestCase include Rails.application.routes.url_helpers include Capybara::DSL include Capybara::Assertions include IntegrationTestHelper # Called before each Feature spec before :each do end # Called after each Feature spec after :each do Capybara.reset_sessions! end end
宝石版本:
> minitest(4.7.5)
> minitest-capybara(0.5.0)
> minitest-focus(1.1.0)
> minitest-Metadata(0.4.0)
> minitest-rails(0.9.2)
> minitest-rails-capybara(0.10.0)
> mobvIoUs-rails(0.1.2)
>摩卡(0.14.0)
>后卫(2.2.4)
> guard-minitest(2.1.2)
> rb-fsevent(0.9.3)
解决方法
我通过向Guardfile添加’ignore’语句来解决它.对于我的rails 3项目,它看起来像这样(./Guardfile):
ignore([%r{^bin/*},%r{^config/*},%r{^db/*},%r{^lib/*},%r{^log/*},%r{^public/*},%r{^tmp/*}]) guard 'rspec',cmd: 'spring rspec',all_after_pass: false,all_on_start: false,focus_on_Failed: true do # Rails watch(%r{^spec/.+_spec\.rb$}) ... end
看起来,这是guard / rspec / rails的最佳实践.
警卫’忽略’信息:https://github.com/guard/guard#ignore
我的问题
我在mac os x 10.9机器上遇到了类似的东西:
>春天(1.0.0)
> rb-fsevent(0.9.3)
>咆哮(1.0.3)
> rspec-core(2.14.7)
> rspec-expectations(2.14.4)
> rspec-mocks(2.14.4)
> rspec(2.14.1)
> guard-rspec(4.2.0)
>听(2.4.0)
> rspec-rails(2.14.0)
>铁轨(3.2.15)
在开始守卫进行我的rspec测试之后,守卫进程在“空转”时跳到100%负载在一个核心上,它保持足够长的时间让我有资格作为“永远”. 原文链接:https://www.f2er.com/ruby/269439.html