Module: DohTest

Extended by:
DohTest
Included in:
DohTest
Defined in:
lib/dohtest/failure.rb,
lib/dohtest/configure.rb,
lib/dohtest/assertions.rb,
lib/dohtest/find_files.rb,
lib/dohtest/test_group.rb,
lib/dohtest/group_runner.rb,
lib/dohtest/master_runner.rb,
lib/dohtest/stream_output.rb,
lib/dohtest/capture_output.rb,
lib/dohtest/load_test_files.rb,
lib/dohtest/backtrace_parser.rb

Defined Under Namespace

Classes: BacktraceParser, CaptureOutput, Failure, GroupRunner, MasterRunner, StreamOutput, TestGroup

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.backtrace_summary(excpt) ⇒ Object



60
61
62
# File 'lib/dohtest/backtrace_parser.rb', line 60

def self.backtrace_summary(excpt)
  BacktraceParser.new(excpt.backtrace).summary
end

Instance Method Details

#add_default_config_valuesObject



58
59
60
61
# File 'lib/dohtest/configure.rb', line 58

def add_default_config_values
  DohTest.config[:glob] ||= '*.dt.rb'
  DohTest.config[:seed] ||= (Time.new.to_f * 1000).to_i
end

#configObject



7
8
9
10
# File 'lib/dohtest/configure.rb', line 7

def config
  @config ||= {:post_all_callback => [], :pre_group_callback => [], :post_group_callback => [], :pre_test_callback => [],
    :pre_each_callback => [], :post_each_callback => [], :pre_require_callback => []}
end

#configure(start_path) ⇒ Object



71
72
73
74
75
# File 'lib/dohtest/configure.rb', line 71

def configure(start_path)
  add_default_config_values
  set_test_files
  load_configuration_file(start_path)
end

#find_files(glob, paths) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/dohtest/find_files.rb', line 4

def find_files(glob, paths)
  retval = []
  expanded_paths = paths.map {|path| File.expand_path(path) }
  expanded_paths.each do |path|
    if File.directory?(path)
      retval.concat(Dir.glob(File.join(path, '**', glob)).to_a)
    else
      retval << path
    end
  end
  return retval
end

#find_root(start_directory, max_tries = 20) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/dohtest/configure.rb', line 12

def find_root(start_directory, max_tries = 20)
  curr_directory = start_directory
  max_tries.times do
    return nil if curr_directory == '/'
    if File.directory?(File.join(curr_directory, 'test')) || File.exist?(File.join(curr_directory, 'dohtest.rb'))
      return curr_directory
    end
    curr_directory = File.expand_path(File.join(curr_directory, '..'))
  end
  nil
end

#load_configuration_file(start_path) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/dohtest/configure.rb', line 24

def load_configuration_file(start_path)
  start_path = File.expand_path(start_path || '.')
  if File.directory?(start_path)
    start_directory = start_path
  else
    start_directory = File.dirname(start_path)
  end

  root_directory = find_root(start_directory)
  if !root_directory
    raise "unable to determine root directory to run tests from"
  end
  DohTest.config[:root] = root_directory

  Doh.find_root_from_path(root_directory)
  libdir = File.join(root_directory, 'lib')
  if File.directory?(libdir) && !$LOAD_PATH.include?(libdir)
    $LOAD_PATH << libdir
  end

  cfgfile = File.join(root_directory, 'dohtest.rb')
  if File.exist?(cfgfile)
    require(cfgfile)
    return
  end

  cfgfile = File.join(root_directory, 'config', 'dohtest.rb')
  if File.exist?(cfgfile)
    require(cfgfile)
    return
  end

end

#load_test_files(paths) ⇒ Object



11
12
13
14
15
16
# File 'lib/dohtest/load_test_files.rb', line 11

def load_test_files(paths)
  callbacks = @config[:pre_require_callback]
  paths.each do |path|
    require_test_file(path, callbacks)
  end
end

#require_test_file(path, callbacks) ⇒ Object



4
5
6
7
8
9
# File 'lib/dohtest/load_test_files.rb', line 4

def require_test_file(path, callbacks)
  callbacks.each do |callback|
    callback.call(path)
  end
  require(path)
end

#set_test_filesObject



63
64
65
66
67
68
69
# File 'lib/dohtest/configure.rb', line 63

def set_test_files
  paths = DohTest.config[:paths]
  if paths.empty?
    paths = ['.']
  end
  DohTest.config[:test_files] = DohTest.find_files(DohTest.config[:glob], paths)
end