Skip to content

Commit d870557

Browse files
committed
Improve the Rakefile adding a TaskLib
1 parent b3fdee5 commit d870557

File tree

1 file changed

+25
-20
lines changed

1 file changed

+25
-20
lines changed

Rakefile

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,31 +8,36 @@ load "rails/tasks/engine.rake"
88
load "rails/tasks/statistics.rake"
99

1010
require "bundler/gem_tasks"
11+
require "rake/tasklib"
1112

12-
def databases
13-
%w[ mysql postgres sqlite ]
14-
end
15-
16-
task :test do
17-
databases.each do |database|
18-
sh("TARGET_DB=#{database} bin/setup")
19-
sh("TARGET_DB=#{database} bin/rails test")
13+
class TestHelpers < Rake::TaskLib
14+
def initialize(databases)
15+
@databases = databases
16+
define
2017
end
21-
end
2218

23-
namespace :test do
24-
task :mysql do
25-
sh("TARGET_DB=mysql bin/setup")
26-
sh("TARGET_DB=mysql bin/rails test")
19+
def define
20+
desc "Run tests for all databases (mysql, postgres, sqlite)"
21+
task :test do
22+
@databases.each { |database| run_test_for_database(database) }
23+
end
24+
25+
namespace :test do
26+
@databases.each do |database|
27+
desc "Run tests for #{database} database"
28+
task database do
29+
run_test_for_database(database)
30+
end
31+
end
32+
end
2733
end
2834

29-
task :postgres do
30-
sh("TARGET_DB=postgres bin/setup")
31-
sh("TARGET_DB=postgres bin/rails test")
32-
end
35+
private
3336

34-
task :sqlite do
35-
sh("TARGET_DB=sqlite bin/setup")
36-
sh("TARGET_DB=sqlite bin/rails test")
37+
def run_test_for_database(database)
38+
sh("TARGET_DB=#{database} bin/setup")
39+
sh("TARGET_DB=#{database} bin/rails test")
3740
end
3841
end
42+
43+
TestHelpers.new(%w[ mysql postgres sqlite ])

0 commit comments

Comments
 (0)