guard gem do not watch file changes

穿精又带淫゛_ 提交于 2019-11-29 17:35:22

After googling and trying everything I found, nothing seemed to work. So, I cool down my horses, and decided to play with guard.

Problem found and solved.

PROBLEM: guard do not react (it is watching) on file changes

THE CAUSE: the regex that are used in Guardfile, seem to be incompatible with rails 5.1.5 file paths

SOLUTION:

guard :minitest do
  watch(%r{^app/views/(.+)_mailer/.+})  { |m| "test/mailers/#{m[1]}_mailer_test.rb" }
  watch(%r{^test/.+_test\.rb$})
  watch(%r{^test/test_helper\.rb$})     { 'test' }
  watch(%r{^app/controllers/(.*)\.rb$}) { |m| "test/functional/#{m[1]}_test.rb" }
  watch(%r{^app/controllers/(.*)\.rb$}) { |m| "test/controllers/#{m[1]}_test.rb" }
  watch(%r{^app/controllers/(.*)\.rb$}) { |m| "test/integration/#{m[1]}_test.rb" }
  watch(%r{^app/helpers/(.*)\.rb$})     { |m| "test/helpers/#{m[1]}_test.rb" }
  watch(%r{^app/mailers/(.*)\.rb$})     { |m| "test/mailers/#{m[1]}_test.rb" }
  watch(%r{^app/models/(.*)\.rb$})      { |m| "test/models/#{m[1]}_test.rb" }
  watch(%r{^app/veiws/(.*)\.rb$})       { |m| "test/system/#{m[1]}_test.rb" }
end

I hope this could be useful to you.

I just fine tuned the regex. Here they come:

guard :minitest do
  watch(%r{test\/.+\.rb})
  watch(%r{app\/controllers\/(.*)\.rb})       { |m| "test/controllers/#{m[1]}_test.rb" }
  watch(%r{app\/controllers\/(.*)\.rb})       { |m| "test/integration/#{m[1]}_test.rb" }
  watch(%r{app\/helpers\/(.*)\.rb})           { |m| "test/helpers/#{m[1]}_test.rb" }
  watch(%r{app\/models\/(.*)\.rb})            { |m| "test/models/#{m[1]}_test.rb" }
  watch(%r{app\/mailers\/(.*)\.rb})           { |m| "test/mailers/#{m[1]}_test.rb" }
  watch(%r{app\/views\/(.*)\/.*\.html\.haml}) { |m| "test/system/#{m[1]}_test.rb" }
  watch(%r{app\/views\/(.*)\/.*\.coffee})     { |m| "test/system/#{m[1]}_test.rb" }
end
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!