monkeytest 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/monkeytest.rb +112 -24
  2. data/lib/tasks/monkey.rake +30 -3
  3. metadata +4 -3
data/lib/monkeytest.rb CHANGED
@@ -1,21 +1,41 @@
1
1
 
2
+ VERSION = 0.2
3
+
2
4
  module Monkey
3
5
 
4
6
  PATTERN = /.+_test.rb/
5
7
  DIRECTORIES = ['./test/unit/','./test/functional/','./test/integration/']
6
8
 
7
- def self.run_tests(mode)
9
+ def self.run_tests(mode, html=false)
10
+
11
+ unless `less ./lib/tasks/monkey.rake | grep \"created with monkeytest #{VERSION}\"`.size > 0
12
+ puts "It looks like you've updated your gem.\nPlease run monkeytest again on your project."
13
+ exit 1
14
+ end
15
+
8
16
  quiet = ((mode.to_s == "quiet") or (mode.to_s == "q"))
9
17
  silent = ((mode.to_s == "silent") or (mode.to_s == "s"))
10
18
  directories = DIRECTORIES.collect {|dir| File.expand_path(dir) }
11
19
  failures = Array.new
12
20
  totalTests = totalAsserts = totalErrors = totalFailures = 0
13
21
 
22
+ if html
23
+ puts "<div id='monkeytest'>"
24
+ end
25
+
14
26
  directories.each do |dir|
15
- puts "#{dir.match(/\/([^\/]+)\/?$/)[1].upcase} TESTS:".bold
27
+ if html
28
+ puts "<div style='margin-bottom: 1em;'><div style='font-weight: bold;'>#{dir.match(/\/([^\/]+)\/?$/)[1].upcase} TESTS:</div><table style='width: 550px;'>"
29
+ else
30
+ puts "\n#{dir.match(/\/([^\/]+)\/?$/)[1].upcase} TESTS:".bold
31
+ end
16
32
  Dir.foreach(dir) do |file|
17
33
  if file.match(PATTERN)
18
- print " #{file.ljust(35)}"
34
+ if html
35
+ print "<tr><td style='width: 50%; padding-left: 8px;'>#{file}</td>"
36
+ else
37
+ print " #{file.ljust(35)}"
38
+ end
19
39
 
20
40
  fullResult = `ruby -C \"#{dir}\" \"#{dir}/#{file}\"`
21
41
 
@@ -30,47 +50,115 @@ module Monkey
30
50
  totalErrors += numErrors
31
51
  totalFailures += numFailures
32
52
 
33
- print "#{numTests.to_s.rjust(4)} Tests "
34
- print "#{numAsserts.to_s.rjust(4)} Assertions "
35
-
53
+ if html
54
+ print "<td style='width: 20%; text-align:right;'>#{numTests.to_s} Tests</td>"
55
+ print "<td style='width: 20%; text-align:right;'>#{numAsserts.to_s} Assertions</td>"
56
+ else
57
+ print "#{numTests.to_s.rjust(4)} Tests "
58
+ print "#{numAsserts.to_s.rjust(4)} Assertions "
59
+ end
60
+
36
61
  if numErrors > 0 then
37
- puts "ERROR".red
62
+ if html
63
+ puts "<td style='color: red; width: 10%; text-align:right;'>ERROR</td></tr>"
64
+ else
65
+ puts "ERROR".red
66
+ end
38
67
  failures.push fullResult
39
68
  elsif numFailures > 0 then
40
- puts "FAIL".yellow
69
+ if html
70
+ puts "<td style='color: yellow; width: 10%; text-align:right;'>FAIL</td></tr>"
71
+ else
72
+ puts "FAIL".yellow
73
+ end
41
74
  failures.push fullResult
42
75
  else
43
- puts "PASS".green
76
+ if html
77
+ puts "<td style='color: green; width: 10%; text-align:right;'>PASS</td></tr>"
78
+ else
79
+ puts "PASS".green
80
+ end
44
81
  end
45
82
  end
46
83
  end
84
+ if html
85
+ print "</table></div>"
86
+ end
87
+ end
88
+ if html
89
+ puts "<hr style=\"width: 500px; position: absolute; left: 25px;\"/>"
90
+ puts "<div id='totals'>"
91
+ print "<table style='width: 550px;'><tr><td style='font-weight: bold; width: 40%;'>TOTALS</td>"
92
+ print "<td style='width: 20%; text-align:right;'>#{totalTests.to_s} Tests</td>"
93
+ print "<td style='width: 20%; text-align:right;'>#{totalAsserts.to_s} Assertions</td>"
94
+ print "<td style='width: 20%; text-align:right;'>#{(totalFailures+totalErrors).to_s} Problem(s)</td></tr></table>"
95
+ else
96
+ puts '-'*80
97
+ print "TOTALS:".bold.ljust(38)
98
+ print "#{totalTests.to_s.rjust(4)} Tests "
99
+ print "#{totalAsserts.to_s.rjust(4)} Assertions "
100
+ print "#{(totalFailures+totalErrors).to_s.rjust(4)} Problem(s)\n"
47
101
  end
48
- puts '-'*80
49
- print "TOTALS:".bold.ljust(38)
50
- print "#{totalTests.to_s.rjust(4)} Tests "
51
- print "#{totalAsserts.to_s.rjust(4)} Assertions "
52
- print "#{(totalFailures+totalErrors).to_s.rjust(4)} Problem(s)\n"
53
102
  if silent
54
- puts "\n"
103
+ if html
104
+ puts "</div>"
105
+ else
106
+ puts "\n"
107
+ end
55
108
  elsif quiet
56
- puts "\n\nErrors & Failures:".bold unless failures.empty?
109
+
110
+ if html
111
+ puts "<div id='errors-failures' style=\"margin-top: 20px\"><div style='font-weight: bold;'>Errors & Failures</div>"
112
+ else
113
+ puts "\n\nErrors & Failures:".bold
114
+ end unless failures.empty?
115
+
116
+ puts "<table>" if html
57
117
  failures.each do |badthing|
58
118
  while matches = badthing.match(/(Error|Failure):[\s]+(test_[^\()]+)\(([^\)]+)\)([\s]\[[^\]]+\/(.+?):([\d]+)\])?/m) do
59
- msg = " #{matches[1].ljust(10).red}" if matches[1] == "Error"
60
- msg = " #{matches[1].ljust(10).yellow}" if matches[1] == "Failure"
61
- msg << " #{matches[3].underline} : #{matches[2]}"
62
- msg << " (#{matches[5]}:#{matches[6]})" unless matches[6].nil?
119
+ unless html
120
+ msg = " #{matches[1].ljust(10).red}" if matches[1] == "Error"
121
+ msg = " #{matches[1].ljust(10).yellow}" if matches[1] == "Failure"
122
+ msg << " #{matches[3].underline} : #{matches[2]}"
123
+ msg << " (#{matches[5]}:#{matches[6]})" unless matches[6].nil?
124
+ else
125
+ msg = "<tr>"
126
+ msg << "<td style=\"color:#FF0000; width: 10%\">#{matches[1]}</td>" if matches[1] == "Error"
127
+ msg << "<td style=\"color:#FFFF00; width: 10%\">#{matches[1]}</td>" if matches [1] == "Failure"
128
+ msg << "<td><u>#{matches[3]}</u> : #{matches[2]}"
129
+ msg << " (#{matches[5]}:#{matches[6]})" unless matches[6].nil?
130
+ msg << "</td></tr>"
131
+ end
63
132
  puts msg
64
133
  badthing = matches.post_match
65
134
  end
66
135
  end
67
- puts "\n"
136
+ if html
137
+ puts "</table></div>"
138
+ else
139
+ puts "\n"
140
+ end
68
141
  else
69
- puts "\n\nErrors & Failures:".bold unless failures.empty?
142
+ if html
143
+ puts "<div id='errors-failures'><div style='font-weight: bold;'>Errors & Failures</div>" unless failures.empty?
144
+ else
145
+ puts "\n\nErrors & Failures:".bold unless failures.empty?
146
+ end
70
147
  failures.each do |badthing|
71
- puts badthing
72
- puts "\n"
148
+ if html
149
+ puts badthing
150
+ puts "</div>"
151
+ else
152
+ puts badthing
153
+ puts "\n"
154
+ end
155
+ if html
156
+ puts "</div>"
157
+ end
73
158
  end
74
159
  end
160
+ if html
161
+ puts "</div>"
162
+ end
75
163
  end
76
164
  end
@@ -1,5 +1,6 @@
1
1
  # ===================================================
2
2
  # A set of rake tasks for running monkey tests.
3
+ # created with monkeytest 0.2
3
4
  # ===================================================
4
5
 
5
6
  begin
@@ -33,18 +34,44 @@ rescue Exception => e
33
34
  end
34
35
 
35
36
  namespace :test do
37
+
36
38
  namespace :monkey do
39
+
40
+ namespace :silent do
41
+ desc "Outputs per-file summary only in HTML."
42
+ task :html do
43
+ Monkey.run_tests(:silent, true)
44
+ end
45
+
46
+ end
47
+
48
+ namespace :quiet do
49
+ desc "Outputs per-file summary as well as a method level summaries in HTML."
50
+ task :html do
51
+ Monkey.run_tests(:quiet, true)
52
+ end
53
+
54
+ end
55
+
37
56
  desc "Outputs per-file summary only."
38
57
  task :silent do
39
- Monkey.run_tests(:silent)
58
+ Monkey.run_tests(:silent, false)
40
59
  end
60
+
41
61
  desc "Outputs per-file summary as well as a method level summaries."
42
62
  task :quiet do
43
- Monkey.run_tests(:quiet)
63
+ Monkey.run_tests(:quiet, false)
64
+ end
65
+
66
+ desc "Outputs per-file summary as well as full failure messages in HTML."
67
+ task :html do
68
+ Monkey.run_tests(:normal, true)
44
69
  end
45
70
  end
71
+
46
72
  desc "Outputs per-file summary as well as full failure messages."
47
73
  task :monkey do
48
- Monkey.run_tests(:normal)
74
+ Monkey.run_tests(:normal, false)
49
75
  end
76
+
50
77
  end
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.8.11
2
+ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: monkeytest
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.1.1
7
- date: 2006-10-27 00:00:00 -04:00
6
+ version: 0.2.0
7
+ date: 2006-11-01 00:00:00 -05:00
8
8
  summary: A set of rake tasks for pretty testing of rails apps.
9
9
  require_paths:
10
10
  - lib
@@ -25,6 +25,7 @@ required_ruby_version: !ruby/object:Gem::Version::Requirement
25
25
  platform: ruby
26
26
  signing_key:
27
27
  cert_chain:
28
+ post_install_message:
28
29
  authors:
29
30
  - Geoff Parsons & Marshall Huss
30
31
  files: