This repository has been archived by the owner on Mar 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 283
/
.watchr
62 lines (53 loc) · 1.71 KB
/
.watchr
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# Put this file in the root of your Rails project and ignore it with git:
#
# echo ".watchr" >> .git/info/exclude
#
# Now run it in a tab with the observr gem:
#
# gem install observr
# observr .watchr
#
# Optionally, install the Fuubar gem to get a progress bar.
FUUBAR_PATH = File.dirname(`gem which fuubar`.strip)
PROGRESSBAR_PATH = File.dirname(`gem which ruby-progressbar`.strip)
SEED_OPTIONS = ENV['SEED'] ? "--seed #{ENV['SEED']}" : ''
RSPEC_CMD = "bundle exec spring rspec --color --tty #{SEED_OPTIONS}"
@last_test = nil
def run_tests(test, force=false)
if (ft = focused_tests).any?
puts "Running focused test(s)..."
test = ft.join(' ')
end
test = @last_test unless File.exist?(test) or force or not @last_test
if force || File.exist?(test)
@last_test = test
puts "-" * 80
rspec_cmd = "#{RSPEC_CMD} #{format_options} #{test}"
puts test
cmd = IO.popen("#{rspec_cmd} 2>&1")
$stdout.write(cmd.getc) until cmd.eof?
else
puts "#{test} does not exist."
end
end
def run_suite
run_tests('spec', :force)
end
def focused_tests
Dir['spec/**/*_spec.rb'].to_a.select { |f| File.read(f).match(/, :focus|, focus: true|fdescribe|fcontext|fit ['"]/) rescue nil }
end
def binding_pry
system("grep --include *.rb -r \"binding\\.pry\" * &>/dev/null")
end
def format_options
return '' if binding_pry
if FUUBAR_PATH == ''
'--format progress'
else
"-I #{FUUBAR_PATH} -I #{PROGRESSBAR_PATH} --require fuubar --format Fuubar"
end
end
watch('^spec/.*_spec\.rb' ) { |m| run_tests(m.to_s) }
watch('^app/(.*)\.rb' ) { |m| run_tests("spec/#{m[1]}_spec.rb") }
watch('^lib/(.*)\.(rb|rake)') { |m| run_tests("spec/lib/#{m[1]}_spec.rb") }
Signal.trap('QUIT') { run_suite } # Ctrl-\