-
Notifications
You must be signed in to change notification settings - Fork 0
/
spec_helper.rb
50 lines (40 loc) · 1.14 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
require "bundler/setup"
require "sequel/extensions/tablefunc"
require 'coveralls'
Coveralls.wear!
DB_NAME = (ENV['DB_NAME'] || "tablefunc_test").freeze
def connect
Sequel.connect("postgres:///#{DB_NAME}").tap(&:tables)
rescue Sequel::DatabaseConnectionError => e
raise unless e.message.include? "database \"#{DB_NAME}\" does not exist"
#Sequel.connect('postgres:///postgres') do |connect|
# connect.run("create database #{DB_NAME}")
#end
`createdb #{DB_NAME}`
Sequel.connect("postgres:///#{DB_NAME}")
end
DB = connect
RSpec.configure do |config|
# Enable flags like --only-failures and --next-failure
config.example_status_persistence_file_path = ".rspec_status"
config.before(:all) do
DB.drop_table?(:data)
DB.create_table?(:data) do
primary_key :id
String :group
String :created_at
Integer :value
end
DB.run(<<~SQL)
CREATE extension IF NOT EXISTS tablefunc;
SQL
data = YAML.load(IO.read("spec/fixtures/data.yml"))
DB[:data].multi_insert(data)
end
config.after(:all) do
DB.drop_table?(:data)
end
config.expect_with :rspec do |c|
c.syntax = :expect
end
end