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)
80 |
# File 'lib/sus/config.rb', line 80 attr :paths |
#paths ⇒ Object (readonly)
Returns the value of attribute paths.
80 81 82 |
# File 'lib/sus/config.rb', line 80 def paths @paths end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
77 78 79 |
# File 'lib/sus/config.rb', line 77 def root @root end |
#The root directory for the project.(rootdirectory) ⇒ Object (readonly)
77 |
# File 'lib/sus/config.rb', line 77 attr :root |
Class Method Details
.load(root: Dir.pwd, arguments: ARGV) ⇒ Object
Load configuration from the given root directory.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/sus/config.rb', line 30 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).
71 72 73 74 |
# File 'lib/sus/config.rb', line 71 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.
62 63 64 65 66 67 68 |
# File 'lib/sus/config.rb', line 62 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.
154 155 156 157 158 |
# File 'lib/sus/config.rb', line 154 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.
144 145 146 147 148 149 |
# File 'lib/sus/config.rb', line 144 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.
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/sus/config.rb', line 114 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.
107 108 109 |
# File 'lib/sus/config.rb', line 107 def make_registry Sus::Registry.new(root: @root) end |
#output ⇒ Object
93 94 95 |
# File 'lib/sus/config.rb', line 93 def output @output ||= Sus::Output.default end |
#partial? ⇒ Boolean
88 89 90 |
# File 'lib/sus/config.rb', line 88 def partial? @paths.any? end |
#prepare_warnings! ⇒ Object
Prepare Ruby warnings for deprecated features.
137 138 139 |
# File 'lib/sus/config.rb', line 137 def prepare_warnings! Warning[:deprecated] = true end |
#registry ⇒ Object
132 133 134 |
# File 'lib/sus/config.rb', line 132 def registry @registry ||= self.load_registry end |
#test_paths ⇒ Object
101 102 103 |
# File 'lib/sus/config.rb', line 101 def test_paths return Dir.glob(DEFAULT_TEST_PATTERN, base: @root) end |
#verbose? ⇒ Boolean
83 84 85 |
# File 'lib/sus/config.rb', line 83 def verbose? @verbose end |