Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added watchr file.

  • Loading branch information...
commit 3979196400e66aba0a30130395c4dddf8e622117 1 parent b1e1547
@jnunemaker authored
Showing with 45 additions and 0 deletions.
  1. +45 −0 specs.watchr
View
45 specs.watchr
@@ -0,0 +1,45 @@
+def growl(title, msg, img)
+ %x{growlnotify -m #{ msg.inspect} -t #{title.inspect} --image ~/.watchr/#{img}.png}
+end
+
+def form_growl_message(str)
+ msg = str.split("\n").last
+ if msg =~ /(\d)\sfailure/
+ img = $1.to_i > 0 ? 'fail' : 'pass'
+ end
+ growl 'Results', msg, img
+end
+
+def run(cmd)
+ puts cmd
+ output = ""
+ IO.popen(cmd) do |com|
+ com.each_char do |c|
+ print c
+ output << c
+ $stdout.flush
+ end
+ end
+ form_growl_message output
+end
+
+def run_spec(path)
+ path.gsub!('lib/', 'spec/')
+ path.gsub!('_spec', '')
+ file_name = File.basename(path, '.rb')
+ path.gsub!(file_name, file_name + "_spec")
+ run %Q(bundle exec rspec #{path})
+end
+
+watch('spec/helper\.rb') { system('clear'); run('rake') }
+watch('lib/.*\.rb') { |m| system('clear'); run_spec(m[0]) }
+watch('spec/.*_spec\.rb') { |m| system('clear'); run_spec(m[0]) }
+
+# Ctrl-\
+Signal.trap('QUIT') do
+ puts " --- Running all tests ---\n\n"
+ run('rake')
+end
+
+# Ctrl-C
+Signal.trap('INT') { abort("\n") }
Please sign in to comment.
Something went wrong with that request. Please try again.