Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Angular guardfile
# Copy ActiveSupport::Inflector.underscore to convert CamelCase angular controller names to snake_case controller spec names
class String
def underscore
self.gsub(/::/, '/').
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
gsub(/([a-z\d])([A-Z])/,'\1_\2').
tr("-", "_").
downcase
end
end
guard :teaspoon do
# Implementation files
watch(%r{app/assets/javascripts/(.+).js}) { |m| "#{m[1]}_spec" }
watch(%r{app/assets/javascripts/angular/(.+).js}) { |m| "spec/javascripts/#{m[1]}_spec" }
# Specs / Helpers
watch(%r{spec/javascripts/(.*)})
# Angular controllers
watch(%r{app/assets/javascripts/angular/controllers/(.+).js}) { |m| "spec/javascripts/controllers/#{m[1].underscore.gsub(/ctrl/, 'controller')}_spec" }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment