我在我的Rails应用程序中守卫,测试套件(最小的)最近停止正常工作。
如果我很幸运,它会运行所有测试一次,也许两次。在那之后,即使一个小的测试文件被更改,使用gem变得徒劳也需要很长时间。
在测试运行时跟随top
,我可以看到有一个红宝石过程占据了100%以上的CPU 持续。即使所有测试都运行完毕,我也没有对文件进行任何更改。
红宝石过程是:
/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
宝石版本:
答案 0 :(得分:17)
<强> SOLUTION:强>
我通过向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机器上遇到了类似的东西:
我试图守卫
没有变化。
我的同事在同一个项目上使用linux,所以他使用rb-inotify而不是rb-fsevent。他在空转时没有负载(正如你对mac os所期望的那样......)。
如上所述,我的解决方案是在我的Guardfile中添加一个'ignore'语句。