guard gem do not watch file changes

跟風遠走 提交于 2019-11-28 12:53:12

问题


I am using:

  • rails 5.1.5
  • guard 2.14.2
  • linuxmint

Yesterday I installed guard, with the plugins livereload and minitest.

I use guard to automate my tests and make sure nothing gets broken by mistake.

I found out that for some reason, guard was not reacting to file changes. When it was first launched, it runned all tests, give me a prompt, and I had to press Enter in the prompt, and then, it start doing ALL THE TESTS again, each round takes about 1hr.


回答1:


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.




回答2:


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


来源:https://stackoverflow.com/questions/49227349/guard-gem-do-not-watch-file-changes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!