Skip to content

Instantly share code, notes, and snippets.

@RobinDaugherty
Created January 19, 2018 19:48
Show Gist options
  • Save RobinDaugherty/1dd664c8397757a459fabc4b3a40b724 to your computer and use it in GitHub Desktop.
Save RobinDaugherty/1dd664c8397757a459fabc4b3a40b724 to your computer and use it in GitHub Desktop.
Guardfile example
group :development do
gem 'guard', require: false
gem 'guard-rspec', require: false
gem 'guard-migrate', require: false
gem 'guard-rubocop', require: false
gem 'guard-bundler', require: false
gem 'guard-pow', require: false
end
# rubocop:disable Style/RegexpLiteral
require 'active_support/inflector'
notification :terminal_notifier
ignore %r{^(tmp|log|run|bin)/}
guard 'migrate', test_prepare: true do
watch(%r{^db/migrate/(\d+).+\.rb})
watch('db/seeds.rb')
end
# Runs rubocop only after the specs have passed.
# https://github.com/yujinakayama/guard-rubocop#advanced-tips
group :red_green_refactor, halt_on_fail: true do
rspec_options = {
failed_mode: :keep,
}
rspec_format = "--format documentation"
if ENV['RSPEC_OPEN_BROWSER']
rspec_options = rspec_options.merge(
launchy: './tmp/spec_results.html',
)
rspec_format += " --format doc --format html --out ./tmp/spec_results.html"
end
rspec_options[:cmd] = "bundle exec rspec #{rspec_format}"
guard 'rspec', rspec_options do
watch(%r{spec/(rails|spec)_helper.rb}) { "spec/" }
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^config/routes.rb$}) { |m| "spec/request" }
watch(%r{^app/controllers/(.*)\.rb$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
watch(%r{^app/controllers/(.*)\.rb$}) { |m| "spec/controllers/#{m[1]}_spec.rb" }
watch(%r{^app/views/(.+)/}) { |m| "spec/requests/#{m[1]}_controller_spec.rb" }
watch(%r{^app/views/(.+)/}) { |m| "spec/controllers/#{m[1]}_controller_spec.rb" }
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
end
rubocop_options = {
cli: %w(-D --format fuubar),
all_on_start: false,
keep_failed: false,
}
if ENV['RUBOCOP_OPEN_BROWSER']
rubocop_options[:launchy] = './tmp/rubocop_results.html'
rubocop_options[:cli] += %w(--format html -o ./tmp/rubocop_results.html)
end
guard :rubocop, rubocop_options do
watch('Guardfile')
watch('config.ru')
watch('Rakefile')
watch(%r{.+\.rb$})
watch(%r{.+\.rake$})
# Rerun rubocop on everything in the folder or below a .rubocop.yml file
watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
end
end
guard 'pow', restart_on_start: false, restart_on_reload: false do
# Restart the application in Pow when these files change.
watch('.powrc')
watch('.powenv')
watch('.ruby-version')
watch('Gemfile.lock')
watch(%r{^config})
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment