public
Rubygem
Description: Merb Core: All you need. None you don't.
Homepage: http://www.merbivore.com
Clone URL: git://github.com/wycats/merb-core.git
Search Repo:
Added autotest with (non-working, experimental) textmate support
wycats (author)
Sun Jan 13 08:02:18 -0800 2008
commit  496a43b7d0b1efabc8324e88383a7cc188a5c5d5
tree    4bd883b96948dc816d7c5c659e7bcd6125fcd0be
parent  72be5800e7b715ea544ba70f06129b29c0d7a6f1
...
 
 
 
...
1
2
3
0
@@ -1 +1,4 @@
0
+Autotest.add_discovery do
0
+ "merbsource"
0
+end
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
0
@@ -1 +1,132 @@
0
+require 'autotest'
0
+# require File.dirname(__FILE__) + '/textmate'
0
+
0
+$VERBOSE = false
0
+
0
+# cloned from Rspec's autotest settings, but modified
0
+# to cope w/ Merb's specs directory layout
0
+
0
+# ==== Merb Source Autotest Rules
0
+# 1. Updating a spec reruns that spec
0
+# 2. Updating a spec_helper reruns all specs at that level and below
0
+# 3. Updating a file under controller (i.e. abstract_controller.rb)
0
+# reruns all the specs under (public|private)/abstract_controller
0
+# 4. Updating a file under controller/mixins (e.g. render)
0
+# reruns all specs under
0
+# (public|private)/(abstract_controller|controller)/render_spec.rb
0
+# 5. Updating a file directly under merb_core (e.g. core_ext.rb)
0
+# reruns all the specs under spec/(public|private)/core_ext
0
+# 6. Updating merb.rb reruns all specs
0
+
0
+class RspecCommandError < StandardError; end
0
+
0
+class Autotest::MerbsourceRspec < Autotest
0
+
0
+ Autotest.add_hook :initialize do |at|
0
+ %w{.git}.each {|exception| at.exceptions.push exception}
0
+ end
0
+
0
+ require 'ruby-debug'
0
+
0
+ Autotest.add_hook :run do |at|
0
+ # See above for human-readable descriptions of these rules
0
+ # 1 above
0
+ at.add_mapping(%r{^spec/.*_spec\.rb$}) { |filename, _| filename}
0
+
0
+ # 2 above
0
+ at.add_mapping(%r{^spec/(.*)/spec_helper\.rb$}) { |_, m| at.files_matching %r{^spec/#{m[1]}/.*_spec\.rb$} }
0
+
0
+ # 3 above
0
+ at.add_mapping(%r{^lib/merb_core/controller/([^/]*)\.rb$}) { |_, m| at.files_matching %r{^spec\/(public|private)\/#{m[1]}\/.*_spec\.rb} }
0
+
0
+ # 4 above
0
+ at.add_mapping(%r{^lib/merb_core/controller/mixins/([^/]*)\.rb$}) { |_, m| at.files_matching %r{^spec/(public|private)/(abstract_)?controller/#{m[1]}_spec\.rb} }
0
+
0
+ # 5 above
0
+ at.add_mapping(%r{^lib/merb_core/([^/]*)\.rb$}) { |_, m| at.files_matching %r{^spec/(public|private)/#{m[1]}/.*_spec\.rb} }
0
+
0
+ # 6 above
0
+ at.add_mapping(%r{^lib/merb\.rb$}) { at.files_matching %r{^spec/[^/]*_spec\.rb$} }
0
+
0
+ end
0
+
0
+ def initialize(kernel = Kernel, separator = File::SEPARATOR, alt_separator = File::ALT_SEPARATOR) # :nodoc:
0
+ super() # need parens so that Ruby doesn't pass our args
0
+ # to the superclass version which takes none..
0
+
0
+ @kernel, @separator, @alt_separator = kernel, separator, alt_separator
0
+ @spec_command = spec_command
0
+ end
0
+
0
+ attr_accessor :failures
0
+
0
+ def tests_for_file(filename)
0
+ super.select { |f| @files.has_key? f }
0
+ end
0
+
0
+ alias :specs_for_file :tests_for_file
0
+
0
+ def failed_results(results)
0
+ results.scan(/^\d+\)\n(?:\e\[\d*m)?(?:.*?Error in )?'([^\n]*)'(?: FAILED)?(?:\e\[\d*m)?\n(.*?)\n\n/m)
0
+ end
0
+
0
+ def handle_results(results)
0
+ @failures = failed_results(results)
0
+ @files_to_test = consolidate_failures @failures
0
+ unless $TESTING
0
+ if @files_to_test.empty?
0
+ hook :green
0
+ else
0
+ hook :red
0
+ end
0
+ end
0
+ @tainted = true unless @files_to_test.empty?
0
+ end
0
+
0
+ def consolidate_failures(failed)
0
+ filters = Hash.new { |h,k| h[k] = [] }
0
+ failed.each do |spec, failed_trace|
0
+ @files.keys.select { |f| f =~ /spec\// }.each do |f|
0
+ if failed_trace =~ Regexp.new(f)
0
+ filters[f] << spec
0
+ break
0
+ end
0
+ end
0
+ end
0
+ filters
0
+ end
0
+
0
+ def make_test_cmd(files_to_test)
0
+ "#{ruby} -S #{@spec_command} #{test_cmd_options} #{files_to_test.keys.flatten.join(' ')}"
0
+ end
0
+
0
+ def test_cmd_options
0
+ '-O specs/spec.opts' if File.exist?('specs/spec.opts')
0
+ end
0
+
0
+ # Finds the proper spec command to use. Precendence
0
+ # is set in the lazily-evaluated method spec_commands. Alias + Override
0
+ # that in ~/.autotest to provide a different spec command
0
+ # then the default paths provided.
0
+ def spec_command
0
+ if cmd = spec_commands.detect { |c| File.exist? c }
0
+ @alt_separator ? (cmd.gsub @separator, @alt_separator) : cmd
0
+ else
0
+ raise RspecCommandError, 'No spec command could be found!'
0
+ end
0
+ end
0
+
0
+ # Autotest will look for spec commands in the following
0
+ # locations, in this order:
0
+ #
0
+ # * bin/spec
0
+ # * default spec bin/loader installed in Rubygems
0
+ def spec_commands
0
+ if (spec = `which spec`.chomp) && !spec.empty?
0
+ return [spec]
0
+ end
0
+ [File.join('bin', 'spec'),
0
+ File.join(Config::CONFIG['bindir'], 'spec')]
0
+ end
0
+end
...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
...
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
0
@@ -1 +1,45 @@
0
+if ENV["TM_RUBY"]
0
+ module Autotest::HtmlConsole
0
+ MAX = 30
0
+ STATUS = {}
0
+ OUT_DUP = STDOUT.dup
0
+ require 'stringio'
0
+ # $stdout = StringIO.new
0
+ # $stderr = StringIO.new
0
+
0
+ OUT_DUP.puts <<-HERE
0
+ <html>
0
+ <head>
0
+ <title>AutoTest Results</title>
0
+ <script>document.body.innerHTML = ''</script>
0
+ </head>
0
+ <body>
0
+
0
+ </body>
0
+ </html>
0
+ HERE
0
+
0
+ def self.update(failures = nil)
0
+ STATUS.delete STATUS.keys.sort.last if STATUS.size > MAX
0
+ STATUS.sort.reverse.each do |t,s|
0
+ if s > 0 then
0
+ OUT_DUP.puts "<p style=\"color:red\">#{t}: #{failures.join("<br/>")}</p>"
0
+ else
0
+ OUT_DUP.puts "<p style=\"color:green\">#{t}: #{s}</p>"
0
+ end
0
+ end
0
+ OUT_DUP.flush
0
+ end
0
+
0
+ Autotest.add_hook :red do |at|
0
+ STATUS[Time.now] = at.files_to_test.size
0
+ update(at.failures)
0
+ end
0
+
0
+ Autotest.add_hook :green do |at|
0
+ STATUS[Time.now] = 0
0
+ update
0
+ end
0
+ end
0
+end

Comments

    No one has commented yet.