Skip to content

Commit

Permalink
add configs for autotest and watchr
Browse files Browse the repository at this point in the history
  • Loading branch information
dchelimsky committed Mar 14, 2010
1 parent bd31129 commit 4540235
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .autotest
@@ -0,0 +1,6 @@
Autotest.add_hook :initialize do |at|
at.add_mapping(%r%^lib/.*\.rb$%) {
at.files_matching %r%^spec/.*\_spec.rb$%
}
end

1 change: 1 addition & 0 deletions autotest/discover.rb
@@ -0,0 +1 @@
Autotest.add_discovery { "rspec2" }
57 changes: 57 additions & 0 deletions specs.watchr
@@ -0,0 +1,57 @@
# Run me with:
#
# $ watchr specs.watchr

# --------------------------------------------------
# Convenience Methods
# --------------------------------------------------
def all_test_files
Dir['spec/**/*_spec.rb']
end

def run_test_matching(thing_to_match)
matches = all_test_files.grep(/#{thing_to_match}/i)
if matches.empty?
puts "Sorry, thanks for playing, but there were no matches for #{thing_to_match}"
else
run matches.join(' ')
end
end

def run(files_to_run)
puts("Running: #{files_to_run}")
system("clear;rspec -cfs #{files_to_run}")
no_int_for_you
end

def run_all
run(all_test_files.join(' '))
end

# --------------------------------------------------
# Watchr Rules
# --------------------------------------------------
watch('^spec/(.*)_spec\.rb') { run_all }
watch('^lib/(.*)\.rb') { run_all }

# --------------------------------------------------
# Signal Handling
# --------------------------------------------------

def no_int_for_you
@sent_an_int = nil
end

Signal.trap 'INT' do
if @sent_an_int then
puts " A second INT? Ok, I get the message. Shutting down now."
exit
else
puts " Did you just send me an INT? Ugh. I'll quit for real if you do it again."
@sent_an_int = true
Kernel.sleep 1.5
run_all
end
end

# vim:ft=ruby

0 comments on commit 4540235

Please sign in to comment.