Created
November 3, 2013 03:03
-
-
Save adamjt/7286132 to your computer and use it in GitHub Desktop.
Dot-autotest file for sending test results to the Pushover service.
This file contains 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 'pushover' | |
PUSHOVER_CHARACTER_LIMIT = 512 | |
Pushover.configure do |config| | |
config.user = 'xxxxx' | |
config.token = 'xxxxx' | |
end | |
Autotest.add_hook :initialize do |autotest| | |
%w{.git .DS_Store db log tmp vendor}.each do |exception| | |
autotest.add_exception(exception) | |
end | |
end | |
Autotest.add_hook :all do |autotest| | |
Pushover.notification(message: 'All specs passed.', title: 'Autotest') | |
end | |
Autotest.add_hook :green do |autotest| | |
Pushover.notification(message: 'Specs passed.', title: 'Autotest') | |
end | |
Autotest.add_hook :red do |autotest| | |
results_line_array = autotest.results.lines | |
msg_list = [] | |
msg = "Specs failed.\n\n" | |
# Chop the test results up into messages small enough for the Pushover API | |
while !results_line_array.empty? do | |
if (msg.size + results_line_array[0].size) <= PUSHOVER_CHARACTER_LIMIT | |
msg << results_line_array.shift | |
else | |
msg_list << msg | |
msg = '' | |
end | |
end | |
msg_list << msg unless msg.empty? | |
# Pushover app displays notifications chronologically, descending. | |
# Reversing the order makes it easier to read in the app. | |
# The sleep statement ensures the messages arrive in the proper sequence. | |
msg_list.reverse.each do |m| | |
Pushover.notification(message: m, title: 'Autotest') | |
sleep 1 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Disable colorization of your test output, otherwise the results may be filled with shell color characters.