Skip to content

Instantly share code, notes, and snippets.

@kylewelsby
Created December 7, 2011 12:32
Show Gist options
  • Save kylewelsby/1442634 to your computer and use it in GitHub Desktop.
Save kylewelsby/1442634 to your computer and use it in GitHub Desktop.
Install Guard-RSpec to all RMV Rubies
#!/usr/bin/ruby env
guardfile = <<-'END'
def determine_rspec_version
if File.exist?("#{Dir.pwd}/spec/spec_helper.rb")
File.new("#{Dir.pwd}/spec/spec_helper.rb").read.include?("Spec::Runner") ? 1 : 2
elsif bundler?
# Allow RSpactor to be tested with RSpactor (bundle show inside a bundle exec)
ENV['BUNDLE_GEMFILE'] = "#{Dir.pwd}/Gemfile"
`bundle show rspec`.include?("/rspec-1.") ? 1 : 2
else
2
end
end
guard 'bundler', :notification => true do
watch('Gemfile')
end
begin
guard "spinach" do
puts "Running Spinach"
watch(%r|^features/(.*)\.feature|)
watch(%r|^features/steps/(.*)([^/]+)\.rb|) do |m|
"features/#{m[1]}#{m[2]}.feature"
end
end
rescue
puts "Looks like your not using Spinach in this Project."
end
guard "rspec", :cli => "--colour", :notification => false, :keep_failed => false, :all_after_pass => false, :all_on_start => false, :run_all => {:cli => "--colour #{determine_rspec_version == 1 ? '--format profile' : '--profile'}"} do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
# Rails example
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^db/migrate/\d+_(.+)\.rb}) { |m| "spec/migrations/#{m[1]}_migration_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"] }
watch('spec/spec_helper.rb') { "spec" }
watch('config/routes.rb') { "spec/routing" }
watch(%r{^script/(.+).rb}) { |m| "spec/script/#{m[1]}_spec.rb" }
watch('app/controllers/application_controller.rb') { "spec/controllers" }
# Capybara request specs
watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
end
group 'frontend' do
begin
guard 'livereload' do
watch(%r{app/.+\.(erb|haml)})
watch(%r{app/helpers/.+\.rb})
watch(%r{(public/|app/assets).+\.(css|js|html)})
watch(%r{(app/assets/.+\.css)\.s[ac]ss}) { |m| m[1] }
watch(%r{(app/assets/.+\.js)\.coffee}) { |m| m[1] }
watch(%r{config/locales/.+\.yml})
end
rescue
puts "Looks like your not using Live Reload"
end
begin
guard 'jasmine', :jasmine_url => 'http://localhost:8888/' do
watch(%r{public/javascripts/(.+)\.(js\.coffee|js|coffee)$}) { |m| "spec/javascripts/#{m[1]}_spec.#{m[2]}" }
watch(%r{app/assets/javascripts/(.+)\.(js\.coffee|js|coffee)$}) { |m| "spec/javascripts/#{m[1]}_spec.#{m[2]}" }
watch(%r{spec/javascripts/(.+)_spec\.(js\.coffee|js|coffee)$}) { |m| puts m.inspect; "spec/javascripts/#{m[1]}_spec.#{m[2]}" }
watch(%r{spec/javascripts/spec\.(js\.coffee|js|coffee)$}) { "spec/javascripts" }
end
rescue
puts "Looks like your not using Jasmine"
end
end
END
## Starts
#
#
#puts "Installing Guard to All Rubies (this make take a minute or three)"
#`rvm @global do gem install guard-rspec`
#puts "Guard Installed on All Rubies"
`rm ~/.Guardfile`
`touch ~/.Guardfile`
puts "Creating Guardfile"
File.open(File.expand_path("~/.Guardfile"),'wb') do |f|
f.write(guardfile)
end
puts "Complete. Guardfile is installed."
puts "install your guard gems to your projects e.g. `gem install guard-rspec`\n or install everything `gem install guard-rspec guard-spinach guard-jasmine guard-bundler guard-livereload`"
puts "Make sure you read the documentations"
puts "type `guard` to monitor file changes."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment