Created
February 14, 2012 23:57
-
-
Save jpablobr/1831795 to your computer and use it in GitHub Desktop.
Tork TCP notifications
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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