Class: Sus::Filter
- Inherits:
-
Object
- Object
- Sus::Filter
- Defined in:
- lib/sus/filter.rb
Overview
Provides a way to filter the registry according to the suffix on loaded paths.
A test has an identity, e.g. the file and line number on which it’s defined.
A filter takes an identity, decomposes it into a file and suffix, loads the file, and registers the filter suffix.
When the filter is used to enumerate the registry, it will only return the tests that match the suffix.
Defined Under Namespace
Classes: Index
Instance Method Summary collapse
-
#call(assertions = Assertions.default) ⇒ Object
Execute filtered tests.
-
#each(&block) ⇒ Object
Iterate over filtered test cases.
-
#initialize(registry = Registry.new) ⇒ Filter
constructor
Initialize a new Filter.
-
#load(target) ⇒ Object
Load a target path, optionally with a filter suffix.
Constructor Details
Instance Method Details
#call(assertions = Assertions.default) ⇒ Object
Execute filtered tests.
96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/sus/filter.rb', line 96 def call(assertions = Assertions.default) if @keys.any? @index = Index.new @index.add(@registry) @keys.each do |key| @index[key]&.call(assertions) end else @registry.call(assertions) end return assertions end |
#each(&block) ⇒ Object
Iterate over filtered test cases.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/sus/filter.rb', line 78 def each(&block) if @keys.any? @index = Index.new @index.add(@registry) @keys.each do |key| if target = @index[key] yield target end end else @registry.each(&block) end end |
#load(target) ⇒ Object
Load a target path, optionally with a filter suffix.
66 67 68 69 70 71 72 73 74 |
# File 'lib/sus/filter.rb', line 66 def load(target) path, filter = target.split(":", 2) @registry.load(path) if filter @keys << target end end |