Class: TestBench::Run
  
  
  
  
  
    - Inherits:
- 
      Object
      
        
        show all
      
    
    - Defined in:
- lib/test_bench/run.rb,
 lib/test_bench/run/substitute.rb
 
Defined Under Namespace
  
    
      Modules: Defaults, Substitute
    
  
    
  
  
    
      Constant Summary
      collapse
    
    
      
        - Error =
          
        
- Class.new(RuntimeError) 
Instance Attribute Summary collapse
  
  
    
      Class Method Summary
      collapse
    
    
  
    
      Instance Method Summary
      collapse
    
    
  
  Constructor Details
  
    
  
  
    #initialize(*paths)  ⇒ Run 
  
  
  
  
    
Returns a new instance of Run.
   
 
  
  
    | 
17
18
19 | # File 'lib/test_bench/run.rb', line 17
def initialize(*paths)
  @paths = Array(paths)
end | 
 
  
 
  
    Instance Attribute Details
    
      
      
      
  
  
    #exclude_pattern  ⇒ Object 
  
  
  
  
    | 
10
11
12 | # File 'lib/test_bench/run.rb', line 10
def exclude_pattern
  @exclude_pattern ||= Defaults.exclude_pattern
end | 
 
    
      
      
      
  
  
    #paths  ⇒ Object  
  
  
  
  
    
Returns the value of attribute paths.
   
 
  
  
    | 
15
16
17 | # File 'lib/test_bench/run.rb', line 15
def paths
  @paths
end | 
 
    
      
      
      
  
  
    #session  ⇒ Object 
  
  
  
  
    | 
5
6
7 | # File 'lib/test_bench/run.rb', line 5
def session
  @session ||= Fixture::Session::Substitute.build
end | 
 
    
   
  
    Class Method Details
    
      
  
  
    .build(*paths, exclude: nil, session: nil, output: nil)  ⇒ Object 
  
  
  
  
    | 
21
22
23
24
25
26
27
28
29
30
31
32 | # File 'lib/test_bench/run.rb', line 21
def self.build(*paths, exclude: nil, session: nil, output: nil)
  session ||= TestBench.session
  instance = new(*paths)
  instance.exclude_pattern = exclude unless exclude.nil?
  Fixture::Session.configure(instance, session: session)
  instance.session.output = output unless output.nil?
  instance
end | 
 
    
      
  
  
    .call(*paths, **args, &block)  ⇒ Object 
  
  
  
  
    | 
42
43
44
45
46
47
48
49
50
51
52 | # File 'lib/test_bench/run.rb', line 42
def self.call(*paths, **args, &block)
  instance = build(*paths, **args)
  if block.nil?
    instance.()
  else
    instance.() do
      block.(instance)
    end
  end
end | 
 
    
      
  
  
    | 
34
35
36
37
38
39
40 | # File 'lib/test_bench/run.rb', line 34
def self.configure(receiver, *paths, attr_name: nil, **args)
  attr_name ||= :run
  instance = build(*paths, **args)
  receiver.public_send(:"#{attr_name}=", instance)
  instance
end | 
 
    
   
  
    Instance Method Details
    
      
  
  
    #call(&block)  ⇒ Object 
  
  
  
  
    | 
54
55
56
57
58
59
60
61
62
63
64
65
66
67 | # File 'lib/test_bench/run.rb', line 54
def call(&block)
  session.start
  if block.nil?
    paths.each do |path|
      path(path)
    end
  else
    block.()
  end
ensure
  session.finish
end | 
 
    
      
  
  
    #directory(path)  ⇒ Object 
  
  
  
  
    | 
79
80
81
82
83
84
85
86
87 | # File 'lib/test_bench/run.rb', line 79
def directory(path)
  glob_pattern = File.join(path, '**/*.rb')
  Dir[glob_pattern].sort.each do |path|
    next if exclude_pattern.match?(path)
    file(path)
  end
end | 
 
    
      
  
  
    #file(path)  ⇒ Object 
  
  
  
  
    | 
89
90
91 | # File 'lib/test_bench/run.rb', line 89
def file(path)
  session.load(path)
end | 
 
    
      
  
  
    #path(path)  ⇒ Object 
  
  
  
  
    | 
69
70
71
72
73
74
75
76
77 | # File 'lib/test_bench/run.rb', line 69
def path(path)
  if File.directory?(path)
    directory(path)
  elsif File.exist?(path)
    file(path)
  else
    raise Error, "Path not found (Path: #{path.inspect})"
  end
end |