I have the following in my Guardfile for a Rails project:
guard 'coffeescript', :input => 'app/assets/javascripts'
As a result, whenever I save a foo.js.coffee
file, it compiles that file to a matching foo.js
.
I want to keep this line in my Guardfile, because it can catch compilation errors. However, I don't want the foo.js
files to remain in the project, so I'd like to know if there's a way for guard to delete them after the tests pass.
What can I do?
I'm not sure really why you want to remove the file (or why not set the output folder to public/assets/javascripts), but you should be able to add a callback hook after tests run:
# Guardfile
guard 'rspec' do
watch(...) { ... }
callback(:run_on_modifications_end) do
File.unlink('app/assets/javascript/foo.js')
end
end
The '_end' hook should not run if the tests fail, so this should do what you want it to.