This repository has been archived by the owner on Jul 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Rakefile
62 lines (53 loc) · 1.57 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
require 'bundler'
require 'yaml'
Bundler::GemHelper.install_tasks
DB_CONFIG = "spec/database.yml"
GEMFILES = "spec/Gemfile.rails_[0-9]_[0-9]"
require 'rake'
desc 'Default: run all unit tests.'
task :default => :"spec:all"
require 'active_record'
# For more info on DatabaseTasks, see:
# https://github.com/rails/rails/blob/v5.0.7/activerecord/lib/active_record/tasks/database_tasks.rb
namespace :db do
task :load_config do
db_configs = YAML.load_file('spec/database.yml')
ActiveRecord::Tasks::DatabaseTasks.tap do |db_tasks|
ActiveRecord::Base.configurations = db_configs
db_tasks.database_configuration = db_configs
db_tasks.db_dir = 'db'
db_tasks.root = File.dirname(__FILE__)
end
end
desc 'Prepare the databases.'
task prepare: :load_config do
unless File.exist? DB_CONFIG
cp "#{DB_CONFIG}.tmpl", DB_CONFIG
end
ActiveRecord::Tasks::DatabaseTasks.tap do |db_tasks|
db_tasks.create_current('mysql')
db_tasks.create_current('sqlite')
end
end
desc "Drop all databases created for testing"
task drop_all: :load_config do
ActiveRecord::Tasks::DatabaseTasks.drop_all
end
end
require "rspec/core/rake_task"
desc 'Run the test suite.'
RSpec::Core::RakeTask.new(:spec) do |t|
t.pattern = 'spec/*_spec.rb'
t.exclude_pattern = 'spec/**/vendor/*'
end
desc 'Run the test suite for all DBs.'
namespace :spec do
task :all do
db_config = YAML::load(IO.read(DB_CONFIG))
db_config.each do |db, config|
ENV["DB"] = db
Rake::Task["spec"].reenable
Rake::Task["spec"].invoke
end
end
end