问题
I'm following along with the Ruby on Rails Tutorial.
Things are working pretty well, but I noticed that Guard only runs after I save some files (view or controller files), but doesn't run when I save others (routes or spec files). I've got Guard hooked up to Spork, not sure if that matters.
When I looked at the console window running Guard/Spork, I noticed an error after I saved the non-running tests:
Exception encountered: #<LoadError: no such file to load -- /Users/Tyler/Development/FirstRails/sample_app/spec/routing
I'm not sure what the syntax of the Guard file is, I just copied the example. Here is the Guard file:
# A sample Guardfile
# More info at https://github.com/guard/guard#readme
guard 'rspec', :version => 2, :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" }
# my edits
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
# Rails example
watch(%r{^spec/.+_spec\.rb$})
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{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_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('spec/spec_helper.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
guard 'spork', :cucumber_env => { 'RAILS_ENV' => 'test' }, :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')
end
In particular, my edits:
# my edits
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
I do not have a spec/routing folder.
Anybody see a simple typo? Or is there some other consideration I need to have?
I'm on rails 3.2
Thanks
回答1:
Found it:
["spec/routing/#{m[1]}_routing}spec.rb",
Notice the second }
between routing
and spec
Now reads:
["spec/routing/#{m[1]}_routing_spec.rb",
Also explains the missing directory shananigans.
Thanks!
回答2:
Can't comment on your answer Tyler (maybe because I'm new here), but I think you've repeated a few lines in the Guardfile:
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
I've noticed this is running tests twice; removing the duplicate lines solved this.
来源:https://stackoverflow.com/questions/9102483/guard-ruby-on-rails-3-2-tutorial