janx (owner)

Revisions

gist: 226978 Download_button fork
public
Public Clone URL: git://gist.github.com/226978.git
Embed All Files: show embed
watchr script for rspec, run spec on diff #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
require 'fileutils'
 
$cache_dir = File.join('tmp', 'watchr')
FileUtils.mkdir_p($cache_dir) unless File.exist?($cache_dir)
 
def modified?(file)
  cache_file = File.join $cache_dir, file
 
  `diff #{file} #{cache_file} >/dev/null 2>&1`
  if $? != 0
    cache_file_dir = File.dirname cache_file
    FileUtils.mkdir_p(cache_file_dir) unless File.exist?(cache_file_dir)
    FileUtils.cp file, cache_file
    return true
  end
 
  false
end
 
watch( '^spec/(.*)/(.*)\.rb' ) { |md|
  modified?(md[0]) && system("spec #{md[0]} --drb --colour --format progress")
}
 
watch( '^app/(.*)/(.*)\.rb' ) { |md|
  modified?(md[0]) && system("spec --drb --colour --format progress spec/#{md[1]}/#{md[2]}_spec.rb")
}
 
Signal.trap('INT') {
  FileUtils.rm_r $cache_dir
  abort("\n")
}