为什么rspec不能在后卫/ spork启动时运行?

时间:2013-09-16 00:57:31

标签: ruby-on-rails rspec jasmine guard spork

在我的开发过程中的某个时刻,启动防护/ 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)> 

1 个答案:

答案 0 :(得分:4)

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

 guard :rspec, :all_on_start => true, ...
相关问题