Codebase list facter / 4f39ec8
Adding autotest hooks Luke Kanies 16 years ago
3 changed file(s) with 138 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 require 'autotest'
1
2 Autotest.add_discovery do
3 "rspec"
4 end
5
6 Autotest.add_discovery do
7 "facter"
8 end
0 require 'autotest'
1 require 'autotest/rspec'
2
3 Autotest.add_hook :initialize do |at|
4 at.clear_mappings
5
6 # the libraries under lib/facter
7 at.add_mapping(%r%^lib/facter/(.*)\.rb$%) { |filename, m|
8 at.files_matching %r!spec/(unit|integration)/#{m[1]}.rb!
9 }
10
11 # the actual spec files themselves
12 at.add_mapping(%r%^spec/(unit|integration)/.*\.rb$%) { |filename, _|
13 filename
14 }
15
16 # force a complete re-run for all of these:
17
18 # main facter lib
19 at.add_mapping(%r!^lib/facter\.rb$!) { |filename, _|
20 at.files_matching %r!spec/(unit|integration)/.*\.rb!
21 }
22
23 # the spec_helper
24 at.add_mapping(%r!^spec/spec_helper\.rb$!) { |filename, _|
25 at.files_matching %r!spec/(unit|integration)/.*\.rb!
26 }
27
28 # the facter spec libraries
29 at.add_mapping(%r!^spec/lib/spec.*!) { |filename, _|
30 at.files_matching %r!spec/(unit|integration)/.*\.rb!
31 }
32
33 # the monkey patches for rspec
34 at.add_mapping(%r!^spec/lib/monkey_patches/.*!) { |filename, _|
35 at.files_matching %r!spec/(unit|integration)/.*\.rb!
36 }
37 end
38
39 class Autotest::FacterRspec < Autotest::Rspec
40 # Autotest will look for spec commands in the following
41 # locations, in this order:
42 #
43 # * bin/spec
44 # * default spec bin/loader installed in Rubygems
45 # * our local vendor/gems/rspec/bin/spec
46 def spec_commands
47 [
48 File.join('vendor', 'gems', 'rspec', 'bin', 'spec') ,
49 File.join('bin', 'spec'),
50 File.join(Config::CONFIG['bindir'], 'spec')
51 ]
52 end
53
54 end
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