Class: Sus::Config
- Inherits:
-
Object
- Object
- Sus::Config
- Defined in:
- lib/sus/config.rb
Constant Summary collapse
- PATH =
"config/sus.rb"
- DEFAULT_TEST_PATTERN =
"test/**/*.rb"
Instance Attribute Summary collapse
-
#paths ⇒ Object
readonly
Returns the value of attribute paths.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Class Method Summary collapse
Instance Method Summary collapse
- #add_default_load_paths ⇒ Object
- #add_load_path(path) ⇒ Object
- #after_tests(assertions, output: self.output) ⇒ Object
- #before_tests(assertions, output: self.output) ⇒ Object
-
#initialize(root, paths, verbose: false) ⇒ Config
constructor
A new instance of Config.
- #load_registry(paths = @paths) ⇒ Object
- #make_registry ⇒ Object
- #output ⇒ Object
- #partial? ⇒ Boolean
- #prepare_warnings! ⇒ Object
- #registry ⇒ Object
- #test_paths ⇒ Object
- #verbose? ⇒ Boolean
Constructor Details
Instance Attribute Details
#paths ⇒ Object (readonly)
Returns the value of attribute paths.
61 62 63 |
# File 'lib/sus/config.rb', line 61 def paths @paths end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
60 61 62 |
# File 'lib/sus/config.rb', line 60 def root @root end |
Class Method Details
.load(root: Dir.pwd, arguments: ARGV) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/sus/config.rb', line 21 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
55 56 57 58 |
# File 'lib/sus/config.rb', line 55 def add_default_load_paths add_load_path("lib") add_load_path("fixtures") end |
#add_load_path(path) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/sus/config.rb', line 47 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
117 118 119 120 121 |
# File 'lib/sus/config.rb', line 117 def after_tests(assertions, output: self.output) @clock.stop! self.print_summary(output, assertions) end |
#before_tests(assertions, output: self.output) ⇒ Object
110 111 112 113 114 115 |
# File 'lib/sus/config.rb', line 110 def before_tests(assertions, output: self.output) @clock.reset! @clock.start! prepare_warnings! end |
#load_registry(paths = @paths) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/sus/config.rb', line 85 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
81 82 83 |
# File 'lib/sus/config.rb', line 81 def make_registry Sus::Registry.new(root: @root) end |
#output ⇒ Object
71 72 73 |
# File 'lib/sus/config.rb', line 71 def output @output ||= Sus::Output.default end |
#partial? ⇒ Boolean
67 68 69 |
# File 'lib/sus/config.rb', line 67 def partial? @paths.any? end |
#prepare_warnings! ⇒ Object
106 107 108 |
# File 'lib/sus/config.rb', line 106 def prepare_warnings! Warning[:deprecated] = true end |
#registry ⇒ Object
102 103 104 |
# File 'lib/sus/config.rb', line 102 def registry @registry ||= self.load_registry end |
#test_paths ⇒ Object
77 78 79 |
# File 'lib/sus/config.rb', line 77 def test_paths return Dir.glob(DEFAULT_TEST_PATTERN, base: @root) end |
#verbose? ⇒ Boolean
63 64 65 |
# File 'lib/sus/config.rb', line 63 def verbose? @verbose end |