Remotely with capistrano

wybo edited this page Jan 17, 2012 · 5 revisions

You can also run your tests over capistrano, on a remote machine, assuming you have installed everything correctly on that machine, and deployed your changes to it.

If you run your tests over capistrano, you can get the same output as locally, with:

task :test do
  [some preparatory stuff]
  test_stream "rake parallel:spec 2>&1", :colorize => true

def test_stream(command, options = {})
  invoke_command(command) do |ch, stream, out| 
    trap("INT") { puts 'Interrupted'; exit 0; } 

    if options[:colorize]
      out.gsub!(/(?<= ^|[\.F*] ) \. (?= $|[\.F*] )/x, "\\033[32m.\\033[0m") # green
      out.gsub!(/(?<= ^|[\.F*] )  F (?= $|[\.F*] )/x, "\\033[31mF\\033[0m") # red
      out.gsub!(/(?<= ^|[\.F*] ) \* (?= $|[\.F*] )/x, "\\033[33m*\\033[0m") # orange

    print out

(this requires a decent network connection to the machine in question)