Skip to content

Instantly share code, notes, and snippets.

@jpablobr
Created February 14, 2012 23:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpablobr/1831795 to your computer and use it in GitHub Desktop.
Save jpablobr/1831795 to your computer and use it in GitHub Desktop.
Tork TCP notifications
require 'socket'
require 'tork/config'
require 'set'
failed_test_files = Set.new
socket = TCPSocket::new("localhost", 5000)
Config.test_event_hooks.push lambda {|message|
event, test_file, line_numbers, log_file = message
# make notifications edge-triggered: pass => fail or vice versa.
# we do not care about pass => pass or fail => fail transitions.
case event.to_sym
when :fail
if failed_test_files.add? test_file
icon = 'dialog-error'
end
when :pass
if line_numbers.empty? and failed_test_files.delete? test_file
icon = 'dialog-information'
end
end
if icon
title = [event.upcase, test_file].join(' ')
statistics = File.readlines(log_file)
.grep(/^\d+ \w+,/)
.join
.gsub(/\e\[\d+(;\d+)?m/, '') # strip ANSI SGR escape codes
message = "#{title}, #{statistics}"
Thread.new { socket.puts(message) }
end
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment