-
-
Notifications
You must be signed in to change notification settings - Fork 825
Expand file tree
/
Copy pathRakefile
More file actions
139 lines (118 loc) · 3.32 KB
/
Rakefile
File metadata and controls
139 lines (118 loc) · 3.32 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
require 'bundler'
require 'rspec/core/rake_task'
Bundler::GemHelper.install_tasks
RSpec::Core::RakeTask.new(:spec) do |rspec|
ENV['SPEC'] = 'spec/ransack/**/*_spec.rb'
# With Rails 3, using `--backtrace` raises 'invalid option' when testing.
# With Rails 4 and 5 it can be uncommented to see the backtrace:
#
# rspec.rspec_opts = ['--backtrace']
end
# RuboCop tasks
begin
require 'rubocop/rake_task'
RuboCop::RakeTask.new
rescue LoadError
# RuboCop not available
end
# Combined test task that runs both specs and RuboCop
desc "Run all tests (specs + RuboCop)"
task :test do
puts "Running RuboCop..."
Rake::Task["rubocop"].invoke
puts "\nRunning RSpec tests..."
Rake::Task["spec"].invoke
end
# Test with PostgreSQL
desc "Run all tests with PostgreSQL"
task :test_pg do
puts "Running RuboCop..."
Rake::Task["rubocop"].invoke
puts "\nRunning RSpec tests with PostgreSQL..."
ENV['DB'] = 'pg'
Rake::Task["spec"].invoke
end
# Test with MySQL
desc "Run all tests with MySQL"
task :test_mysql do
puts "Running RuboCop..."
Rake::Task["rubocop"].invoke
puts "\nRunning RSpec tests with MySQL..."
ENV['DB'] = 'mysql'
Rake::Task["spec"].invoke
end
# Helper method to check database availability
def database_available?(adapter)
case adapter
when 'pg', 'postgres', 'postgresql'
begin
require 'pg'
PG.connect(host: 'localhost', dbname: 'postgres', user: 'postgres', password: '')
true
rescue PG::Error, LoadError
false
end
when 'mysql', 'mysql2'
begin
require 'mysql2'
Mysql2::Client.new(host: 'localhost', username: 'root', password: '')
true
rescue Mysql2::Error, LoadError
false
end
else
true # SQLite is always available
end
rescue
false
end
# Test with all available databases
desc "Run all tests with available databases (SQLite, PostgreSQL, MySQL)"
task :test_all do
puts "Running RuboCop..."
Rake::Task["rubocop"].invoke
puts "\nRunning RSpec tests with SQLite..."
ENV.delete('DB')
Rake::Task["spec"].invoke
if database_available?('pg')
puts "\nPostgreSQL detected. Running RSpec tests with PostgreSQL..."
ENV['DB'] = 'pg'
Rake::Task["spec"].invoke
else
puts "\nPostgreSQL not available. Skipping PostgreSQL tests."
end
if database_available?('mysql')
puts "\nMySQL detected. Running RSpec tests with MySQL..."
ENV['DB'] = 'mysql'
Rake::Task["spec"].invoke
else
puts "\nMySQL not available. Skipping MySQL tests."
end
end
# Test with detected databases only
desc "Run tests with all detected databases"
task :test_detected do
puts "Detecting available databases..."
available_dbs = []
available_dbs << 'sqlite' if true # SQLite is always available
available_dbs << 'postgresql' if database_available?('pg')
available_dbs << 'mysql' if database_available?('mysql')
puts "Available databases: #{available_dbs.join(', ')}"
puts "\nRunning RuboCop..."
Rake::Task["rubocop"].invoke
available_dbs.each do |db|
puts "\nRunning RSpec tests with #{db.capitalize}..."
ENV['DB'] = db
Rake::Task["spec"].invoke
end
end
task :default do
Rake::Task["test"].invoke
end
desc "Open an irb session with Ransack and the sample data used in specs"
task :console do
require 'pry'
require File.expand_path('../spec/console.rb', __FILE__)
ARGV.clear
Pry.start
end