Skip to content

Commit 14c0915

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

File tree

1 file changed

+24
-20
lines changed

1 file changed

+24
-20
lines changed

Rakefile

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,34 @@ load "rails/tasks/statistics.rake"
99

1010
require "bundler/gem_tasks"
1111

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")
12+
class TestHelpers < Rake::TaskLib
13+
def initialize(databases)
14+
@databases = databases
15+
define
2016
end
21-
end
2217

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

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

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

0 commit comments

Comments
 (0)