Skip to content

Commit

Permalink
Support #run_on_deletion to cleanup generated JavaScript.
Browse files Browse the repository at this point in the history
  • Loading branch information
netzpirat committed Sep 30, 2011
1 parent 435208d commit a9244b8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/guard/coffeescript.rb
Expand Up @@ -73,6 +73,18 @@ def run_on_change(paths)
throw :task_has_failed unless success
end

# Called on file(s) deletions that the Guard watches.
#
# @param [Array<String>] paths the deleted files or paths
# @raise [:task_has_failed] when run_on_change has failed
#
def run_on_deletion(paths)
Inspector.clean(paths).each do |file|
javascript = file.gsub(/(js\.coffee|coffee)$/, 'js')
File.remove(javascript) if File.exists?(javascript)
end
end

private

# Notify changed files back to Guard, so that other Guards can continue
Expand Down
10 changes: 10 additions & 0 deletions spec/guard/coffeescript_spec.rb
Expand Up @@ -143,4 +143,14 @@
guard.run_on_change(['a.coffee', 'b.coffee'])
end
end

describe '#run_on_deletion' do
it 'removes generated the generated javascript' do
inspector.should_receive(:clean).with(['a.coffee', 'b.coffee', 'c.coffee']).and_return ['a.coffee', 'b.coffee']
File.should_receive(:exists?).with('a.js').and_return true
File.should_receive(:exists?).with('b.js').and_return false
File.should_receive(:remove).with('a.js')
guard.run_on_deletion(['a.coffee', 'b.coffee', 'c.coffee'])
end
end
end

0 comments on commit a9244b8

Please sign in to comment.