At some point in my development process, starting up guard/spork no longer resulted in RSpec being initially run as it used to be. I now have to hit "enter" at the guard console to cause the suite to run. I'd like to understand why this behavior changed and what I need to do have it run automatically.
I noticed also that Rails seems to be loading twice, although I'm not sure if that was true before or not. Finally, I'm using Jasmine and those tests are getting run at startup.
Here's my Guardfile, which is derived from the Hartl Rails tutorial.
# 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
Here's the console output (before hitting enter):
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)>
Here's the additional output after I hit "enter":
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)>
i see that you define guard :spork twice and if you want to run rspec on start you should define it in your guard rspec
guard :rspec, :all_on_start => true, ...