Class: TestBench::Runner

Inherits:
Object
  • Object
show all
Defined in:
lib/test_bench/runner.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(paths, telemetry) ⇒ Runner

Returns a new instance of Runner.



8
9
10
11
# File 'lib/test_bench/runner.rb', line 8

def initialize paths, telemetry
  @paths = paths
  @telemetry = telemetry
end

Instance Attribute Details

#executorObject



51
52
53
# File 'lib/test_bench/runner.rb', line 51

def executor
  @executor ||= Executor.build
end

#expand_pathObject



55
56
57
# File 'lib/test_bench/runner.rb', line 55

def expand_path
  @expand_path ||= proc do [] end
end

#pathsObject (readonly)

Returns the value of attribute paths.



5
6
7
# File 'lib/test_bench/runner.rb', line 5

def paths
  @paths
end

#telemetryObject (readonly)

Returns the value of attribute telemetry.



6
7
8
# File 'lib/test_bench/runner.rb', line 6

def telemetry
  @telemetry
end

Class Method Details

.build(paths, root_directory, exclude_pattern: nil) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/test_bench/runner.rb', line 13

def self.build paths, root_directory, exclude_pattern: nil
  telemetry = Telemetry::Registry.get TOPLEVEL_BINDING

  instance = new paths, telemetry
  instance.executor = Executor.build
  instance.expand_path = ExpandPath.build root_directory, exclude_pattern
  instance
end

.call(paths, root_directory = nil, exclude_pattern: nil) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/test_bench/runner.rb', line 22

def self.call paths, root_directory=nil, exclude_pattern: nil
  paths = Array paths
  root_directory ||= File.dirname caller_locations[0].path

  instance = build paths, root_directory, :exclude_pattern => exclude_pattern
  instance.()
end

Instance Method Details

#callObject



30
31
32
33
34
35
36
37
38
39
# File 'lib/test_bench/runner.rb', line 30

def call
  telemetry.run_started

  files = gather_files
  execute files
  return telemetry.passed?

ensure
  telemetry.run_finished
end

#execute(files) ⇒ Object



47
48
49
# File 'lib/test_bench/runner.rb', line 47

def execute files
  executor.(files)
end

#gather_filesObject



41
42
43
44
45
# File 'lib/test_bench/runner.rb', line 41

def gather_files
  paths.flat_map do |path|
    Array expand_path.(path)
  end
end