examples/skeleton/spec/watchr.rb in win32-autogui-0.4.0 vs examples/skeleton/spec/watchr.rb in win32-autogui-0.4.1
- old
+ new
@@ -5,13 +5,24 @@
# Run me with:
#
# $ watchr spec/watchr.rb
require 'term/ansicolor'
+require 'rbconfig'
-$c = Term::ANSIColor
+WINDOWS = Config::CONFIG['host_os'] =~ /mswin|mingw/i unless defined?(WINDOWS)
+require 'win32/process' if WINDOWS
+if WINDOWS
+ begin
+ require 'Win32/Console/ANSI'
+ $c = Term::ANSIColor
+ rescue LoadError
+ STDERR.puts 'WARNING: You must "gem install win32console" (1.2.0 or higher) to get color output on MRI/Windows'
+ end
+end
+
def getch
state = `stty -g`
begin
`stty raw -echo cbreak`
$stdin.getc
@@ -33,18 +44,23 @@
def run(cmd)
pid = fork do
puts "\n"
- print $c.cyan, cmd, $c.clear, "\n"
+ if $c
+ print $c.cyan, cmd, $c.clear, "\n"
+ else
+ puts cmd
+ end
+
exec(cmd)
end
Signal.trap('INT') do
puts "sending KILL to pid: #{pid}"
Process.kill("KILL", pid)
end
- Process.waitpid(pid)
+ Process.waitpid(pid) if (pid > 0)
prompt
end
def run_all
@@ -78,11 +94,10 @@
run(cmd)
end
def run_all_specs
cmd = "spec _1.3.1_ --color --format s #{all_spec_files.join(' ')}"
- p cmd
run(cmd)
end
def run_spec(spec)
cmd = "spec _1.3.1_ --color --format s #{spec}"
@@ -93,11 +108,14 @@
def run_last_spec
run_spec($last_spec) if $last_spec
end
def prompt
- puts "Ctrl-\\ for menu, Ctrl-C to quit"
+ menu = "Ctrl-C to quit"
+ menu = menu + ", Ctrl-\\ for menu" if Signal.list.include?('QUIT')
+
+ puts menu
end
# init
$last_feature = nil
prompt
@@ -105,11 +123,11 @@
# --------------------------------------------------
# Watchr Rules
# --------------------------------------------------
watch( '^features/(.*)\.feature' ) { run_default_cucumber }
-#watch( '^bin/(.*)' ) { run_default_cucumber }
+watch( '^bin/(.*)' ) { run_default_cucumber }
watch( '^lib/(.*)' ) { run_default_cucumber }
watch( '^features/step_definitions/(.*)\.rb' ) { run_default_cucumber }
watch( '^features/support/(.*)\.rb' ) { run_default_cucumber }
@@ -117,27 +135,28 @@
# specify just the lib files that have specs
# TODO: This can be determined automatically from the spec file naming convention
watch( '^lib/(.*)' ) { run_default_spec }
# --------------------------------------------------
-# Signal Handling
+# Signal Handling (May not be supported on Windows)
# --------------------------------------------------
+if Signal.list.include?('QUIT')
+ # Ctrl-\
+ Signal.trap('QUIT') do
-# Ctrl-\
-Signal.trap('QUIT') do
+ puts "\n\nMENU: a = all , f = features s = specs, l = last feature (#{$last_feature ? $last_feature : 'none'}), q = quit\n\n"
+ c = getch
+ puts c.chr
+ if c.chr == "a"
+ run_all
+ elsif c.chr == "f"
+ run_default_cucumber
+ elsif c.chr == "s"
+ run_all_specs
+ elsif c.chr == "q"
+ abort("exiting\n")
+ elsif c.chr == "l"
+ run_last_feature
+ end
- puts "\n\nMENU: a = all , f = features s = specs, l = last feature (#{$last_feature ? $last_feature : 'none'}), q = quit\n\n"
- c = getch
- puts c.chr
- if c.chr == "a"
- run_all
- elsif c.chr == "f"
- run_default_cucumber
- elsif c.chr == "s"
- run_all_specs
- elsif c.chr == "q"
- abort("exiting\n")
- elsif c.chr == "l"
- run_last_feature
end
-
end