grosser-autotest 4.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,26 @@
1
+ module Autotest::AutoUpdate
2
+ @@sleep_time, @@update_cmd, @@updater = 60, "svn up", nil
3
+
4
+ def self.sleep_time= o
5
+ @@sleep_time = o
6
+ end
7
+
8
+ def self.update_cmd= o
9
+ @@update_cmd = o
10
+ end
11
+
12
+ Autotest.add_hook :run_command do |at|
13
+ @@updater.kill if @@updater
14
+ end
15
+
16
+ Autotest.add_hook :ran_command do |at|
17
+ @@updater = Thread.start do
18
+ loop do
19
+ puts "# Waiting for #{@@sleep_time} seconds before updating"
20
+ sleep @@sleep_time
21
+ puts "# Running #{@@update_cmd}"
22
+ system @@update_cmd
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,37 @@
1
+ require 'autotest'
2
+
3
+ ##
4
+ # CampingAutotest is an Autotest subclass designed for use with Camping projects.
5
+ #
6
+ # To use CampingAutotest pass the -camping flag to autotest.
7
+ #
8
+ # Contributed by Geoffrey Grosenbach http://nubyonrails.com
9
+
10
+ class Autotest::Camping < Autotest
11
+
12
+ def initialize # :nodoc:
13
+ super
14
+ @exceptions = %r%\.(log|db)$%
15
+
16
+ @test_mappings = {
17
+ %r%^test/fixtures/([^_]+)_.*s\.yml% => proc { |_, m|
18
+ "test/#{m[1]}_test.rb"
19
+ },
20
+ %r%^test/.*rb$% => proc { |filename, m|
21
+ filename
22
+ },
23
+ %r%^public/([^\/]+)/(models|controllers|views)\.rb$% => proc { |_, m|
24
+ "test/#{m[1]}_test.rb"
25
+ },
26
+ %r%^public/(.*)\.rb$% => proc { |_, m|
27
+ "test/#{m[1]}_test.rb"
28
+ },
29
+ }
30
+
31
+ return functional_tests
32
+ end
33
+
34
+ def tests_for_file(filename)
35
+ super.select { |f| @files.has_key? f }
36
+ end
37
+ end
@@ -0,0 +1,57 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'fileutils'
4
+
5
+ module Autotest::CCTray
6
+ MAX = 30
7
+ STATUS = {
8
+ :all_good => "Success",
9
+ :green => "Success",
10
+ :red => "Failure",
11
+ }
12
+ DIR = File.expand_path("~/Sites/dashboard")
13
+
14
+ def self.project_name= name
15
+ @@project_name = name
16
+ end
17
+
18
+ def self.update_status status
19
+ dir = File.join(DIR, @@project_name)
20
+ serial = Time.now.to_i
21
+ file = "status.#{serial}.xml"
22
+ FileUtils.mkdir_p dir
23
+ Dir.chdir dir do
24
+ File.open(file, 'w') do |f|
25
+ f.puts %(<Project name="#{@@project_name}" activity="Sleeping" lastBuildStatus="#{STATUS[status]}" lastBuildLabel="build.#{serial}" lastBuildTime="#{Time.now.xmlschema}" webUrl="http://localhost/~ryan/dashboard/#{@@project_name}/"/>)
26
+ end
27
+ files = Dir["*.xml"].sort_by { |f| File.mtime f }.reverse
28
+ (files - files.first(MAX)).each do |f|
29
+ File.unlink f
30
+ end
31
+ end
32
+
33
+ Dir.chdir DIR do
34
+ new_file = "cctray.xml.#{$$}"
35
+ old_file = "cctray.xml"
36
+ File.open(from_file, "w") do |out|
37
+ out.puts "<Projects>"
38
+ Dir["*"].each do |d|
39
+ next unless File.directory? d
40
+ Dir.chdir d do
41
+ latest = Dir["*.xml"].sort_by { |f| File.mtime f }.last
42
+ out.puts File.read(latest)
43
+ end
44
+ end
45
+ out.puts "</Projects>"
46
+ end
47
+ File.rename new_file, old_file
48
+ end
49
+ end
50
+
51
+ [:run, :red, :green, :all_good].each do |status|
52
+ Autotest.add_hook status do |at|
53
+ STATUS[Time.now] = at.files_to_test.size
54
+ update_status status
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,6 @@
1
+ Autotest.add_discovery do
2
+ style = []
3
+ style << "rails" if File.exist? 'config/environment.rb'
4
+ style << "camping" if File.exist? 'test/camping_test_case.rb'
5
+ style
6
+ end
@@ -0,0 +1,36 @@
1
+ #
2
+ # Get autotest.el from http://www.emacswiki.org/cgi-bin/wiki/RyanDavis
3
+ #
4
+
5
+ module Autotest::Emacs
6
+ @@client_cmd = 'emacsclient -e'
7
+
8
+ def self.command= o
9
+ @@client_cmd = o
10
+ end
11
+
12
+ def self.emacs_autotest status
13
+ `#{@@client_cmd} \"(autotest-update '#{status})\"`
14
+ nil
15
+ end
16
+
17
+ Autotest.add_hook :run_command do |at|
18
+ emacs_autotest :running
19
+ end
20
+
21
+ Autotest.add_hook :green do |at|
22
+ emacs_autotest :passed
23
+ end
24
+
25
+ Autotest.add_hook :all_good do |at|
26
+ emacs_autotest :passed
27
+ end
28
+
29
+ Autotest.add_hook :red do |at|
30
+ emacs_autotest :failed
31
+ end
32
+
33
+ Autotest.add_hook :quit do |at|
34
+ emacs_autotest :quit
35
+ end
36
+ end
@@ -0,0 +1,66 @@
1
+ require 'net/smtp'
2
+
3
+ module Autotest::EmailNotify
4
+ @@smtp_settings = ['localhost']
5
+ @@from = nil
6
+ @@recipients = []
7
+ @@use_svn = true
8
+ @@report_every_run = false
9
+
10
+ @@last_rev = nil
11
+
12
+ def self.smtp_settings= o
13
+ @@smtp_settings = o
14
+ end
15
+
16
+ def self.from= o
17
+ @@from = o
18
+ end
19
+
20
+ def self.recipients= o
21
+ @@recipients = o
22
+ end
23
+
24
+ def self.use_svn= o
25
+ @@use_svn = o
26
+ end
27
+
28
+ def self.report_every_run= o
29
+ @@report_every_run = o
30
+ end
31
+
32
+ def self.notify title, msg
33
+ @@recipients.each do |to|
34
+ body = ["From: autotest <#{@@from}>"]
35
+ body << "To: <#{to}>"
36
+ body << "Subject: #{title}"
37
+ body << "\n"
38
+ body << msg
39
+ Net::SMTP.start(*@@smtp_settings) do |smtp|
40
+ smtp.send_message body.join("\n"), @@from, to
41
+ end
42
+ end
43
+ end
44
+
45
+ def self.svn_release
46
+ if @@use_svn
47
+ rev = `svn info`.match(/Revision: (\d+)/)[1]
48
+ return "r#{rev} "
49
+ end
50
+ end
51
+
52
+ Autotest.add_hook :ran_command do |at|
53
+ rev = self.svn_release
54
+ if @@report_every_run or rev != @@last_rev
55
+ @@last_rev = rev
56
+ output = at.results.join
57
+ failed = output.scan(/^\s+\d+\) (?:Failure|Error):\n(.*?)\((.*?)\)/)
58
+ if failed.size == 0 then
59
+ notify "#{rev}Tests Passed", output
60
+ else
61
+ f,e = failed.partition { |s| s =~ /Failure/ }
62
+ notify "#{rev}#{failed.size} Tests Failed", output
63
+ end
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,12 @@
1
+ # -*- ruby -*-
2
+
3
+ # This is an example of how to change the mappings of file that
4
+ # changed to tests to run for a project.
5
+
6
+ module Autotest::Fixtures
7
+ Autotest.add_hook :initialize do |at|
8
+ at.test_mappings['^test/fixtures/(.*)s.yml'] = proc { |filename, matches|
9
+ at.files_matching(/test\/\w+\/#{matches[1]}(_\w+)?.*_test.rb$/)
10
+ }
11
+ end
12
+ end
@@ -0,0 +1,29 @@
1
+ # -*- ruby -*-
2
+
3
+ module Autotest::Growl
4
+ def self.growl title, msg, pri = 0, img = nil
5
+ title += " in #{Dir.pwd.split(/\//).last(3).join("/")}"
6
+ msg += " at #{Time.now.strftime('%Y-%m-%d %H:%M:%S')}"
7
+ # TODO: parameterize default image
8
+ img ||= "/Applications/Mail.app/Contents/Resources/Caution.tiff"
9
+ cmd = "growlnotify -w -n autotest --image #{img} -p #{pri} -m #{msg.inspect} #{title}"
10
+ system cmd
11
+ nil
12
+ end
13
+
14
+ Autotest.add_hook :initialize do |at|
15
+ growl "autotest running", "Started"
16
+ end
17
+
18
+ Autotest.add_hook :red do |at|
19
+ growl "Tests Failed", "#{at.files_to_test.size} tests failed", 2
20
+ end
21
+
22
+ Autotest.add_hook :green do |at|
23
+ growl "Tests Passed", "Tests passed", -2 if at.tainted
24
+ end
25
+
26
+ Autotest.add_hook :all_good do |at|
27
+ growl "Tests Passed", "All tests passed", -2 if at.tainted
28
+ end
29
+ end
@@ -0,0 +1,14 @@
1
+ # -*- ruby -*-
2
+
3
+ module Autotest::Heckle
4
+ @@flags = []
5
+ @@klasses = []
6
+ def self.flags; @@flags; end
7
+ def self.klasses; @@klasses; end
8
+
9
+ Autotest.add_hook :all_good do |at|
10
+ heckle = "heckle" + (@@flags.empty? ? '' : " #{flags.join(' ')}")
11
+ cmd = @@klasses.map { |klass| "#{heckle} #{klass}" }.join(" && ")
12
+ system cmd
13
+ end
14
+ end
@@ -0,0 +1,31 @@
1
+ # -*- mode -*-
2
+
3
+ module Autotest::HtmlConsole
4
+ MAX = 30
5
+ STATUS = {}
6
+ PATH = File.expand_path("~/Sites/autotest.html")
7
+
8
+ def self.update
9
+ STATUS.delete STATUS.keys.sort.last if STATUS.size > MAX
10
+ File.open(PATH, "w") do |f|
11
+ f.puts "<title>Autotest Status</title>"
12
+ STATUS.sort.reverse.each do |t,s|
13
+ if s > 0 then
14
+ f.puts "<p style=\"color:red\">#{t}: #{s}"
15
+ else
16
+ f.puts "<p style=\"color:green\">#{t}: #{s}"
17
+ end
18
+ end
19
+ end
20
+ end
21
+
22
+ Autotest.add_hook :red do |at|
23
+ STATUS[Time.now] = at.files_to_test.size
24
+ update
25
+ end
26
+
27
+ Autotest.add_hook :green do |at|
28
+ STATUS[Time.now] = 0
29
+ update
30
+ end
31
+ end
@@ -0,0 +1,111 @@
1
+ begin; require 'rubygems'; rescue LoadError; end
2
+ require 'xmpp4r-simple'
3
+
4
+ module Autotest::JabberNotify
5
+ @@recipients = []
6
+ @@account = nil
7
+ @@password = nil
8
+ @@use_svn = true
9
+ @@report_every_run = true
10
+
11
+ @@im = nil
12
+ @@last_rev = nil
13
+ @@green = false
14
+
15
+ def self.recipients= o
16
+ @@recipients = o
17
+ end
18
+
19
+ def self.account= o
20
+ @@account = o
21
+ end
22
+
23
+ def self.password= o
24
+ @@password = o
25
+ end
26
+
27
+ def self.use_svn= o
28
+ @@use_svn = o
29
+ end
30
+
31
+ def self.report_every_run= o
32
+ @@report_every_run = o
33
+ end
34
+
35
+ def self.im
36
+ unless @@im
37
+ puts "# creating im client"
38
+ @@im = Jabber::Simple.new(@@account,@@password)
39
+ sleep(2) # need this or else the first announcement may cause an error
40
+ end
41
+ if !@@im.connected?
42
+ puts "# reconnecting to #{@@account}"
43
+ @@im.reconnect
44
+ end
45
+ @@im
46
+ end
47
+
48
+ def self.notify(msg)
49
+ @@recipients.each do |contact|
50
+ self.im.deliver(contact, msg)
51
+ end
52
+ end
53
+
54
+ def self.status(status)
55
+ rev = self.svn_release
56
+ status = "#{rev}#{status}"
57
+ self.im.status(:chat, status)
58
+ end
59
+
60
+ def self.svn_release
61
+ if @@use_svn
62
+ rev = `svn info`.match(/Revision: (\d+)/)[1]
63
+ return "r#{rev} "
64
+ end
65
+ end
66
+
67
+ # hooks
68
+
69
+ Autotest.add_hook :run do |at|
70
+ notify "autotest started"
71
+ end
72
+
73
+ Autotest.add_hook :run_command do |at|
74
+ status "testing"
75
+ end
76
+
77
+ Autotest.add_hook :ran_command do |at|
78
+ rev = self.svn_release
79
+ if @@report_every_run or rev != @@last_rev
80
+ @@last_rev = rev
81
+ output = at.results.join
82
+ failed = output.scan(/^\s+\d+\) ((?:Failure|Error):\n.*?\.*?\))/).flatten
83
+ failed.map! {|f| f.gsub!(/\n/,' '); f.gsub(/^/,'- ') }
84
+ time = output.scan(/Finished in (.*?)\n/)
85
+ if failed.size > 0 then
86
+ notify "Tests Passed\n#{time}\n" if !@@green
87
+ @@green = true # prevent repeat success notifications
88
+ else
89
+ @@green = false
90
+ notify "#{failed.size} Tests Failed\n" + failed.join("\n")
91
+ end
92
+ end
93
+ end
94
+
95
+ Autotest.add_hook :green do |at|
96
+ status "Tests Pass"
97
+ end
98
+
99
+ Autotest.add_hook :red do |at|
100
+ status "Tests Failed"
101
+ end
102
+
103
+ Autotest.add_hook :quit do |at|
104
+ notify "autotest is exiting"
105
+ self.im.disconnect
106
+ end
107
+
108
+ Autotest.add_hook :all do |at|_hook
109
+ notify "Tests have fully passed" unless $TESTING
110
+ end
111
+ end
@@ -0,0 +1,14 @@
1
+ # -*- ruby -*-
2
+
3
+ # stolen (with permission) from http://www.snailbyte.com/2006/08/24/rails-autotest-growl-notification-using-dcop-and-knotify
4
+
5
+ module Autotest::KDENotify
6
+ def self.knotify title, msg
7
+ system "dcop knotify default notify " +
8
+ "eventname \'#{title}\' \'#{msg}\' '' '' 16 2"
9
+ end
10
+
11
+ Autotest.add_hook :red do |at|
12
+ knotify "Tests failed", "#{at.files_to_test.size} tests failed"
13
+ end
14
+ end