2

在我的开发过程中的某个时刻,启动guard/spork 不再导致RSpec 最初像以前那样运行。我现在必须在守卫控制台上按“输入”才能使套件运行。我想了解为什么这种行为会发生变化以及我需要做什么才能让它自动运行。

我还注意到 Rails 似乎加载了两次,尽管我不确定以前是否如此。最后,我正在使用 Jasmine,并且这些测试启动时运行。

这是我的 Guardfile,它源自 Hartl Rails 教程。

# A sample Guardfile
# More info at https://github.com/guard/guard#readme
require 'active_support/core_ext'

guard 'spork', :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')
  watch('test/test_helper.rb')
  watch('spec/support/')
end

guard 'rspec', :all_after_pass => false, :cli => '--drb' 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" }

  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",
     (m[1][/_pages/] ? "spec/requests/#{m[1]}_spec.rb" : 
                       "spec/requests/#{m[1].singularize}_pages_spec.rb")]
  end
  watch(%r{^app/views/(.+)/}) do |m|
    (m[1][/_pages/] ? "spec/requests/#{m[1]}_spec.rb" : 
                       "spec/requests/#{m[1].singularize}_pages_spec.rb")
  end

  # Capybara request specs
  watch(%r{^app/views/(.+)/.*\.(erb|haml)$})          { |m| "spec/requests/#{m[1]}_spec.rb" }

  # Turnip features and steps
  watch(%r{^spec/acceptance/(.+)\.feature$})
  watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$})   { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
end


guard 'spork', :cucumber_env => { 'RAILS_ENV' => 'test' }, :rspec_env => { 'RAILS_ENV' => 'test' } do
  watch('config/application.rb')
  watch('config/environment.rb')
  watch('config/environments/test.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 :jasmine do
  watch(%r{spec/javascripts/spec\.(js\.coffee|js|coffee)$}) { 'spec/javascripts' }
  watch(%r{spec/javascripts/.+_spec\.(js\.coffee|js|coffee)$})
  watch(%r{spec/javascripts/fixtures/.+$})
  watch(%r{app/assets/javascripts/(.+?)\.(js\.coffee|js|coffee)(?:\.\w+)*$}) { |m| "spec/javascripts/#{ m[1] }_spec.#{ m[2] }" }
end

这是控制台输出(在按回车之前):

new-host-3:bot palfvin$ guard
17:48:09 - INFO - Guard is using Growl to send notifications.
17:48:09 - INFO - Guard is using TerminalTitle to send notifications.
17:48:09 - INFO - Starting Spork for RSpec
Using RSpec, Rails
Preloading Rails environment
Loading Spork.prefork block...
Spork is ready and listening on 8989!
17:48:15 - INFO - Spork server for RSpec successfully started

17:48:16 - INFO - Guard::RSpec is running
17:48:16 - INFO - Starting Spork for RSpec
Using RSpec, Rails
Preloading Rails environment
Loading Spork.prefork block...
Spork is ready and listening on 8989!
17:48:21 - INFO - Spork server for RSpec successfully started

17:48:22 - INFO - Guard::Jasmine starts thin spec server on port 51679 in development environment (coverage off).
17:48:26 - INFO - Waiting for Jasmine test runner at http://localhost:51679/jasmine
17:48:26 - INFO - Run all Jasmine suites
17:48:26 - INFO - Run Jasmine suite at http://localhost:51679/jasmine
17:48:29 - INFO - Finished in 0.02 seconds
17:48:29 - INFO - 12 specs, 0 failures

17:48:29 - INFO - Done.
17:48:29 - INFO - Guard is now watching at '/Users/palfvin/rails_projects/botmetrics'
[1] guard(main)> 

这是我点击“输入”后的附加输出:

17:54:58 - INFO - Run all
17:54:58 - INFO - Running all specs
Running tests with args ["--drb", "-f", "progress", "-r", "/Users/palfvin/.rvm/gems/ruby-2.0.0-p247@botmetrics/gems/guard-rspec-3.0.2/lib/guard/rspec/formatter.rb", "-f", "Guard::RSpec::Formatter", "--failure-exit-code", "2", "spec"]...
........................................................................................................

Finished in 5.54 seconds
104 examples, 0 failures

Coverage report generated for RSpec to /Users/palfvin/rails_projects/botmetrics/coverage. 391 / 481 LOC (81.29%) covered.
Done.

17:55:05 - INFO - Run all Jasmine suites
17:55:05 - INFO - Run Jasmine suite at http://localhost:51679/jasmine
17:55:08 - INFO - Finished in 0.018 seconds
17:55:08 - INFO - 12 specs, 0 failures

17:55:08 - INFO - Done.
[1] guard(main)> 
4

1 回答 1

4

我看到你定义了两次guard :spork,如果你想在启动时运行rspec,你应该在你的guard rspec 中定义它

 guard :rspec, :all_on_start => true, ...
于 2013-09-16T01:26:23.770 回答