summaryrefslogtreecommitdiffstats
path: root/autotest
diff options
context:
space:
mode:
authorLuke Kanies <luke@madstop.com>2008-05-13 20:49:04 -0500
committerLuke Kanies <luke@madstop.com>2008-05-13 20:49:04 -0500
commit4f39ec8dd205ecf0a3ad90c950c86046da3f454e (patch)
treed905a41889b33a3dd47a5a82a0f9cd4f84f62481 /autotest
parentfef9b7d958f1ac6cba80a5ae97e6c96703e15595 (diff)
downloadfacter-4f39ec8dd205ecf0a3ad90c950c86046da3f454e.tar.gz
facter-4f39ec8dd205ecf0a3ad90c950c86046da3f454e.tar.xz
facter-4f39ec8dd205ecf0a3ad90c950c86046da3f454e.zip
Adding autotest hooks
Diffstat (limited to 'autotest')
-rw-r--r--autotest/discover.rb9
-rw-r--r--autotest/facter_rspec.rb55
-rw-r--r--autotest/rspec.rb74
3 files changed, 138 insertions, 0 deletions
diff --git a/autotest/discover.rb b/autotest/discover.rb
new file mode 100644
index 0000000..7cf0916
--- /dev/null
+++ b/autotest/discover.rb
@@ -0,0 +1,9 @@
+require 'autotest'
+
+Autotest.add_discovery do
+ "rspec"
+end
+
+Autotest.add_discovery do
+ "facter"
+end
diff --git a/autotest/facter_rspec.rb b/autotest/facter_rspec.rb
new file mode 100644
index 0000000..bd057a8
--- /dev/null
+++ b/autotest/facter_rspec.rb
@@ -0,0 +1,55 @@
+require 'autotest'
+require 'autotest/rspec'
+
+Autotest.add_hook :initialize do |at|
+ at.clear_mappings
+
+ # the libraries under lib/facter
+ at.add_mapping(%r%^lib/facter/(.*)\.rb$%) { |filename, m|
+ at.files_matching %r!spec/(unit|integration)/#{m[1]}.rb!
+ }
+
+ # the actual spec files themselves
+ at.add_mapping(%r%^spec/(unit|integration)/.*\.rb$%) { |filename, _|
+ filename
+ }
+
+ # force a complete re-run for all of these:
+
+ # main facter lib
+ at.add_mapping(%r!^lib/facter\.rb$!) { |filename, _|
+ at.files_matching %r!spec/(unit|integration)/.*\.rb!
+ }
+
+ # the spec_helper
+ at.add_mapping(%r!^spec/spec_helper\.rb$!) { |filename, _|
+ at.files_matching %r!spec/(unit|integration)/.*\.rb!
+ }
+
+ # the facter spec libraries
+ at.add_mapping(%r!^spec/lib/spec.*!) { |filename, _|
+ at.files_matching %r!spec/(unit|integration)/.*\.rb!
+ }
+
+ # the monkey patches for rspec
+ at.add_mapping(%r!^spec/lib/monkey_patches/.*!) { |filename, _|
+ at.files_matching %r!spec/(unit|integration)/.*\.rb!
+ }
+end
+
+class Autotest::FacterRspec < Autotest::Rspec
+ # Autotest will look for spec commands in the following
+ # locations, in this order:
+ #
+ # * bin/spec
+ # * default spec bin/loader installed in Rubygems
+ # * our local vendor/gems/rspec/bin/spec
+ def spec_commands
+ [
+ File.join('vendor', 'gems', 'rspec', 'bin', 'spec') ,
+ File.join('bin', 'spec'),
+ File.join(Config::CONFIG['bindir'], 'spec')
+ ]
+ end
+
+end
diff --git a/autotest/rspec.rb b/autotest/rspec.rb
new file mode 100644
index 0000000..ebafbfe
--- /dev/null
+++ b/autotest/rspec.rb
@@ -0,0 +1,74 @@
+require 'autotest'
+
+Autotest.add_hook :initialize do |at|
+ at.clear_mappings
+ # watch out: Ruby bug (1.8.6):
+ # %r(/) != /\//
+ at.add_mapping(%r%^spec/.*\.rb$%) { |filename, _|
+ filename
+ }
+ at.add_mapping(%r%^lib/(.*)\.rb$%) { |_, m|
+ ["spec/#{m[1]}_spec.rb"]
+ }
+ at.add_mapping(%r%^spec/(spec_helper|shared/.*)\.rb$%) {
+ at.files_matching %r{^spec/.*_spec\.rb$}
+ }
+end
+
+class RspecCommandError < StandardError; end
+
+class Autotest::Rspec < Autotest
+
+ def initialize
+ super
+
+ self.failed_results_re = /^\d+\)\n(?:\e\[\d*m)?(?:.*?Error in )?'([^\n]*)'(?: FAILED)?(?:\e\[\d*m)?\n(.*?)\n\n/m
+ self.completed_re = /\Z/ # FIX: some sort of summary line at the end?
+ end
+
+ def consolidate_failures(failed)
+ filters = Hash.new { |h,k| h[k] = [] }
+ failed.each do |spec, failed_trace|
+ if f = test_files_for(failed).find { |f| failed_trace =~ Regexp.new(f) } then
+ filters[f] << spec
+ break
+ end
+ end
+ return filters
+ end
+
+ def make_test_cmd(files_to_test)
+ return "#{ruby} -S #{spec_command} #{add_options_if_present} #{files_to_test.keys.flatten.join(' ')}"
+ end
+
+ def add_options_if_present
+ File.exist?("spec/spec.opts") ? "-O spec/spec.opts " : ""
+ end
+
+ # Finds the proper spec command to use. Precendence is set in the
+ # lazily-evaluated method spec_commands. Alias + Override that in
+ # ~/.autotest to provide a different spec command then the default
+ # paths provided.
+ def spec_command(separator=File::ALT_SEPARATOR)
+ unless defined? @spec_command then
+ @spec_command = spec_commands.find { |cmd| File.exists? cmd }
+
+ raise RspecCommandError, "No spec command could be found!" unless @spec_command
+
+ @spec_command.gsub! File::SEPARATOR, separator if separator
+ end
+ @spec_command
+ end
+
+ # Autotest will look for spec commands in the following
+ # locations, in this order:
+ #
+ # * bin/spec
+ # * default spec bin/loader installed in Rubygems
+ def spec_commands
+ [
+ File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'bin', 'spec')),
+ File.join(Config::CONFIG['bindir'], 'spec')
+ ]
+ end
+end