Class: Ace::TestRunner::Models::TestTarget
- Inherits:
-
Object
- Object
- Ace::TestRunner::Models::TestTarget
- Defined in:
- lib/ace/test_runner/models/test_target.rb
Overview
Represents a target of tests to be executed together
Instance Attribute Summary collapse
-
#files ⇒ Object
readonly
Returns the value of attribute files.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#patterns ⇒ Object
readonly
Returns the value of attribute patterns.
Class Method Summary collapse
-
.default_targets ⇒ Object
Default test targets for common Ruby project structures.
-
.from_config(config) ⇒ Object
Load targets from configuration.
Instance Method Summary collapse
-
#execute(executor, formatter_options = {}) ⇒ Object
Execute this target’s tests.
-
#find_files ⇒ Object
Find all test files matching this target’s patterns.
-
#includes_file?(file_path) ⇒ Boolean
Check if a file belongs to this target.
-
#initialize(name:, patterns: [], files: [], options: {}) ⇒ TestTarget
constructor
A new instance of TestTarget.
- #to_h ⇒ Object
Constructor Details
#initialize(name:, patterns: [], files: [], options: {}) ⇒ TestTarget
Returns a new instance of TestTarget.
10 11 12 13 14 15 |
# File 'lib/ace/test_runner/models/test_target.rb', line 10 def initialize(name:, patterns: [], files: [], options: {}) @name = name @patterns = Array(patterns) @files = Array(files) @options = end |
Instance Attribute Details
#files ⇒ Object (readonly)
Returns the value of attribute files.
8 9 10 |
# File 'lib/ace/test_runner/models/test_target.rb', line 8 def files @files end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
8 9 10 |
# File 'lib/ace/test_runner/models/test_target.rb', line 8 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/ace/test_runner/models/test_target.rb', line 8 def @options end |
#patterns ⇒ Object (readonly)
Returns the value of attribute patterns.
8 9 10 |
# File 'lib/ace/test_runner/models/test_target.rb', line 8 def patterns @patterns end |
Class Method Details
.default_targets ⇒ Object
Default test targets for common Ruby project structures
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/ace/test_runner/models/test_target.rb', line 67 def self.default_targets { "fast" => { "patterns" => ["test/fast/**/*_test.rb", "test/*_test.rb", "test/unit/**/*_test.rb"], "options" => {} }, "feat" => { "patterns" => ["test/feat/**/*_test.rb", "test/edge/**/*_test.rb"], "options" => {} }, "all" => { "patterns" => ["test/fast/**/*_test.rb", "test/*_test.rb", "test/feat/**/*_test.rb", "test/edge/**/*_test.rb"], "options" => {} } } end |
.from_config(config) ⇒ Object
Load targets from configuration
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/ace/test_runner/models/test_target.rb', line 53 def self.from_config(config) targets = config.fetch("targets", default_targets) targets.map do |name, definition| new( name: name, patterns: definition["patterns"] || [], files: definition["files"] || [], options: definition.fetch("options", {}).transform_keys(&:to_sym) ) end end |
Instance Method Details
#execute(executor, formatter_options = {}) ⇒ Object
Execute this target’s tests
26 27 28 29 30 31 32 |
# File 'lib/ace/test_runner/models/test_target.rb', line 26 def execute(executor, = {}) test_files = find_files return empty_result if test_files.empty? = @options.merge() executor.execute_tests(test_files, ) end |
#find_files ⇒ Object
Find all test files matching this target’s patterns
18 19 20 21 22 23 |
# File 'lib/ace/test_runner/models/test_target.rb', line 18 def find_files return @files unless @files.empty? detector = Atoms::TestDetector.new(patterns: @patterns) detector.find_test_files end |
#includes_file?(file_path) ⇒ Boolean
Check if a file belongs to this target
35 36 37 38 39 40 41 |
# File 'lib/ace/test_runner/models/test_target.rb', line 35 def includes_file?(file_path) return true if @files.include?(file_path) @patterns.any? do |pattern| File.fnmatch(pattern, file_path, File::FNM_PATHNAME) end end |
#to_h ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/ace/test_runner/models/test_target.rb', line 43 def to_h { name: @name, patterns: @patterns, files: @files, options: @options } end |