forked from integrity/integrity
-
Notifications
You must be signed in to change notification settings - Fork 2
/
helpers.rb
87 lines (72 loc) · 1.63 KB
/
helpers.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
$:.unshift File.dirname(__FILE__) + "/../lib", File.dirname(__FILE__)
%w(test/unit
context
pending
matchy
storyteller
webrat/sinatra
rr
mocha
dm-sweatshop).each { |dependency|
begin
require dependency
rescue LoadError => e
puts "You're missing some gems required to run the tests."
puts "Please run `rake test:setup`"
puts "NOTE: You'll probably need to run that command as root or with sudo."
puts "Thanks :)"
puts
raise
end
}
begin
require "ruby-debug"
require "redgreen"
rescue LoadError
end
require "integrity"
require "helpers/expectations"
require "integrity/notifier/test/fixtures"
module TestHelper
def ignore_logs!
Integrity.config[:log] = "/tmp/integrity.test.log"
end
def capture_stdout
output = StringIO.new
$stdout = output
yield
$stdout = STDOUT
output
end
def silence_warnings
$VERBOSE, v = nil, $VERBOSE
yield
ensure
$VERBOSE = v
end
end
class Test::Unit::TestCase
class << self
alias_method :specify, :test
end
include RR::Adapters::TestUnit
include Integrity
include TestHelper
before(:all) do
DataMapper.setup(:default, "sqlite3::memory:")
end
before(:each) do
require "integrity/migrations"
[Project, Build, Commit, Notifier].each(&:auto_migrate_down!)
capture_stdout { Integrity.migrate_db }
RR.reset
Notifier.available.each { |n|
Notifier.send(:remove_const, n.to_s.split(":").last.to_sym)
}
Integrity.instance_variable_set(:@config, nil)
Integrity.instance_variable_set(:@notifiers, nil)
end
after(:each) do
capture_stdout { Integrity::Migrations.migrate_down! }
end
end