-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path.autotest
More file actions
112 lines (94 loc) · 3.31 KB
/
Copy path.autotest
File metadata and controls
112 lines (94 loc) · 3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#require 'active_support'
require 'active_support/inflector'
require 'autotest/timestamp'
module Autotest::GnomeNotify
# Time notification will be displayed before disappearing automatically
APP_TITLE = "p2p-training"
EXPIRATION_IN_SECONDS = 15
ERROR_STOCK_ICON = "gtk-cancel"
SUCCESS_STOCK_ICON = "gtk-apply"
WARNING_STOCK_ICON = "gtk-info"
def self.icon
# icons from http://www.famfamfam.com/lab/icons/silk/
=begin
path = File.join(File.dirname(__FILE__), "/.autotest_images/")
{
:green => "#{path}pass.png",
:red => "#{path}fail.png",
:info => "#{path}pending.png"
}
=end
{
:green => SUCCESS_STOCK_ICON,
:red => ERROR_STOCK_ICON,
:info => WARNING_STOCK_ICON
}
end
# Convenience method to send an error notification message
#
# [stock_icon] Stock icon name of icon to display
# [title] Notification message title
# [message] Core message for the notification
def self.notify stock_icon, title, message
#p icon[stock_icon]
options = "-t #{EXPIRATION_IN_SECONDS * 1000} -i #{icon[stock_icon]}"
cmd = "notify-send #{options} '#{title} test result' '#{message}'"
system cmd
end
def self.parse_rspec_results(at)
ran_results_re = /\d+ example(s?), \d+ failure(s?)(?:, \d+ pending)?/mi
completed = at.results[ran_results_re]
ran_results = completed.scan(/(\d+) (\w+)/).map do |v, k|
sk = ActiveSupport::Inflector.singularize(k.downcase).to_sym
[sk, v.to_i]
end
results = Hash[*ran_results.flatten]
end
Autotest.add_hook :initialize do |at|
at.add_exception(%r{^\./\.git})
at.add_exception(%r{^\./db})
at.add_exception(%r{^\./log})
at.add_exception(%r{^\./tmp})
at.add_exception(%r{^\./Gemfile\.lock})
at.add_exception(%r{^\./\.idea})
at.add_exception(%r{^\./.*\.log})
at.add_exception(%r{^\./rerun\.txt})
at.add_exception(%r{^\./test_report})
at.add_exception(%r{^\./public\/uploads})
end
Autotest.add_hook :red do |at|
result = parse_rspec_results(at)
msg = "#{result[:example]} executed, #{result[:failure]} failure(s)"
msg << ", #{result[:pending]} pending." if result[:pending]
notify :red, APP_TITLE, msg
end
Autotest.add_hook :green do |at|
result = parse_rspec_results(at)
if (!result[:pending].nil?) && (result[:pending] > 0) then
notify :info, APP_TITLE, "#{result[:example]} executed, #{result[:pending]} pending."
else
notify :green, APP_TITLE, "#{result[:example]} executed."
end
end
Autotest.add_hook :ran_features do |at|
results = at.results.select{ |line| line =~ /^\d+ \w+/
}.collect{|line|
line.gsub(/\e\[\d*m/, '')}.join
if results =~ /failed|undefined/m then
results << at.features_to_run
notify :red, "#{APP_TITLE} - Cucumber", results
elsif results =~ /pending/m then
results << at.features_to_run
notify :info,"#{APP_TITLE} - Cucumber", results
else
notify :green,"#{APP_TITLE} - Cucumber", results
end
# result = parse_rspec_results(at)
# p result
# if (!result[:pending].nil?) && (result[:pending] > 0) then
# notify :info, APP_TITLE, "#{result[:example]} executed, #{result[:pending]} pending."
# else
# notify :green, APP_TITLE, "#{result[:example]} executed."
# end
end
end