class TestBench::Run

Constants

Error

Attributes

exclude_pattern[W]
paths[R]
session[W]

Public Class Methods

build(*paths, exclude: nil, session: nil, output: nil) click to toggle source
# 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) click to toggle source
# 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
configure(receiver, *paths, attr_name: nil, **args) click to toggle source
# 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
new(*paths) click to toggle source
# File lib/test_bench/run.rb, line 17
def initialize(*paths)
  @paths = Array(paths)
end

Public Instance Methods

call(&block) click to toggle source
# 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) click to toggle source
# File lib/test_bench/run.rb, line 79
def directory(path)
  glob_pattern = File.join(path, '**/*.rb')

  Dir.glob(glob_pattern).sort.each do |path|
    file(path)
  end
end
exclude_pattern() click to toggle source
# File lib/test_bench/run.rb, line 10
def exclude_pattern
  @exclude_pattern ||= Defaults.exclude_pattern
end
file(path) click to toggle source
# File lib/test_bench/run.rb, line 87
def file(path)
  unless exclude_pattern.match?(path)
    session.load(path)
  end
end
path(path) click to toggle source
# 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
session() click to toggle source
# File lib/test_bench/run.rb, line 5
def session
  @session ||= Fixture::Session::Substitute.build
end