8000 Add a way to forcefully create the test application · stephancom/activeadmin@b199f4b · GitHub
[go: up one dir, main page]

Skip to content

Commit b199f4b

Browse files
Add a way to forcefully create the test application
I find myself running `rm -rf tmp/rails/rails_52` or whatever and then running `bin/rake setup` to recreate the test application. Now I can do `bin/rake setup:force`.
1 parent 2b83836 commit b199f4b

File tree

2 files changed

+57
-30
lines changed

2 files changed

+57
-30
lines changed

tasks/test.rake

Lines changed: 38 additions & 7 deletions
10000
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,48 @@
11
desc "Run the full suite using parallel_tests to run on multiple cores"
22
task test: [:setup, :spec, :cucumber]
33

4-
desc "Create a test rails app for the parallel specs to run against"
5-
task :setup, [:rails_env, :template] do |_t, opts|
6-
if ENV["COVERAGE"] == "true"
7-
require "simplecov"
4+
desc "Create a test rails app for the parallel specs to run against if it doesn't exist already"
5+
task setup: :"setup:create"
86

9-
SimpleCov.command_name "test app creation"
7+
namespace :setup do
8+
desc "Forcefully create a test rails app for the parallel specs to run against"
9+
task :force, [:rails_env, :template] => [:require, :rm, :run]
10+
11+
desc "Create a test rails app for the parallel specs to run against if it doesn't exist already"
12+
task :create, [:rails_env, :template] => [:require, :guard, :run]
13+
14+
desc "Makes test app creation code available"
15+
task :require do
16+
if ENV["COVERAGE"] == "true"
17+
require "simplecov"
18+
19+
SimpleCov.command_name "test app creation"
20+
end
21+
22+
require_relative "test_application"
23+
end
24+
25+
desc "Create a test rails app for the parallel specs to run against"
26+
task :run, [:rails_env, :template] do |_t, opts|
27+
ActiveAdmin::TestApplication.new(opts).generate
1028
end
1129

12-
require_relative "test_application"
30+
desc "Aborts if the test app already exists"
31+
task :guard, [:rails_env, :template] do |_t, opts|
32+
test_app = ActiveAdmin::TestApplication.new(opts)
1333

14-
ActiveAdmin::TestApplication.new(opts).generate
34+
app_dir = test_app.app_dir
35+
36+
if File.exist? app_dir
37+
abort "test app #{app_dir} already exists; skipping test app generation"
38+
end
39+
end
40+
41+
task :rm, [:rails_env, :template] do |_t, opts|
42+
test_app = ActiveAdmin::TestApplication.new(opts)
43+
44+
FileUtils.rm_rf test_app.app_dir
45+
end
1546
end
1647

1748
task spec: :"spec:all"

tasks/test_application.rb

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,25 @@ def initialize(opts = {})
1010
end
1111

1212
def generate
13-
if File.exist? app_dir
14-
puts "test app #{app_dir} already exists; skipping test app generation"
15-
else
16-
FileUtils.mkdir_p base_dir
17-
args = %W(
18-
-m spec/support/#{template}.rb
19-
--skip-bootsnap
20-
--skip-bundle
21-
--skip-gemfile
22-
--skip-listen
23-
--skip-spring
24-
--skip-turbolinks
25-
--skip-test-unit
26-
--skip-coffee
27-
--skip-webpack-install
28-
)
29-
30-
command = ['bundle', 'exec', 'rails', 'new', app_dir, *args].join(' ')
31-
32-
env = { 'BUNDLE_GEMFILE' => expanded_gemfile, 'RAILS_ENV' => rails_env }
33-
34-
Bundler.with_original_env { abort unless Kernel.system(env, command) }
35-
end
13+
FileUtils.mkdir_p base_dir
14+
args = %W(
15+
-m spec/support/#{template}.rb
16+
--skip-bootsnap
17+
--skip-bundle
18+
--skip-gemfile
19+
--skip-listen
20+
--skip-spring
21+
--skip-turbolinks
22+
--skip-test-unit
23+
--skip-coffee
24+
--skip-webpack-install
25+
)
26+
27+
command = ['bundle', 'exec', 'rails', 'new', app_dir, *args].join(' ')
28+
29+
env = { 'BUNDLE_GEMFILE' => expanded_gemfile, 'RAILS_ENV' => rails_env }
30+
31+
Bundler.with_original_env { abort unless Kernel.system(env, command) }
3632
end
3733

3834
def full_app_dir

0 commit comments

Comments
 (0)
0