-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rakefile
86 lines (69 loc) · 2.19 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
# frozen_string_literal: true
ENV['DB'] ||= 'postgres'
require 'fileutils'
require 'bundler'
Bundler::GemHelper.install_tasks
desc 'Copy the database.DB.yml per ENV[\'DB\']'
task :install_database_yml do
puts "installing database.yml for #{ENV['DB']}"
FileUtils.rm('spec/dummy_app/db/database.yml', force: true)
FileUtils.cp(
"spec/dummy_app/config/database-template.#{ENV['DB']}.yml",
'spec/dummy_app/config/database.yml'
)
end
desc 'Delete generated files and databases'
task :clean do
use_docker = ENV['IRONTRAIL_TEST_DOCKER']
db = ENV.fetch('DB', 'postgres')
puts "Will drop #{db} database"
case db
when 'postgres'
command =
if use_docker
"docker exec -t #{use_docker} dropdb -U postgres --if-exists iron_trail_test"
else
"dropdb --if-exists iron_trail_test > /dev/null 2>&1"
end
system(command)
else
raise "Don't know DB '#{db}'"
end
# Delete generated IronTrail migrations
migrate_path = File.expand_path('spec/dummy_app/db/migrate', __dir__)
Dir.glob("#{migrate_path}/*.rb").each do |full_path|
base_name = File.basename(full_path)
next unless base_name =~ /^\d{14}_create_irontrail_.+\.rb$/
FileUtils.rm full_path
end
end
desc 'Create the database.'
task :create_db do
use_docker = ENV['IRONTRAIL_TEST_DOCKER']
db = ENV.fetch('DB', 'postgres')
puts "Will create #{db} database"
case db
when 'postgres'
command =
if use_docker
"docker exec -t #{use_docker} createdb -U postgres iron_trail_test"
else
"createdb iron_trail_test > /dev/null 2>&1"
end
system(command)
else
raise "Don't know DB '#{db}'"
end
end
task prepare: %i[clean install_database_yml create_db]
require 'rspec/core/rake_task'
task(:spec).clear
RSpec::Core::RakeTask.new(:spec)
# Loading the testing/rspec file will affect RSpec globally. Because of that,
# we want to test it in a separate scope. We could also always require it,
# but that wouldn't be true in a real rails app and could make all tests
# farther apart from reality, thus less reliable.
RSpec::Core::RakeTask.new(:testing_spec).tap do |task|
task.pattern = 'spec/testing_itself.rb'
end
task default: %i[prepare spec testing_spec]