|
0 |
require 'autotest'
|
|
1 |
|
|
2 |
Autotest.add_hook :initialize do |at|
|
|
3 |
at.clear_mappings
|
|
4 |
# watch out: Ruby bug (1.8.6):
|
|
5 |
# %r(/) != /\//
|
|
6 |
at.add_mapping(%r%^spec/.*\.rb$%) { |filename, _|
|
|
7 |
filename
|
|
8 |
}
|
|
9 |
at.add_mapping(%r%^lib/(.*)\.rb$%) { |_, m|
|
|
10 |
["spec/#{m[1]}_spec.rb"]
|
|
11 |
}
|
|
12 |
at.add_mapping(%r%^spec/(spec_helper|shared/.*)\.rb$%) {
|
|
13 |
at.files_matching %r{^spec/.*_spec\.rb$}
|
|
14 |
}
|
|
15 |
end
|
|
16 |
|
|
17 |
class RspecCommandError < StandardError; end
|
|
18 |
|
|
19 |
class Autotest::Rspec < Autotest
|
|
20 |
|
|
21 |
def initialize
|
|
22 |
super
|
|
23 |
|
|
24 |
self.failed_results_re = /^\d+\)\n(?:\e\[\d*m)?(?:.*?Error in )?'([^\n]*)'(?: FAILED)?(?:\e\[\d*m)?\n(.*?)\n\n/m
|
|
25 |
self.completed_re = /\Z/ # FIX: some sort of summary line at the end?
|
|
26 |
end
|
|
27 |
|
|
28 |
def consolidate_failures(failed)
|
|
29 |
filters = Hash.new { |h,k| h[k] = [] }
|
|
30 |
failed.each do |spec, failed_trace|
|
|
31 |
if f = test_files_for(failed).find { |f| failed_trace =~ Regexp.new(f) } then
|
|
32 |
filters[f] << spec
|
|
33 |
break
|
|
34 |
end
|
|
35 |
end
|
|
36 |
return filters
|
|
37 |
end
|
|
38 |
|
|
39 |
def make_test_cmd(files_to_test)
|
|
40 |
return "#{ruby} -S #{spec_command} #{add_options_if_present} #{files_to_test.keys.flatten.join(' ')}"
|
|
41 |
end
|
|
42 |
|
|
43 |
def add_options_if_present
|
|
44 |
File.exist?("spec/spec.opts") ? "-O spec/spec.opts " : ""
|
|
45 |
end
|
|
46 |
|
|
47 |
# Finds the proper spec command to use. Precendence is set in the
|
|
48 |
# lazily-evaluated method spec_commands. Alias + Override that in
|
|
49 |
# ~/.autotest to provide a different spec command then the default
|
|
50 |
# paths provided.
|
|
51 |
def spec_command(separator=File::ALT_SEPARATOR)
|
|
52 |
unless defined? @spec_command then
|
|
53 |
@spec_command = spec_commands.find { |cmd| File.exists? cmd }
|
|
54 |
|
|
55 |
raise RspecCommandError, "No spec command could be found!" unless @spec_command
|
|
56 |
|
|
57 |
@spec_command.gsub! File::SEPARATOR, separator if separator
|
|
58 |
end
|
|
59 |
@spec_command
|
|
60 |
end
|
|
61 |
|
|
62 |
# Autotest will look for spec commands in the following
|
|
63 |
# locations, in this order:
|
|
64 |
#
|
|
65 |
# * bin/spec
|
|
66 |
# * default spec bin/loader installed in Rubygems
|
|
67 |
def spec_commands
|
|
68 |
[
|
|
69 |
File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'bin', 'spec')),
|
|
70 |
File.join(Config::CONFIG['bindir'], 'spec')
|
|
71 |
]
|
|
72 |
end
|
|
73 |
end
|