guard-jasmine-headless-webkit
guard-jasmine-headless-webkit copied to clipboard
Generated Guardfile code does not support source files with js.coffee extension
The code generated by guard init jasmine-headless-webkit does not support source files with js.coffee extension.
Consider this part of the code added to the Guardfile:
spec_location = "spec/javascripts/%s_spec"
guard 'jasmine-headless-webkit' do
watch(%r{^app/assets/javascripts/(.*)\.(js|coffee)$}) { |m| newest_js_file(spec_location % m[1]) }
end
The problem as I see it lies in the regular expression used. For a path ending in ".js.coffee", the regex match will end in "{filename}.js" instead of just ending in {filename}. Doing "spec_location % m[1]" afterwards results in "{filename}.js_spec" being fed to the "newest_js_file" function, which then brings up nothing.
I was able to fix it by adding
watch(%r{^app/assets/javascripts/(.*)\.js\.coffee$}) { |m| newest_js_file(spec_location % m[1]) }
Simply adding "js.coffee" as extra possible extension to the original regex doesn't work because the regex engine still "prefers" to consider "coffee" as the tail, as opposed to "coffee.js". Removing the option of a sole "coffee" extension would fix that, but then handling files ending in ".coffee" would require an extra watch statement.
My regex skills are too limited too quickly come up with a expression properly covering all possible cases. I leave this as an exercise to the reader. ;)