Class: Test::Config
- Inherits:
-
Object
- Object
- Test::Config
- Defined in:
- lib/rubytest/config.rb
Overview
Encapsulates test run configruation.
Constant Summary collapse
- DEFAULT_FORMAT =
Default report is in the old “dot-progress” format.
'dotprogress'- GLOB_ROOT =
Glob used to find project root directory.
'{.index,.gemspec,.git,.hg,_darcs,lib/}'- GLOB_CONFIG =
Deprecated.
Use manual -c/–config option instead.
RubyTest configuration file can be in ‘.test.rb`,
etc/test.rborconfig/test.rb,.test, in that order of precedence. '{.test.rb,etc/test.rb,config/test.rb,.test}'
Instance Attribute Summary collapse
-
#loadpath ⇒ Array<String>
Paths to add to $LOAD_PATH.
-
#requires ⇒ Array<String>
Scripts to require prior to tests.
Class Method Summary collapse
- .assertionless ⇒ Object
- .assertionless=(boolean) ⇒ Object
- .config_file ⇒ Object deprecated Deprecated.
-
.dotindex ⇒ Hash
Load and cache a project’s
.indexfile, if it has one. -
.load_config ⇒ Object
deprecated
Deprecated.
Planned for deprecation in April 2013.
-
.load_path_setup ⇒ Object
Setup $LOAD_PATH based on project’s
.indexfile, if an index file is not found, then default tolib/if it exists. -
.root ⇒ String
Find and cache project root directory.
Instance Method Summary collapse
-
#apply(&block) ⇒ Object
Evaluate configuration block.
-
#apply_environment_defaults ⇒ Object
Apply environment as underlying defaults for unset configuration settings.
-
#apply_environment_overrides ⇒ Object
Apply environment, overriding any previous configuration settings.
-
#autopath=(boolean) ⇒ Boolean
Automatically modify the ‘$LOAD_PATH`?.
-
#autopath? ⇒ Boolean
Automatically modify the ‘$LOAD_PATH`?.
-
#chdir ⇒ String
Change to this directory before running tests.
-
#chdir=(dir) ⇒ String
Set directory to change to before running tests.
-
#files ⇒ Array<String>
(also: #test_files)
List of test files to run.
-
#files=(list) ⇒ Array<String>
(also: #test_files=)
Set the list of test files to run.
-
#format ⇒ String
Name of test report format, by default it is
dotprogress. -
#format=(format) ⇒ String
Set test report format.
-
#hard=(boolean) ⇒ Boolean
Hard is a synonym for assertionless.
-
#hard? ⇒ Boolean
Hard is a synonym for assertionless.
-
#initialize(settings = {}, &block) ⇒ Config
constructor
Initialize new Config instance.
-
#load_config(file) ⇒ Boolean
Load configuration file.
-
#match ⇒ Array<String>
Description match for filtering tests.
-
#match=(list) ⇒ Array<String>
Set the description matches for filtering tests.
-
#mode ⇒ String
The mode is only useful for specialied purposes, such as how to run tests via the Rake task.
-
#mode=(type) ⇒ String
The mode is only useful for specialied purposes, such as how to run tests via the Rake task.
-
#suite ⇒ Array
Default test suite ($TEST_SUITE).
-
#suite=(test_objects) ⇒ Object
This is not really for general, but it is useful for Ruby Test’s own tests, to isolate tests.
-
#tags ⇒ Array<String>
Selection of tags for filtering tests.
-
#tags=(list) ⇒ Array<String>
Set the list of tags for filtering tests.
-
#to_shellwords ⇒ Array<String>
Convert configuration to shell options, compatible with the rubytest command line.
-
#units ⇒ Array<String>
List of units with which to filter tests.
-
#units=(list) ⇒ Array<String>
Set the list of units with which to filter tests.
-
#verbose=(boolean) ⇒ Boolean
Set verbose mode.
-
#verbose? ⇒ Boolean
Provide extra details in reports?.
Constructor Details
#initialize(settings = {}, &block) ⇒ Config
Initialize new Config instance.
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/rubytest/config.rb', line 129 def initialize(settings={}, &block) @format = nil @autopath = nil @chdir = nil @files = [] = [] @match = [] @units = [] @requires = [] @loadpath = [] #apply_environment settings.each do |k,v| send("#{k}=", v) end self.class.load_config # deprecated!!! apply(&block) end |
Instance Attribute Details
#loadpath ⇒ Array<String>
Paths to add to $LOAD_PATH.
204 205 206 |
# File 'lib/rubytest/config.rb', line 204 def loadpath @loadpath end |
#requires ⇒ Array<String>
Scripts to require prior to tests.
216 217 218 |
# File 'lib/rubytest/config.rb', line 216 def requires @requires end |
Class Method Details
.assertionless ⇒ Object
49 50 51 |
# File 'lib/rubytest/config.rb', line 49 def self.assertionless @assertionless end |
.assertionless=(boolean) ⇒ Object
54 55 56 |
# File 'lib/rubytest/config.rb', line 54 def self.assertionless=(boolean) @assertionaless = !!boolean end |
.config_file ⇒ Object
Find traditional configuration file.
76 77 78 |
# File 'lib/rubytest/config.rb', line 76 def self.config_file @config_file ||= Dir.glob(File.join(root, GLOB_CONFIG)).first end |
.dotindex ⇒ Hash
Load and cache a project’s .index file, if it has one.
100 101 102 103 104 105 106 107 108 109 110 |
# File 'lib/rubytest/config.rb', line 100 def self.dotindex @dotindex ||= ( file = File.join(root, '.index') if File.exist?(file) require 'yaml' YAML.load_file(file) rescue {} else {} end ) end |
.load_config ⇒ Object
Planned for deprecation in April 2013.
Load configuration file. An example file might look like:
Test.configure do |run|
run.files << 'test/case_*.rb'
end
65 66 67 68 69 70 71 |
# File 'lib/rubytest/config.rb', line 65 def self.load_config if config_file file = config_file.sub(Dir.pwd+'/','') $stderr.puts "Automatic #{file} loading has been deprecated.\nUse -c option for future version." load config_file end end |
.load_path_setup ⇒ Object
Setup $LOAD_PATH based on project’s .index file, if an index file is not found, then default to lib/ if it exists.
115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/rubytest/config.rb', line 115 def self.load_path_setup if load_paths = (dotindex['paths'] || {})['lib'] load_paths.each do |path| $LOAD_PATH.unshift(File.join(root, path)) end else typical_load_path = File.join(root, 'lib') if File.directory?(typical_load_path) $LOAD_PATH.unshift(typical_load_path) end end end |
.root ⇒ String
Find and cache project root directory.
83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/rubytest/config.rb', line 83 def self.root @root ||= ( glob = GLOB_ROOT stop = '/' default = Dir.pwd dir = Dir.pwd until dir == stop break dir if Dir[File.join(dir, glob)].first dir = File.dirname(dir) end dir == stop ? default : dir ) end |
Instance Method Details
#apply(&block) ⇒ Object
Evaluate configuration block.
154 155 156 |
# File 'lib/rubytest/config.rb', line 154 def apply(&block) block.call(self) if block end |
#apply_environment_defaults ⇒ Object
Apply environment as underlying defaults for unset configuration settings.
382 383 384 385 386 387 388 389 390 391 |
# File 'lib/rubytest/config.rb', line 382 def apply_environment_defaults @format = env(:format, @format) if @format.nil? @autopath = env(:autopath, @autopath) if @autopath.nil? @files = env(:files, @files) if @files.empty? @match = env(:match, @match) if @match.empty? = env(:tags, ) if .empty? @units = env(:units, @units) if @units.empty? @requires = env(:requires, @requires) if @requires.empty? @loadpath = env(:loadpath, @loadpath) if @loadpath.empty? end |
#apply_environment_overrides ⇒ Object
Better name for this method?
Apply environment, overriding any previous configuration settings.
367 368 369 370 371 372 373 374 375 376 |
# File 'lib/rubytest/config.rb', line 367 def apply_environment_overrides @format = env(:format, @format) @autopath = env(:autopath, @autopath) @files = env(:files, @files) @match = env(:match, @match) = env(:tags, ) @units = env(:units, @units) @requires = env(:requires, @requires) @loadpath = env(:loadpath, @loadpath) end |
#autopath=(boolean) ⇒ Boolean
Automatically modify the ‘$LOAD_PATH`?
197 198 199 |
# File 'lib/rubytest/config.rb', line 197 def autopath=(boolean) @autopath = !! boolean end |
#autopath? ⇒ Boolean
Automatically modify the ‘$LOAD_PATH`?
190 191 192 |
# File 'lib/rubytest/config.rb', line 190 def autopath? @autopath end |
#chdir ⇒ String
Change to this directory before running tests.
315 316 317 |
# File 'lib/rubytest/config.rb', line 315 def chdir @chdir end |
#chdir=(dir) ⇒ String
Set directory to change to before running tests.
322 323 324 |
# File 'lib/rubytest/config.rb', line 322 def chdir=(dir) @chdir = dir.to_s end |
#files ⇒ Array<String> Also known as: test_files
List of test files to run.
174 175 176 |
# File 'lib/rubytest/config.rb', line 174 def files @files end |
#files=(list) ⇒ Array<String> Also known as: test_files=
Set the list of test files to run. Entries can be file glob patterns.
182 183 184 |
# File 'lib/rubytest/config.rb', line 182 def files=(list) @files = makelist(list) end |
#format ⇒ String
Name of test report format, by default it is dotprogress.
229 230 231 |
# File 'lib/rubytest/config.rb', line 229 def format @format || DEFAULT_FORMAT end |
#format=(format) ⇒ String
Set test report format.
236 237 238 |
# File 'lib/rubytest/config.rb', line 236 def format=(format) @format = format.to_s end |
#hard=(boolean) ⇒ Boolean
Hard is a synonym for assertionless.
308 309 310 |
# File 'lib/rubytest/config.rb', line 308 def hard=(boolean) @hard = !! boolean end |
#hard? ⇒ Boolean
Hard is a synonym for assertionless.
301 302 303 |
# File 'lib/rubytest/config.rb', line 301 def hard? @hard || self.class.assertionless end |
#load_config(file) ⇒ Boolean
Load configuration file.
396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 |
# File 'lib/rubytest/config.rb', line 396 def load_config(file) try_paths = ['etc', 'config'] try_paths.concat loadpath try_paths << '.' try_paths = try_paths.uniq if chdir try_paths = try_paths.map{ |path| File.join(chdir, path) } end hold_path = $LOAD_PATH.dup $LOAD_PATH.replace(try_paths) begin success = require file ensure $LOAD_PATH.replace(hold_path) end success end |
#match ⇒ Array<String>
Description match for filtering tests.
271 272 273 |
# File 'lib/rubytest/config.rb', line 271 def match @match end |
#match=(list) ⇒ Array<String>
Set the description matches for filtering tests.
278 279 280 |
# File 'lib/rubytest/config.rb', line 278 def match=(list) @match = makelist(list) end |
#mode ⇒ String
The mode is only useful for specialied purposes, such as how to run tests via the Rake task. It has no general purpose and can be ignored in most cases.
331 332 333 |
# File 'lib/rubytest/config.rb', line 331 def mode @mode end |
#mode=(type) ⇒ String
The mode is only useful for specialied purposes, such as how to run tests via the Rake task. It has no general purpose and can be ignored in most cases.
340 341 342 |
# File 'lib/rubytest/config.rb', line 340 def mode=(type) @mode = type.to_s end |
#suite ⇒ Array
Default test suite ($TEST_SUITE).
161 162 163 |
# File 'lib/rubytest/config.rb', line 161 def suite @suite ||= $TEST_SUITE end |
#suite=(test_objects) ⇒ Object
This is not really for general, but it is useful for Ruby Test’s own tests, to isolate tests.
167 168 169 |
# File 'lib/rubytest/config.rb', line 167 def suite=(test_objects) @suite = Array(test_objects) end |
#tags ⇒ Array<String>
Selection of tags for filtering tests.
257 258 259 |
# File 'lib/rubytest/config.rb', line 257 def end |
#tags=(list) ⇒ Array<String>
Set the list of tags for filtering tests.
264 265 266 |
# File 'lib/rubytest/config.rb', line 264 def (list) = makelist(list) end |
#to_shellwords ⇒ Array<String>
Convert configuration to shell options, compatible with the rubytest command line.
348 349 350 351 352 353 354 355 356 357 358 359 360 361 |
# File 'lib/rubytest/config.rb', line 348 def to_shellwords argv = [] argv << %[--autopath] if autopath? argv << %[--verbose] if verbose? argv << %[--format="#{format}"] if format argv << %[--chdir="#{chdir}"] if chdir argv << %[--tags="#{tags.join(';')}"] unless .empty? argv << %[--match="#{match.join(';')}"] unless match.empty? argv << %[--units="#{units.join(';')}"] unless units.empty? argv << %[--loadpath="#{loadpath.join(';')}"] unless loadpath.empty? argv << %[--requires="#{requires.join(';')}"] unless requires.empty? argv << files.join(' ') unless files.empty? argv end |
#units ⇒ Array<String>
List of units with which to filter tests. It is an array of strings which are matched against module, class and method names.
286 287 288 |
# File 'lib/rubytest/config.rb', line 286 def units @units end |
#units=(list) ⇒ Array<String>
Set the list of units with which to filter tests. It is an array of strings which are matched against module, class and method names.
294 295 296 |
# File 'lib/rubytest/config.rb', line 294 def units=(list) @units = makelist(list) end |
#verbose=(boolean) ⇒ Boolean
Set verbose mode.
250 251 252 |
# File 'lib/rubytest/config.rb', line 250 def verbose=(boolean) @verbose = !! boolean end |
#verbose? ⇒ Boolean
Provide extra details in reports?
243 244 245 |
# File 'lib/rubytest/config.rb', line 243 def verbose? @verbose end |