Skip to content

Instantly share code, notes, and snippets.

@janvarljen
Created October 10, 2015 14:20
Show Gist options
  • Select an option

  • Save janvarljen/aecd58da3b8b2d017a69 to your computer and use it in GitHub Desktop.

Select an option

Save janvarljen/aecd58da3b8b2d017a69 to your computer and use it in GitHub Desktop.
# A sample Guardfile
# More info at https://github.com/guard/guard#readme
## Uncomment and set this to only include directories you want to watch
# directories %w(app lib config test spec features) \
# .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
## Note: if you are using the `directories` clause above and you are not
## watching the project directory ('.'), then you will want to move
## the Guardfile to a watched dir and symlink it back, e.g.
#
# $ mkdir config
# $ mv Guardfile config/
# $ ln -s config/Guardfile .
#
# and, you'll have to watch "config/Guardfile" instead of "Guardfile"
guard 'zeus' do
require 'ostruct'
rspec = OpenStruct.new
rspec.spec_dir = 'spec'
rspec.spec = ->(m) { "#{rspec.spec_dir}/#{m}_spec.rb" }
rspec.spec_helper = "#{rspec.spec_dir}/spec_helper.rb"
# matchers
rspec.spec_files = /^#{rspec.spec_dir}\/.+_spec\.rb$/
# Ruby apps
ruby = OpenStruct.new
ruby.lib_files = /^(lib\/.+)\.rb$/
watch(rspec.spec_files)
watch(rspec.spec_helper) { rspec.spec_dir }
watch(ruby.lib_files) { |m| rspec.spec.call(m[1]) }
# Rails example
rails = OpenStruct.new
rails.app_files = /^app\/(.+)\.rb$/
rails.views_n_layouts = /^app\/(.+(?:\.erb|\.haml|\.slim))$/
watch(rails.app_files) { |m| rspec.spec.call(m[1]) }
watch(rails.views_n_layouts) { |m| rspec.spec.call(m[1]) }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment