-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathRakefile
40 lines (33 loc) · 1.26 KB
/
Rakefile
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
require 'rake/testtask'
require 'rake/clean'
require 'yaml'
NAME = "mysql_blob_streaming"
file "lib/#{NAME}/#{NAME}.so" => Dir.glob("ext/#{NAME}/*{.rb,.c}") do
Dir.chdir("ext/#{NAME}") do
ruby "extconf.rb"
sh "make"
end
mkdir_p "lib/#{NAME}"
cp FileList["ext/#{NAME}/#{NAME}.{so,bundle}"], "lib/#{NAME}"
end
task test: "lib/#{NAME}/#{NAME}.so"
task test: :prepare_test_db
CLEAN.include('ext/**/*.{o,log,so,bundle}')
CLEAN.include('ext/**/Makefile')
CLEAN.include('ext/**/conftest*')
CLOBBER.include('lib/**/*.{so,bundle}')
Rake::TestTask.new do |t|
t.test_files = FileList["test/test.rb"]
end
desc "Run tests"
task :default => :test
task :cruise => :test
task :prepare_test_db do
database_config = YAML::load_file("test/database.yml")
if %x(mysql -uroot -e 'show databases' --batch).split.include?(database_config['database'])
sh "mysqladmin", "-uroot", "--force", "drop", database_config['database']
end
sh "mysqladmin", "-uroot", "create", database_config['database']
sh "mysql", "-uroot", "-e", "CREATE USER IF NOT EXISTS '#{database_config['username']}'@'localhost' IDENTIFIED BY '#{database_config['password']}'"
sh "mysql", "-uroot", "-e", "GRANT ALL ON #{database_config['database']}.* TO '#{database_config['username']}'@'localhost'"
end