Skip to content

Instantly share code, notes, and snippets.

@johnbintz
Created May 10, 2011 18:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save johnbintz/965115 to your computer and use it in GitHub Desktop.
Save johnbintz/965115 to your computer and use it in GitHub Desktop.
Running RSpec and jasmine-headless-webkit using watchr
# all tests, run all at start
ACCEPTANCE=true watchr test.watchr
# all tests, don't run at start
ACCEPTANCE=true watchr test.watchr -- -f
# skip acceptance (the slow ones)
watchr test.watchr
require 'getoptlong'
watch('app/views/.*\.jst') { jasmine }
watch('public/javascripts/(.*)\.js') { |m| jasmine(m[1]) }
watch('app/coffeescripts/(.*)\.coffee') { |m| jasmine(m[1]) }
watch('spec/javascripts/(.*)_spec\..*') { |m| jasmine(m[1]) }
watch('app/(.*)\.rb') { |file| rspec(file[1]) }
watch('spec/(.*)_spec\.rb') { |file| rspec(file[1]) }
def newest_spec(file)
Dir["spec/javascripts/#{file}_spec.{js,coffee}"].sort { |left, right| File.mtime(right) <=> File.mtime(left) }.first
end
def system_v(command)
puts command
system command
end
JASMINE_RUNNER = %{jammit -f 2>/dev/null && bundle exec jasmine-headless-webkit} if !self.class.const_defined?(:JASMINE_RUNNER)
def jasmine(file = nil)
file = newest_spec(file) if file
system_v %{#{JASMINE_RUNNER} #{file || ''}}
system_v JASMINE_RUNNER if file && $?.exitstatus == 0
end
RSPEC_RUNNER = %{bundle exec rspec} if !self.class.const_defined?(:RSPEC_RUNNER)
def rspec(file = nil)
all = (file == nil)
if file
file = [ "spec/#{file}_spec.rb" ]
else
file = Dir['spec/**/*_spec.rb']
end
if !ENV['ACCEPTANCE']
file = file.reject { |f| f['/acceptance/'] }
end
file = file.find_all { |f| File.file?(f) }
system_v %{#{RSPEC_RUNNER} #{file.join(' ')}}
system_v %{#{RSPEC_RUNNER} spec} if !all && $?.exitstatus == 0
end
opts = GetoptLong.new(
['-f', GetoptLong::NO_ARGUMENT]
)
run = true
opts.each do |opt, arg|
case opt
when '-f'
run = false
end
end
if run
rspec
jasmine
else
puts "Watching for changes..."
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment