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/}'
Class Method Summary collapse
- .assertionless ⇒ Object
- .assertionless=(boolean) ⇒ Object
-
.dotindex ⇒ Hash
Load and cache a project’s
.indexfile, if it has one. -
.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
-
#after(&proc) ⇒ Proc?
Procedure to call, just after running tests.
-
#apply(hash = {}, &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`?.
-
#before(&proc) ⇒ Proc?
Procedure to call, just before running tests.
-
#chdir(dir = nil) ⇒ String
Change to this directory before running tests.
-
#chdir=(dir) ⇒ String
Set directory to change to before running tests.
-
#files(*list) ⇒ 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(name = nil) ⇒ String
Name of test report format, by default it is
dotprogress. -
#format=(name) ⇒ 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 for project.
-
#loadpath(*list) ⇒ Array<String>
(also: #load_path)
Paths to add to $LOAD_PATH.
-
#loadpath=(list) ⇒ Array<String>
(also: #load_path=)
Set paths to add to $LOAD_PATH.
-
#match(*list) ⇒ 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.
-
#requires(*list) ⇒ Array<String>
Scripts to require prior to tests.
-
#requires=(list) ⇒ Array<String>
Set the features that need to be required before the test files.
-
#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(*list) ⇒ 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(*list) ⇒ 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.
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/rubytest/config.rb', line 106 def initialize(settings={}, &block) @format = nil @autopath = nil @chdir = nil @files = [] @tags = [] @match = [] @units = [] @requires = [] @loadpath = [] #apply_environment apply(settings, &block) end |
Class Method Details
.assertionless ⇒ Object
48 49 50 |
# File 'lib/rubytest/config.rb', line 48 def self.assertionless @assertionless end |
.assertionless=(boolean) ⇒ Object
53 54 55 |
# File 'lib/rubytest/config.rb', line 53 def self.assertionless=(boolean) @assertionaless = !!boolean end |
.dotindex ⇒ Hash
Load and cache a project’s .index file, if it has one.
77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/rubytest/config.rb', line 77 def self.dotindex @dotindex ||= ( file = File.join(root, '.index') if File.exist?(file) require 'yaml' YAML.load_file(file) rescue {} else {} 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.
92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/rubytest/config.rb', line 92 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.
60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/rubytest/config.rb', line 60 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
#after(&proc) ⇒ Proc?
Procedure to call, just after running tests.
328 329 330 331 |
# File 'lib/rubytest/config.rb', line 328 def after(&proc) @after = proc if proc @after end |
#apply(hash = {}, &block) ⇒ Object
Evaluate configuration block.
125 126 127 128 129 130 |
# File 'lib/rubytest/config.rb', line 125 def apply(hash={}, &block) hash.each do |k,v| send("#{k}=", v) end block.call(self) if block end |
#apply_environment_defaults ⇒ Object
Apply environment as underlying defaults for unset configuration settings.
389 390 391 392 393 394 395 396 397 398 |
# File 'lib/rubytest/config.rb', line 389 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? @tags = env(:tags, @tags) if @tags.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.
374 375 376 377 378 379 380 381 382 383 |
# File 'lib/rubytest/config.rb', line 374 def apply_environment_overrides @format = env(:format, @format) @autopath = env(:autopath, @autopath) @files = env(:files, @files) @match = env(:match, @match) @tags = env(:tags, @tags) @units = env(:units, @units) @requires = env(:requires, @requires) @loadpath = env(:loadpath, @loadpath) end |
#autopath=(boolean) ⇒ Boolean
Automatically modify the ‘$LOAD_PATH`?
172 173 174 |
# File 'lib/rubytest/config.rb', line 172 def autopath=(boolean) @autopath = !! boolean end |
#autopath? ⇒ Boolean
Automatically modify the ‘$LOAD_PATH`?
165 166 167 |
# File 'lib/rubytest/config.rb', line 165 def autopath? @autopath end |
#before(&proc) ⇒ Proc?
Procedure to call, just before running tests.
320 321 322 323 |
# File 'lib/rubytest/config.rb', line 320 def before(&proc) @before = proc if proc @before end |
#chdir(dir = nil) ⇒ String
Change to this directory before running tests.
305 306 307 308 |
# File 'lib/rubytest/config.rb', line 305 def chdir(dir=nil) @chdir = dir.to_s if dir @chdir end |
#chdir=(dir) ⇒ String
Set directory to change to before running tests.
313 314 315 |
# File 'lib/rubytest/config.rb', line 313 def chdir=(dir) @chdir = dir.to_s end |
#files(*list) ⇒ Array<String> Also known as: test_files
List of test files to run.
148 149 150 151 |
# File 'lib/rubytest/config.rb', line 148 def files(*list) @files.concat(makelist(list)) unless list.empty? @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.
157 158 159 |
# File 'lib/rubytest/config.rb', line 157 def files=(list) @files = makelist(list) end |
#format(name = nil) ⇒ String
Name of test report format, by default it is dotprogress.
212 213 214 215 |
# File 'lib/rubytest/config.rb', line 212 def format(name=nil) @format = name.to_s if name @format || DEFAULT_FORMAT end |
#format=(name) ⇒ String
Set test report format.
223 224 225 |
# File 'lib/rubytest/config.rb', line 223 def format=(name) @format = name.to_s end |
#hard=(boolean) ⇒ Boolean
Hard is a synonym for assertionless.
298 299 300 |
# File 'lib/rubytest/config.rb', line 298 def hard=(boolean) @hard = !! boolean end |
#hard? ⇒ Boolean
Hard is a synonym for assertionless.
291 292 293 |
# File 'lib/rubytest/config.rb', line 291 def hard? @hard || self.class.assertionless end |
#load_config(file) ⇒ Boolean
Load configuration file for project.
File names are prefixed with ./ to ensure they are from a local source. An extension of .rb is assumed if the file lacks an one.
406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 |
# File 'lib/rubytest/config.rb', line 406 def load_config(file) file = file + '.rb' if File.extname(file) == '' if chdir file = File.join(chdir, file) else file = File.join('.', file) end if File.exist?(file) return require(file) else raise "config file not found -- `#{file}'" end end |
#loadpath(*list) ⇒ Array<String> Also known as: load_path
Paths to add to $LOAD_PATH.
179 180 181 182 |
# File 'lib/rubytest/config.rb', line 179 def loadpath(*list) @loadpath.concat(makelist(list)) unless list.empty? @loadpath end |
#loadpath=(list) ⇒ Array<String> Also known as: load_path=
Set paths to add to $LOAD_PATH.
188 189 190 |
# File 'lib/rubytest/config.rb', line 188 def loadpath=(list) @loadpath = makelist(list) end |
#match(*list) ⇒ Array<String>
Description match for filtering tests.
259 260 261 262 |
# File 'lib/rubytest/config.rb', line 259 def match(*list) @match.concat(makelist(list)) unless list.empty? @match end |
#match=(list) ⇒ Array<String>
Set the description matches for filtering tests.
267 268 269 |
# File 'lib/rubytest/config.rb', line 267 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.
338 339 340 |
# File 'lib/rubytest/config.rb', line 338 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.
347 348 349 |
# File 'lib/rubytest/config.rb', line 347 def mode=(type) @mode = type.to_s end |
#requires(*list) ⇒ Array<String>
Scripts to require prior to tests.
196 197 198 199 |
# File 'lib/rubytest/config.rb', line 196 def requires(*list) @requires.concat(makelist(list)) unless list.empty? @requires end |
#requires=(list) ⇒ Array<String>
Set the features that need to be required before the test files.
205 206 207 |
# File 'lib/rubytest/config.rb', line 205 def requires=(list) @requires = makelist(list) end |
#suite ⇒ Array
Default test suite ($TEST_SUITE).
135 136 137 |
# File 'lib/rubytest/config.rb', line 135 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.
141 142 143 |
# File 'lib/rubytest/config.rb', line 141 def suite=(test_objects) @suite = Array(test_objects) end |
#tags(*list) ⇒ Array<String>
Selection of tags for filtering tests.
244 245 246 247 |
# File 'lib/rubytest/config.rb', line 244 def (*list) @tags.concat(makelist(list)) unless list.empty? @tags end |
#tags=(list) ⇒ Array<String>
Set the list of tags for filtering tests.
252 253 254 |
# File 'lib/rubytest/config.rb', line 252 def (list) @tags = makelist(list) end |
#to_shellwords ⇒ Array<String>
Convert configuration to shell options, compatible with the rubytest command line.
355 356 357 358 359 360 361 362 363 364 365 366 367 368 |
# File 'lib/rubytest/config.rb', line 355 def to_shellwords argv = [] argv << %[--autopath] if autopath? argv << %[--verbose] if verbose? argv << %[--format="#{format}"] if format argv << %[--chdir="#{chdir}"] if chdir argv << %[--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(*list) ⇒ 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.
275 276 277 278 |
# File 'lib/rubytest/config.rb', line 275 def units(*list) @units.concat(makelist(list)) unless list.empty? @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.
284 285 286 |
# File 'lib/rubytest/config.rb', line 284 def units=(list) @units = makelist(list) end |
#verbose=(boolean) ⇒ Boolean
Set verbose mode.
237 238 239 |
# File 'lib/rubytest/config.rb', line 237 def verbose=(boolean) @verbose = !! boolean end |
#verbose? ⇒ Boolean
Provide extra details in reports?
230 231 232 |
# File 'lib/rubytest/config.rb', line 230 def verbose? @verbose end |