summaryrefslogtreecommitdiffstats
path: root/test/lib/spec/runner/command_line.rb
diff options
context:
space:
mode:
authorluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2007-03-17 02:48:41 +0000
committerluke <luke@980ebf18-57e1-0310-9a29-db15c13687c0>2007-03-17 02:48:41 +0000
commitba23a5ac276e59fdda8186750c6d0fd2cfecdeac (patch)
tree1e14b25ade74ea52d8da2788ede9b12b507867e8 /test/lib/spec/runner/command_line.rb
parent8ea6adaeb1e3d0aa6348c2a2c3a385d185372d06 (diff)
Adding spec libs, so we can use them some day
git-svn-id: https://reductivelabs.com/svn/puppet/trunk@2283 980ebf18-57e1-0310-9a29-db15c13687c0
Diffstat (limited to 'test/lib/spec/runner/command_line.rb')
-rw-r--r--test/lib/spec/runner/command_line.rb34
1 files changed, 34 insertions, 0 deletions
diff --git a/test/lib/spec/runner/command_line.rb b/test/lib/spec/runner/command_line.rb
new file mode 100644
index 000000000..db928ad9b
--- /dev/null
+++ b/test/lib/spec/runner/command_line.rb
@@ -0,0 +1,34 @@
+require 'spec/runner/option_parser'
+
+module Spec
+ module Runner
+ # Facade to run specs without having to fork a new ruby process (using `spec ...`)
+ class CommandLine
+ # Runs specs. +argv+ is the commandline args as per the spec commandline API, +err+
+ # and +out+ are the streams output will be written to. +exit+ tells whether or
+ # not a system exit should be called after the specs are run and
+ # +warn_if_no_files+ tells whether or not a warning (the help message)
+ # should be printed to +err+ in case no files are specified.
+ def self.run(argv, err, out, exit=true, warn_if_no_files=true)
+ old_context_runner = defined?($context_runner) ? $context_runner : nil
+ $context_runner = OptionParser.new.create_context_runner(argv, err, out, warn_if_no_files)
+ return if $context_runner.nil? # This is the case if we use --drb
+
+ # If ARGV is a glob, it will actually each over each one of the matching files.
+ argv.each do |file_or_dir|
+ if File.directory?(file_or_dir)
+ Dir["#{file_or_dir}/**/*.rb"].each do |file|
+ load file
+ end
+ elsif File.file?(file_or_dir)
+ load file_or_dir
+ else
+ raise "File or directory not found: #{file_or_dir}"
+ end
+ end
+ $context_runner.run(exit)
+ $context_runner = old_context_runner
+ end
+ end
+ end
+end \ No newline at end of file