Class: Assert::AssertRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/assert/assert_runner.rb

Constant Summary collapse

TEST_FILE_SUFFIXES =
['_tests.rb', '_test.rb']
USER_SETTINGS_FILE =
".assert/init.rb"
LOCAL_SETTINGS_FILE =
".assert.rb"
DEFAULT_CHANGED_FILES_PROC =
Proc.new do |test_paths|
  # use git to determine which files have changes
  files = []
  cmd = [
    "git diff --no-ext-diff --name-only",       # changed files
    "git ls-files --others --exclude-standard"  # added files
  ].map{ |c| "#{c} -- #{test_paths.join(' ')}" }.join(' && ')

  Assert::CLI.bench('Load only changed files') do
    files = `#{cmd}`.split("\n")
  end
  puts Assert::CLI.debug_msg("  `#{cmd}`") if Assert.config.debug
  files
end

Instance Method Summary collapse

Constructor Details

#initialize(test_paths, test_options) ⇒ AssertRunner

Returns a new instance of AssertRunner.



25
26
27
28
29
30
31
32
33
34
35
# File 'lib/assert/assert_runner.rb', line 25

def initialize(test_paths, test_options)
  Assert::CLI.bench('Apply settings') do
    
    apply_local_settings
    apply_option_settings(test_options)
    apply_env_settings
  end

  files = test_files(test_paths.empty? ? [*Assert.config.test_dir] : test_paths)
  init(files, path_of(Assert.config.test_dir, files.first))
end

Instance Method Details

#init(test_files, test_dir) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/assert/assert_runner.rb', line 37

def init(test_files, test_dir)
  # load any test helper file
  if test_dir && (h = File.join(test_dir, Config.test_helper)) && File.exists?(h)
    Assert::CLI.bench('Require test helper'){ require h }
  end

  # load the test files
  Assert.view.fire(:before_load, test_files)
  Assert::CLI.bench("Require #{test_files.count} test files") do
    test_files.each{ |p| require p }
  end
  if Assert.config.debug
    puts Assert::CLI.debug_msg("Test files:")
    test_files.each{ |f| puts Assert::CLI.debug_msg("  #{f}") }
  end
  Assert.view.fire(:after_load)
end

#runObject



55
56
57
# File 'lib/assert/assert_runner.rb', line 55

def run
  Assert.runner.run(Assert.suite, Assert.view)
end