11module Test
22
3- # TODO: Support config profile's again?
4-
53 # Alias for `Test.configure`.
64 # Use #run! to run tests immediately.
75 #
8- def self . run ( config = nil , &config_proc )
9- $stderr. puts "configuration profiles no longer supported." if config
10- configure ( &config_proc )
6+ def self . run ( profile = nil , &config_proc )
7+ configure ( profile , &config_proc )
118 end
129
1310 # Configure and run immediately.
1411 #
12+ # @todo Should this method return the success instead of exiting?
13+ # @todo Wrap run in at_exit ?
14+ #
15+ # @return [void]
1516 def run! ( config = nil , &config_proc )
16- Runner . run ( config , &config_proc )
17+ begin
18+ success = Runner . run ( config , &config_proc )
19+ exit -1 unless success
20+ rescue => error
21+ raise error if $DEBUG
22+ $stderr. puts ( 'ERROR: ' + error . to_s )
23+ exit -1
24+ end
1725 end
1826
1927 # The Test::Runner class handles the execution of tests.
2028 #
2129 class Runner
2230
23- # TODO: Wrap run in at_exit ?
24- def self . run ( config = nil , &config_proc )
25- runner = Runner . new ( config , &config_proc )
26- begin
27- success = runner . run
28- exit -1 unless success
29- rescue => error
30- raise error if $DEBUG
31- $stderr. puts ( 'ERROR: ' + error . to_s )
32- exit -1
31+ # Run tests.
32+ #
33+ # @param [Config,Hash,String,Symbol] config
34+ # Either a Config instance, a hash to construct a Config
35+ # instance with, or a name of a configuration profile.
36+ #
37+ # @return [Boolean] Success of test run.
38+ def self . run ( config = nil ) #:yield:
39+ case config
40+ when Config
41+ when Hash
42+ config = Config . new ( config )
43+ else
44+ config = Test . configuration ( config )
3345 end
46+
47+ yeild config if block_given?
48+
49+ runner = Runner . new ( config )
50+ runner . run
3451 end
3552
3653 # Exceptions that are not caught by test runner.
@@ -90,15 +107,7 @@ def upon(type, &block)
90107 # @param [Config] config
91108 # Config instance.
92109 #
93- def initialize ( config = nil , &block )
94- if config
95- @config = Hash === config ? Config . new ( config ) : config
96- else
97- @config = Test . configuration
98- end
99-
100- block . call ( @config ) if block
101-
110+ def initialize ( config )
102111 @advice = Advice . new
103112 end
104113
@@ -123,15 +132,17 @@ def run
123132
124133 ignore_callers
125134
126- config . loadpath . each { |path | $LOAD_PATH. unshift ( path ) }
127- config . requires . each { |file | require file }
135+ config . loadpath . flatten . each { |path | $LOAD_PATH. unshift ( path ) }
136+ config . requires . flatten . each { |file | require file }
137+
138+ # Config before advice occurs after loadpath and require are
139+ # applied and before test files are required.
140+ config . before . call if config . before
128141
129142 test_files . each do |test_file |
130143 require test_file
131144 end
132145
133- config . before . call if config . before
134-
135146 @reporter = reporter_load ( format )
136147 @recorder = Recorder . new
137148
0 commit comments