-
Notifications
You must be signed in to change notification settings - Fork 2
/
spec_helper.rb
52 lines (40 loc) · 1.36 KB
/
spec_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
require 'coveralls'
Coveralls.wear!
require 'active_record'
require 'data_mapper'
require 'sql_partitioner'
require 'logger'
#require 'ruby-debug' # enable debugger support
SPEC_LOGGER = Logger.new(nil)
RSpec.configure do |config|
# enable both should and expect syntax in rspec without deprecation warnings
config.expect_with :rspec do |c|
c.syntax = [:should, :expect]
end
config.mock_with :rspec do |c|
c.syntax = [:should, :expect]
end
config.before :suite do
require 'yaml'
db_conf = YAML.load_file('spec/db_conf.yml')
# establish both ActiveRecord and DataMapper connections
ActiveRecord::Base.establish_connection(db_conf["test"])
adapter,database,user,pass,host = db_conf["test"].values_at *%W(adapter database username password host)
connection_string = "#{adapter}://#{user}:#{pass}@#{host}/#{database}"
DataMapper.setup(:default, connection_string)
end
config.before :each do
sql = <<-SQL
DROP TABLE IF EXISTS `test_events`
SQL
DataMapper.repository.adapter.execute(sql)
sql = <<-SQL
CREATE TABLE IF NOT EXISTS `test_events` (
`id` bigint(20) NOT NULL AUTO_INCREMENT,
`timestamp` bigint(20) unsigned NOT NULL DEFAULT '0',
PRIMARY KEY (`id`,`timestamp`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8
SQL
DataMapper.repository.adapter.execute(sql)
end
end