Module: DohTest

Defined in:
lib/doh/test/run_tests.rb,
lib/doh/test/error_acceptor.rb,
lib/doh/test/use_test_database.rb

Class Method Summary collapse

Class Method Details

.check_for_unhandled_errorsObject



17
18
19
20
21
22
23
24
25
# File 'lib/doh/test/error_acceptor.rb', line 17

def self.check_for_unhandled_errors
  errors = DohTest::error_acceptor.events
  unless errors.empty?
    STDERR.puts("#{errors.size} unhandled errors were written to the log file (call DohTest::pop_error after a test if the test is expected to generate an error):")
    formatter = DohLogger::Formatter.new("[%severity] : %msg\nexception: %exception\nstack:\n%call_stack")
    errors.each {|elem| STDERR.puts(formatter.replace(elem))}
    exit 1
  end
end

.error_acceptorObject



9
10
11
# File 'lib/doh/test/error_acceptor.rb', line 9

def self.error_acceptor
  @@error_acceptor
end

.execute_test_files(files, method_filter = nil, growl_notify = nil) ⇒ Object



23
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
# File 'lib/doh/test/run_tests.rb', line 23

def self.execute_test_files(files, method_filter = nil, growl_notify = nil)
if RUBY_VERSION.to_d < 1.9
  collector = Test::Unit::Collector::Dir.new
  collector.filter = [proc {|tstobj| !tstobj.method_name.index(method_filter).nil?}] if method_filter
  suite = collector.collect(*files)
  results = Test::Unit::UI::Console::TestRunner.run(suite)

  dohlog.literal do
    results.errors.each do |error|
      dohlog.debug("got #{error.to_s}")
    end
    results.failures.each do |failure|
      dohlog.debug("got #{failure.to_s}")
    end
  end

  if growl_notify
    if !results.passed?
      `growlnotify -n run_tests_failed -m 'some tests failed' -p 1`
    else
      `growlnotify -n run_tests_passed -m 'all tests passed' -p -2`
    end
  end
  exit(1) unless results.passed?
  DohTest::check_for_unhandled_errors
else
  files.each {|onefile| require onefile}
end
end

.init_error_acceptorObject



5
6
7
# File 'lib/doh/test/error_acceptor.rb', line 5

def self.init_error_acceptor
  @@error_acceptor = DohLogger::MemoryAcceptor.new
end

.init_test_databaseObject



16
17
18
19
20
21
# File 'lib/doh/test/run_tests.rb', line 16

def self.init_test_database
  if DohApp::config['database_type'] == 'mysql'
    dbname = DohApp::config['primary_database']
    DohDb::DatabaseCreator.new.create_database_copy('doh_test_' + dbname, dbname, true)
  end
end

.pop_errorObject



13
14
15
# File 'lib/doh/test/error_acceptor.rb', line 13

def self.pop_error
  @@error_acceptor.events.pop
end

.run_tests(what_to_run, include_production_tests, include_slow_tests, method_filter = nil, growl_notify = nil) ⇒ Object



77
78
79
80
81
82
83
84
85
# File 'lib/doh/test/run_tests.rb', line 77

def self.run_tests(what_to_run, include_production_tests, include_slow_tests, method_filter = nil, growl_notify = nil)
  DohApp::activate_database
  DohData::require_datagen
  if File.directory?(what_to_run)
    run_tests_directory(what_to_run, include_production_tests, include_slow_tests, method_filter, growl_notify)
  else
    run_tests_file(what_to_run, method_filter, growl_notify)
  end
end

.run_tests_directory(directory, include_production_tests, include_slow_tests, method_filter = nil, growl_notify = nil) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/doh/test/run_tests.rb', line 53

def self.run_tests_directory(directory, include_production_tests, include_slow_tests, method_filter = nil, growl_notify = nil)
  result = false
  if include_production_tests
    letters = 'pq'
  else
    letters = 'dp'
  end
  letters += 's' if include_slow_tests

  files = Dir.glob(File.join(directory, '**', "*.dt[#{letters}].rb"))
  unless files.empty?
    init_test_database
    execute_test_files(files, method_filter, growl_notify)
    result = true
  end
  result
end

.run_tests_file(filename, method_filter = nil, growl_notify = nil) ⇒ Object



71
72
73
74
75
# File 'lib/doh/test/run_tests.rb', line 71

def self.run_tests_file(filename, method_filter = nil, growl_notify = nil)
  init_test_database
  execute_test_files([filename], method_filter, growl_notify)
  true
end

.use_test_databaseObject



5
6
7
8
9
10
# File 'lib/doh/test/use_test_database.rb', line 5

def self.use_test_database
  dbcfg = DohApp::config['database']
  dbname = DohApp::config['primary_database']
  DohDb::set_connector_instance(DohDb::CacheConnector.new(dbcfg['host'], dbcfg['username'], dbcfg['password'], nil, DohApp::config['row_builder']))
  DohDb::DatabaseCreator.new.create_database_copy('doh_test_' + dbname, dbname, true)
end