Class: Sus::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/sus/config.rb

Constant Summary collapse

PATH =
"config/sus.rb"
DEFAULT_TEST_PATTERN =
"test/**/*.rb"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root, paths, verbose: false) ⇒ Config

Returns a new instance of Config.



37
38
39
40
41
42
43
44
45
# File 'lib/sus/config.rb', line 37

def initialize(root, paths, verbose: false)
	@root = root
	@paths = paths
	@verbose = verbose
	
	@clock = Clock.new
	
	self.add_default_load_paths
end

Instance Attribute Details

#pathsObject (readonly)

Returns the value of attribute paths.



61
62
63
# File 'lib/sus/config.rb', line 61

def paths
  @paths
end

#rootObject (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
	
	options = {
		verbose: !!arguments.delete("--verbose")
	}
	
	return derived.new(root, arguments, **options)
end

.path(root) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/sus/config.rb', line 13

def self.path(root)
	path = ::File.join(root, PATH)
	
	if ::File.exist?(path)
		return path
	end
end

Instance Method Details

#add_default_load_pathsObject



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.expand_path(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_registryObject



81
82
83
# File 'lib/sus/config.rb', line 81

def make_registry
	Sus::Registry.new(root: @root)
end

#outputObject



71
72
73
# File 'lib/sus/config.rb', line 71

def output
	@output ||= Sus::Output.default
end

#partial?Boolean

Returns:

  • (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

#registryObject



102
103
104
# File 'lib/sus/config.rb', line 102

def registry
	@registry ||= self.load_registry
end

#test_pathsObject



77
78
79
# File 'lib/sus/config.rb', line 77

def test_paths
	return Dir.glob(DEFAULT_TEST_PATTERN, base: @root)
end

#verbose?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/sus/config.rb', line 63

def verbose?
	@verbose
end