Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Guard clears screen more than once per single watch event #316

japgolly opened this Issue Aug 9, 2012 · 8 comments


None yet
2 participants

japgolly commented Aug 9, 2012

Hi. If you run guard with the -c option Guard is clears the screen before running new tests. There is a problem, however, when used in conjunction with multiple guard groups. See the following example of a scenario with two groups

  1. File modified.
  2. Guard checks Group A
    1. Clear screen.
    2. Matching rule found - run test.
  3. Guard checks Group B
    1. Clear screen.
    2. No matching rule found - do nothing.

Which means the user sees tests run and then they disappear before they can be read.

japgolly commented Aug 9, 2012

Extra info:

With my setup, this is consistently replicatable.
Given the Guardfile below, if I edit anything under lib/blah/ the screen gets clears twice.
If I edit anything under test/unit or test/spec then it correctly only gets cleared once.

Guardfile (simplified)

# Ignore Vim swap files
ignore /~$/
ignore /^(?:.*[\\\/])?\.[^\\\/]+\.sw[p-z]$/

group :unit do
  guard 'minitest', test_folders: 'test/unit', test_file_patterns: '*_test.rb' do

    watch(%r'^lib/blah/(.+)\.rb$') {|m| "test/unit/#{m[1]}_test.rb"}


group :spec do
  guard 'rspec', binstubs: true, spec_paths: ['test/spec'], all_on_start: false, all_after_pass: false do

    watch(%r'^lib/blah/(.+)\.rb$') {|m| "test/spec/#{m[1]}_spec.rb"}


thibaudgg commented Aug 9, 2012

Yeah, it's a known issue.
We could memorize if the screen has been already clean per run, and skip a second screen clean.

@ghost ghost assigned thibaudgg Aug 9, 2012

Sounds like a plan. Maybe it'd help to have the clear-screen code could be in it's own class that then gets passed around to anyone interested, that would make it easy for it to maintain its own state. Just an idea :)


thibaudgg commented Aug 10, 2012

Yeah good idea, I'll try to have a look at that this week-end. Thanks!

No worries mate! If there's anything you'd like me to help with just give me a shout ;)


thibaudgg commented Aug 14, 2012

Committed on this PR (#318) could you give it a try please.

Just tested it out, I couldn't reproduce the problem, works perfectly! Nice work mate!!


thibaudgg commented Aug 15, 2012

Thanks, Guard 1.3.2 has been released with this fix!

@thibaudgg thibaudgg closed this Aug 15, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment