guard gem do not watch file changes

前端 未结 2 1750
臣服心动
臣服心动 2020-12-22 06:22

I am using:

  • rails 5.1.5
  • guard 2.14.2
  • linuxmint

Yesterday I installed guard, with the plugins livereload and <

相关标签:
2条回答
  • 2020-12-22 06:36

    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.

    0 讨论(0)
  • 2020-12-22 06:47

    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
    
    0 讨论(0)
提交回复
热议问题