Repository navigation
Description
Hi guys
My set up is as follows:
I am developing a rails app in a virtual machine being managed by vagrant. Currently, I am using rsync to update files in the virtual machine. My rsync arguments in Vagrant look like this:
config.vm.synced_folder "./data", "/var/www/nginx",
type: "rsync",
owner: "root",
group: "www",
rsync__exclude: ["tmp/", ".git/", "Gemfile.lock"],
rsync__args: ["-rltW", "--delete", "--chown=false"]
In addition, I am using the guard-rspec gem to perform automated testing.
I know that guard works correctly because if I change a file from within the VM, guard runs fine. However, when I change a file on the host machine it does not seem to run.
When I run guard in debug mode (guard -d) and change a file from within the VM, I see the following output (and guard works like a charm):
21:37:05 - DEBUG - Start interactor
21:37:06 - DEBUG - Interactor was stopped or killed
21:37:06 - DEBUG - Hook :run_on_modifications_begin executed for Guard::RSpec
However, when I run guard in debug mode and change the same file on my host I see this output:
21:37:09 - DEBUG - Start interactor
21:38:06 - DEBUG - Interactor was stopped or killed
21:38:06 - DEBUG - Start interactor
I understand that the fact that the Interactor is killed means that it is picking up the file change. What I don't understand is why this is not being processed correctly (i.e. the hook is missing). Can anyone help?
Here's my guardfile in full, in case it helps. Thanks in advance.
PS: I did try using listen to forward local file system changes, but it seems that listen doesn't support TCP forwarding any more. In addition, I can't get version 2.9 of listen to work either. But, given that guard seems to be detecting the file system change, I think I'm missing something very small (and possibly very obvious)...
guard :rspec, cmd: "bundle exec rspec" do
require "guard/rspec/dsl"
dsl = Guard::RSpec::Dsl.new(self)
# Feel free to open issues for suggestions and improvements
# RSpec files
rspec = dsl.rspec
watch(rspec.spec_helper) { rspec.spec_dir }
watch(rspec.spec_support) { rspec.spec_dir }
watch(rspec.spec_files)
# Ruby files
ruby = dsl.ruby
dsl.watch_spec_files_for(ruby.lib_files)
# Rails files
rails = dsl.rails(view_extensions: %w(erb haml slim))
dsl.watch_spec_files_for(rails.app_files)
dsl.watch_spec_files_for(rails.views)
watch(rails.controllers) do |m|
[
rspec.spec.("routing/#{m[1]}_routing"),
rspec.spec.("controllers/#{m[1]}_controller"),
rspec.spec.("acceptance/#{m[1]}")
]
end
# Rails config changes
watch(rails.spec_helper) { rspec.spec_dir }
watch(rails.routes) { "#{rspec.spec_dir}/routing" }
watch(rails.app_controller) { "#{rspec.spec_dir}/controllers" }
# Capybara features specs
watch(rails.view_dirs) { |m| rspec.spec.("features/#{m[1]}") }
watch(rails.layouts) { |m| rspec.spec.("features/#{m[1]}") }
# Turnip features and steps
watch(%r{^spec/acceptance/(.+)\.feature$})
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m|
Dir[File.join("**/#{m[1]}.feature")][0] || "spec/acceptance"
end
end
Activity
e2 commentedon Oct 10, 2015
Have you checked that the rsync does work? If you have a host file, does the VM file get changed?
Listen has a debugging option, so you can run
LISTEN_GEM_DEBUGGING=2 bundle exec guardIf you post the output of that, it should be easier to find out what changes are actually happening, and why Guard isn't handling them.
tden012 commentedon Oct 11, 2015
Yes, rsync works correctly. I know this because I have opened the synced files using nano on the VM side. In addition, guard runs without a flaw using forced polling (however, I don't like that option because it chews through a lot of system resources... my CPU fan runs overtime when I use the option)
Okay, so here is the output that I got from it. Having taken a look at the last few lines myself, I would hazard a guess that Guard is picking up the the changed file as a new addition rather than a modification... perhaps this is where the issue is?
e2 commentedon Oct 11, 2015
Yes, it looks like rsync in catching the file change while it's being saved by your editor (or whatever tool you're using for changes).
You should just change your editor setting on how it creates backup files (maybe none at all). I think modifying the file in-place is the best option.
Listenhas some techniques for supporting specific editors to avoid this - what editor are you using?tden012 commentedon Oct 13, 2015
Sorry for the delay on this.
The editor I'm using is gedit, and I've been using it with backup files turned off. As far as I know, it is modifying the file directly. Is there anything I need to do to get gedit to work correctly?
e2 commentedon Oct 14, 2015
You can try increasing the wait delay: https://github.com/guard/guard/wiki/Command-line-options-for-Guard#-y--wait-for-delay-option
gedit was supposed to be supported, though the backup files don't match what you're getting:
https://github.com/guard/listen/blob/master/lib/listen/silencer.rb#L24
If you can, try a different editor first, and see if you get different results.
If not, I'll probably need the output and the version of gedit you're using.
I'm guessing that if you add something like this to your
Guardfileit may work. (Show me the output with debugging so I can confirm).
tden012 commentedon Oct 19, 2015
Thanks for sticking with me on.
So, I the delay option, but that didn't seem to work.
I also tried the option with the ignore command, but no luck there either. This is my Guardfile with the command (just in case I'm using it wrong - your line is at the top of the file)
The debug output, after running with ignore is:
I'm using gedit version 3.10.4 with backup files unchecked, if that helps. But perhaps it's not specific to an editor, because I tried editing with both Geany and nano (from within the terminal) but had no luck.
e2 commentedon Oct 20, 2015
Ok, I got it. It's rsync that's creating those files.
Just subscribe to this issue here: guard/listen#350
I'm closing this here, since this will be fixed as soon as I release a new version of Listen with the fix.
e2 commentedon Oct 20, 2015
Actually, this should fix it (add
--inplace):tden012 commentedon Oct 27, 2015
Hey, sorry for the delay on this - got caught up for a bit. I just tried out your fix and it works! Thanks for your help with this. I have to remember this in the future - didn't figure that rsync replacing instead of editing the files would cause this issue.
e2 commentedon Oct 27, 2015
Glad to help :)