我正在关注Ruby on Rails Tutorial。
事情进展顺利,但我注意到Guard仅在保存一些文件(视图或控制器文件)后运行,但在保存其他文件(路由或spec文件)时不运行。我已经把警卫连接到Spork,不确定这是否重要。
当我查看运行Guard / Spork的控制台窗口时,我在保存非运行测试后发现错误:
Exception encountered: #<LoadError: no such file to load -- /Users/Tyler/Development/FirstRails/sample_app/spec/routing
我不确定Guard文件的语法是什么,我只是复制了这个例子。这是Guard文件:
# 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
特别是我的编辑:
# 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
我没有spec / routing文件夹。
有人看到一个简单的拼写错误?或者我需要考虑其他一些因素吗?
我在轨道上3.2
由于
答案 0 :(得分:2)
找到它:
["spec/routing/#{m[1]}_routing}spec.rb",
请注意}
和routing
spec
现在阅读:
["spec/routing/#{m[1]}_routing_spec.rb",
还解释了丢失的目录shananigans。
谢谢!
答案 1 :(得分:1)
不能评论你的答案Tyler(也许是因为我在这里很新),但我认为你在Guardfile中重复了几行:
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
我注意到这是两次运行测试;删除重复的行解决了这个问题。