当您使用 RubyMine 运行保护进行测试时,为保护规范配置单独的数据库环境非常有用,否则您会遇到奇怪的问题(一个进程或另一个进程冻结或给出不一致的结果。
将您的保护规范环境命名为“ci”并在 database.yml 中创建一个附加条目。我将“ci”用于持续自动化。
然后将其放入您的 Guardfile 中。关键是
'RAILS_ENV' => 'ci'
我的设置如下:
group :spec do
guard :spork, :rspec_port => 1234, :cucumber_env => { 'RAILS_ENV' => 'ci' }, :rspec_env => { 'RAILS_ENV' => 'ci' } do
watch('config/application.rb')
watch('config/environment.rb')
watch(%r{^config/environments/.+.rb$})
watch(%r{^config/initializers/.+.rb$})
watch('spec/spec_helper.rb')
watch(%r{app/models/.+\.rb})
watch(%r{app/views/.+\.haml})
watch('Gemfile')
watch('Gemfile.lock')
watch('test/test_helper.rb')
end
# environment is 'ci'
guard :rspec, :cli => '--drb --drb-port 1234', :version => 2, :all_after_pass => false, :notification => true, :environment => 'ci' 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{^spec/.+_spec.rb$})
watch(%r{^app/(.+).rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^lib/(.+).rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch(%r{^app/controllers/(.+)_(controller).rb$}) do |m|
["spec/routing/#{m[1]}_routing_spec.rb",
"spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb",
"spec/acceptance/#{m[1]}_spec.rb",
"spec/requests/#{m[1]}_spec.rb"]
end
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
end
然后我运行
bundle exec guard -g spec
我也不介意让 RubyMine 每 60 秒自动保存一次文件,即使这会启动 Guard,因为我的新 MBP Retina 在运行 Guard 时不会明显变慢。
顺便说一句,Guard running specs 真的很棒,因为您会发现失败的测试比尝试在 RubyMine 中自己运行测试要快得多。即,测试基本上是在我的手指从 cmd-s 释放以保存时完成的。
我从终端运行它。我还没有尝试使用 RubyMine 运行。有人想评论这样做的好处吗?我想让堆栈转储可点击会很好。