Skip to content

Instantly share code, notes, and snippets.

@tadejm
Last active August 29, 2015 13:58
Show Gist options
  • Save tadejm/10209786 to your computer and use it in GitHub Desktop.
Save tadejm/10209786 to your computer and use it in GitHub Desktop.
Guard, red green refactor with Rubocop
group :red_green_refactor, halt_on_fail: true do
guard :rspec, failed_mode: :keep, all_after_pass: true do
watch('spec/spec_helper.rb') { "spec" }
watch('spec/factories/factories.rb') { "spec" }
watch('config/routes.rb') { "spec/routing" }
watch('app/controllers/application_controller.rb') { "spec/controllers" }
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
end
guard :rubocop, all_on_start: false, cli: ['--format', 'simple', '--rails'] do
watch(%r{.+\.rb$})
watch(%r{(?:.+/)?\.rubocop\.yml$}) { |m| File.dirname(m[0]) }
end
end
if %w(development test).include?(Rails.env)
require 'rubocop/rake_task'
Rubocop::RakeTask.new
task(:default).clear
task default: [:spec, :rubocop]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment