Skip to content

Instantly share code, notes, and snippets.

@agibralter
Created October 18, 2012 21:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save agibralter/3914760 to your computer and use it in GitHub Desktop.
Save agibralter/3914760 to your computer and use it in GitHub Desktop.
Setup for `bundle exec guard` to work without compressed assets but `rake guard:jasmine` to compress assets.
# Guardfile
# Spork
guard('spork', cucumber: false, test_unit: false, wait: 90) do
watch('config/application.rb')
watch('config/environment.rb')
watch(%r{^config/environments/.*\.rb$})
watch(%r{^config/initializers/.*\.rb$})
watch('spec/spec_helper.rb')
watch(%r{^spec/support/.*\.rb$})
end
# RSpec (without request specs because they are heavy)
guard('rspec', cli: '--drb --tag ~type:request --tag ~slow') do
# Watch all specs except for request specs. Since those can be quite heavy,
# run them manually.
watch(%r{^spec/(?!request/).+_spec\.rb$})
watch('spec/spec_helper.rb') { 'spec' }
watch(%r{^spec/support/(.+)\.rb$}) { 'spec' }
watch(%r{^lib/(.+)\.rb$}) do |m|
"spec/lib/#{m[1]}_spec.rb"
end
watch(%r{^app/(.+)\.rb$}) do |m|
"spec/#{m[1]}_spec.rb"
end
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) do |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
watch('app/controllers/application_controller.rb') { 'spec/controllers' }
watch('config/routes.rb') { 'spec/routing_spec.rb' }
end
guard('jasmine', {
# See the README, but basically I (Aaron) recommend setting up an entry in
# /etc/hosts and adding another virtual host in nginx.conf.
jasmine_url: 'http://app-jasmine.dev/jasmine',
port: 3002,
server: :app_jasmine_uncompressed_assets, # sets APP_HOST
server_env: :test,
timeout: 15000, # time in ms for whole test to finish
server_timeout: 15 # time in s for server to boot up
}) do
watch(%r{spec/javascripts/spec\.(js\.coffee|js|coffee)$}) do
"spec/javascripts"
end
watch(%r{spec/javascripts/.+_spec\.(js\.coffee|js|coffee)$})
watch(%r{app/assets/javascripts/(.+?)\.(js\.coffee|js|coffee)$}) do |m|
"spec/javascripts/#{m[1]}_spec.#{m[2]}"
end
end
# Won't be available in production/staging.
begin
require 'childprocess'
require 'guard/jasmine/task'
# Used by guard-jasmine to run a server that changes APP_HOST (for assets to
# resolve correctly). `do_not_compress` means don't "compress, compile, digest"
# assets. We want this to be true for `rake guard:jasmine`, which gets executed
# when we run the whole test suite. We want it to be false for when `bundle
# exec guard` is running so we can debug more easily in real time.
def run_jasmine(do_not_compress)
process = ChildProcess.build(
'rackup',
'-E', 'test',
'-p', ENV['JASMINE_PORT'] || '3002',
'-s', 'thin'
)
process.environment['APP_HOST'] = 'app-jasmine.dev'
process.environment['DO_NOT_COMPRESS_ASSETS'] = true if do_not_compress
process.io.inherit!
process.start
Signal.trap('TERM') do
Process.kill('TERM', process.pid)
end
Signal.trap('INT') do
Process.kill('INT', process.pid)
end
process.wait
end
task :app_jasmine_uncompressed_assets do
run_jasmine(true)
end
task :app_jasmine_compressed_assets do
run_jasmine(false)
end
# `rake guard:jasmine` runs the jasmine suite one time. This is not to be
# confused with the Guardfiles's jasmine section, which uses `rake
# app_jasmine`.
Guard::JasmineTask.new do |task|
task.options = [
'-e', 'test',
'-p', '3002',
'-u', 'http://app-jasmine.dev/jasmine',
'-s', 'app_jasmine_compressed_assets',
'-t', '15000', # time in ms for whole test to finish
'--server-timeout', '15 # time in s for server to boot up
].join(' ')
end
rescue LoadError
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment