forked from kylejginavan/factory_data_preloader
/
test_helper.rb
56 lines (46 loc) · 1.3 KB
/
test_helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
52
53
54
55
56
require 'rubygems'
require 'test/unit'
require 'shoulda'
begin
require 'ruby-debug'
Debugger.start
Debugger.settings[:autoeval] = true if Debugger.respond_to?(:settings)
rescue LoadError
# ruby-debug wasn't available so neither can the debugging be
end
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'factory_data_preloader'
ActiveRecord::Base.establish_connection({ :database => ":memory:", :adapter => 'sqlite3', :timeout => 500 })
module OutputCapturer
# borrowed from zentest assertions...
def self.capture
require 'stringio'
orig_stdout = $stdout.dup
orig_stderr = $stderr.dup
captured_stdout = StringIO.new
captured_stderr = StringIO.new
$stdout = captured_stdout
$stderr = captured_stderr
yield
captured_stdout.rewind
captured_stderr.rewind
return captured_stdout.string, captured_stderr.string
ensure
$stdout = orig_stdout
$stderr = orig_stderr
end
end
module FactoryDataPreloader
def self.reset!
self.preload_all = true
self.preload_types = []
preloaders = Array.new(FactoryDataPreloader::AllPreloaders.instance)
preloaders.each do |preloader|
preloader.remove!
end
FactoryData.reset_cache!
end
end
require 'lib/schema'
require 'lib/models'