-
Notifications
You must be signed in to change notification settings - Fork 12
/
Rakefile
97 lines (76 loc) · 1.68 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
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
88
89
90
91
92
93
94
95
96
97
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
require 'yaml'
require 'erb'
namespace :db do
config_name = ENV['DBCONF'] || 'config.yml'
databases = YAML.load(ERB.new(IO.read(File.join(File.dirname(__FILE__), 'spec', 'support', 'db', config_name))).result)
databases.each do |name, spec|
desc "Run given task for #{spec['adapter']} database"
task name do
with_database(name) do
announce
exec
end
end
end
task :all do
require 'benchmark'
time = Benchmark.realtime do
databases.keys.each do |name|
with_database(name) do
announce
run
end
end
end
puts
puts 'Time taken: %.2f sec' % time
exit
end
private
def exec
Kernel.exec(ENV, *command)
end
def run
unless Kernel.system(ENV, *command)
exit(1)
end
end
def with_database(name)
ENV['DB'] = name
yield
ensure
ENV['DB'] = nil
end
def command
['bundle', 'exec', 'rake', *ARGV.slice(1, ARGV.size)]
end
def announce
puts ">> DB=#{ENV['DB']} #{command.join(' ')}"
end
end
desc 'Run given task for all databases'
task :db => 'db:all'
RSpec::Core::RakeTask.new(:spec) do |t|
t.rspec_opts = '--color --format progress'
end
begin
require 'coveralls/rake/task'
Coveralls::RakeTask.new
rescue LoadError, NameError
task 'coveralls:push'
end
namespace :coverage do
desc 'Turn on code coverage'
task :enable do
ENV['COVERAGE'] = '1' unless ENV.key?('COVERAGE')
end
desc 'Turn off code coverage'
task :disable do
ENV['COVERAGE'] = ''
end
desc 'Push code coverage to coveralls'
task :push => 'coveralls:push'
end
task :spec => 'coverage:enable'