Class: Sus::Config
- Inherits:
-
Object
- Object
- Sus::Config
- Defined in:
- lib/sus/config.rb
Overview
Represents the configuration for running tests.
Constant Summary collapse
- PATH =
The default path to the configuration file.
"config/sus.rb"- DEFAULT_TEST_PATTERN =
The default pattern for finding test files.
"test/**/*.rb"
Instance Attribute Summary collapse
- #Optional paths to specific test files.(pathstospecifictestfiles.) ⇒ Object readonly
-
#paths ⇒ Object
readonly
Returns the value of attribute paths.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
- #The root directory for the project.(rootdirectory) ⇒ Object readonly
Class Method Summary collapse
-
.load(root: Dir.pwd, arguments: ARGV) ⇒ Object
Load configuration from the given root directory.
-
.path(root) ⇒ Object
Find the configuration file path for the given root directory.
Instance Method Summary collapse
-
#add_default_load_paths ⇒ Object
Add default load paths (lib and fixtures).
-
#add_load_path(path) ⇒ Object
Add a directory to the load path.
-
#after_tests(assertions, output: self.output) ⇒ Object
Called after tests are run.
-
#before_tests(assertions, output: self.output) ⇒ Object
Called before tests are run.
-
#initialize(root, paths, verbose: false) ⇒ Config
constructor
Initialize a new Config instance.
-
#load_registry(paths = @paths) ⇒ Object
Load the test registry, optionally filtering by paths.
-
#make_registry ⇒ Object
Create a new registry instance.
- #output ⇒ Object
- #partial? ⇒ Boolean
-
#prepare_warnings! ⇒ Object
Prepare Ruby warnings for deprecated features.
- #registry ⇒ Object
- #test_paths ⇒ Object
- #verbose? ⇒ Boolean
Constructor Details
Instance Attribute Details
#Optional paths to specific test files.(pathstospecifictestfiles.) ⇒ Object (readonly)
81 |
# File 'lib/sus/config.rb', line 81 attr :paths |
#paths ⇒ Object (readonly)
Returns the value of attribute paths.
81 82 83 |
# File 'lib/sus/config.rb', line 81 def paths @paths end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
78 79 80 |
# File 'lib/sus/config.rb', line 78 def root @root end |
#The root directory for the project.(rootdirectory) ⇒ Object (readonly)
78 |
# File 'lib/sus/config.rb', line 78 attr :root |
Class Method Details
.load(root: Dir.pwd, arguments: ARGV) ⇒ Object
Load configuration from the given root directory.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/sus/config.rb', line 31 def self.load(root: Dir.pwd, arguments: ARGV) derived = Class.new(self) if path = self.path(root) config = Module.new config.module_eval(::File.read(path), path) derived.prepend(config) end = { verbose: !!arguments.delete("--verbose") } return derived.new(root, arguments, **) end |
Instance Method Details
#add_default_load_paths ⇒ Object
Add default load paths (lib and fixtures).
72 73 74 75 |
# File 'lib/sus/config.rb', line 72 def add_default_load_paths add_load_path("lib") add_load_path("fixtures") end |
#add_load_path(path) ⇒ Object
Add a directory to the load path.
63 64 65 66 67 68 69 |
# File 'lib/sus/config.rb', line 63 def add_load_path(path) path = ::File.(path, @root) if ::File.directory?(path) $LOAD_PATH.unshift(path) end end |
#after_tests(assertions, output: self.output) ⇒ Object
Called after tests are run.
155 156 157 158 159 |
# File 'lib/sus/config.rb', line 155 def after_tests(assertions, output: self.output) @clock.stop! self.print_summary(output, assertions) end |
#before_tests(assertions, output: self.output) ⇒ Object
Called before tests are run.
145 146 147 148 149 150 |
# File 'lib/sus/config.rb', line 145 def before_tests(assertions, output: self.output) @clock.reset! @clock.start! prepare_warnings! end |
#load_registry(paths = @paths) ⇒ Object
Load the test registry, optionally filtering by paths.
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/sus/config.rb', line 115 def load_registry(paths = @paths) registry = make_registry if paths&.any? registry = Sus::Filter.new(registry) paths.each do |path| registry.load(path) end else test_paths.each do |path| registry.load(path) end end return registry end |
#make_registry ⇒ Object
Create a new registry instance.
108 109 110 |
# File 'lib/sus/config.rb', line 108 def make_registry Sus::Registry.new(root: @root) end |
#output ⇒ Object
94 95 96 |
# File 'lib/sus/config.rb', line 94 def output @output ||= Sus::Output.default end |
#partial? ⇒ Boolean
89 90 91 |
# File 'lib/sus/config.rb', line 89 def partial? @paths.any? end |
#prepare_warnings! ⇒ Object
Prepare Ruby warnings for deprecated features.
138 139 140 |
# File 'lib/sus/config.rb', line 138 def prepare_warnings! Warning[:deprecated] = true end |
#registry ⇒ Object
133 134 135 |
# File 'lib/sus/config.rb', line 133 def registry @registry ||= self.load_registry end |
#test_paths ⇒ Object
102 103 104 |
# File 'lib/sus/config.rb', line 102 def test_paths return Dir.glob(DEFAULT_TEST_PATTERN, base: @root) end |
#verbose? ⇒ Boolean
84 85 86 |
# File 'lib/sus/config.rb', line 84 def verbose? @verbose end |