8000 Cleaner test application setup by deivid-rodriguez · Pull Request #5797 · activeadmin/activeadmin · GitHub
[go: up one dir, main page]

Skip to content

Cleaner test application setup #5797

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jul 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 27 additions & 15 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,11 @@ version: 2.1
.create_test_app: &create_test_app
run:
name: Create test app
command: PARALLEL_TEST_PROCESSORS=4 bin/rake setup
command: COVERAGE=true PARALLEL_TEST_PROCESSORS=4 bin/rake setup

.restore_test_reporter: &restore_test_reporter
attach_workspace:
at: bin

.restore_coverage: &restore_coverage
attach_workspace:
Expand All @@ -55,7 +59,7 @@ version: 2.1
.format_coverage: &format_coverage
run:
name: Format coverage
command: coverage/test-reporter format-coverage --input-type simplecov --output coverage/codeclimate.$CIRCLE_JOB.json
command: bin/test-reporter format-coverage --input-type simplecov --output coverage/codeclimate.$CIRCLE_JOB.json

.save_coverage: &save_coverage
persist_to_workspace:
Expand All @@ -67,16 +71,15 @@ version: 2.1
run:
name: Upload coverage results to Code Climate
command: |
# The parts number is the total jobs count plus the lint job,
# This number should match the number of jobs under upload_coverage/requires
coverage/test-reporter sum-coverage coverage/codeclimate.*.json --parts 16 --output coverage/codeclimate.total.json
coverage/test-reporter upload-coverage --input coverage/codeclimate.total.json
# The parts number should match the number of jobs under upload_coverage/requires
bin/test-reporter sum-coverage coverage/codeclimate.*.json --parts 20 --output coverage/codeclimate.total.json
bin/test-reporter upload-coverage --input coverage/codeclimate.total.json

.save_test_app_to_workspace: &save_test_app_to_workspace
.save_test_app: &save_test_app
persist_to_workspace:
root: tmp/rails
paths:
- rails-*
- rails_*

.restore_test_app_from_workspace: &restore_test_app_from_workspace
attach_workspace:
Expand Down Expand Up @@ -138,7 +141,7 @@ version: 2.1
- *save_cache
- *restore_test_app_from_workspace
- *restore_test_times
- *restore_coverage
- *restore_test_reporter
- *run_tests
- *run_features
- *format_coverage
Expand All @@ -152,9 +155,12 @@ version: 2.1
- *copy_current_gemfile
- *restore_cache
- *install_dependencies
- *restore_test_reporter
- *save_cache
- *create_test_app
- *save_test_app_to_workspace
- *format_coverage
- *save_coverage
- *save_test_app

jobs:
setup_coverage:
Expand All @@ -165,12 +171,12 @@ jobs:
- run:
name: Download Code Climate test-reporter
command: |
mkdir coverage
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-0.6.3-linux-amd64 > coverage/test-reporter
chmod +x coverage/test-reporter
mkdir bin
curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-0.6.3-linux-amd64 > bin/test-reporter
chmod +x bin/test-reporter

- persist_to_workspace:
root: coverage
root: bin
paths:
- test-reporter

Expand All @@ -181,6 +187,7 @@ jobs:
CC_TEST_REPORTER_ID: 8d5fcf7abea6d56c625104a9d1a81140a588a7f546f4fa9de9bc6ffc8feaaf70

steps:
- *restore_test_reporter
- *restore_coverage
- *submit_coverage

Expand Down Expand Up @@ -245,7 +252,7 @@ jobs:
- *install_dependencies
- *save_cache
- *generate_docs
- *restore_coverage
- *restore_test_reporter
- *run_lints
- *run_bug_report_template
- *format_coverage
Expand Down Expand Up @@ -520,6 +527,11 @@ workflows:
requires:
- lint_and_docs

- testapp50
- testapp51
- testapp52
- testapp60

- ruby24rails50
- ruby24rails51
- ruby24rails52
Expand Down
8 changes: 4 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ GEM
responders
warden (~> 1.2.3)
diff-lcs (1.3)
docile (1.3.1)
docile (1.3.2)
draper (3.1.0)
actionpack (>= 5.0)
activemodel (>= 5.0)
Expand Down Expand Up @@ -187,8 +187,8 @@ GEM
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
jruby-openssl (0.10.1-java)
json (2.1.0)
json (2.1.0-java)
json (2.2.0)
json (2.2.0-java)
kaminari (1.1.1)
activesupport (>= 4.1.0)
kaminari-actionview (= 1.1.1)
Expand Down Expand Up @@ -348,7 +348,7 @@ GEM
selenium-webdriver (3.141.0)
childprocess (~> 0.5)
rubyzip (~> 1.2, >= 1.2.2)
simplecov (0.16.1)
simplecov (0.17.0)
docile (~> 1.1)
json (>= 1.8, < 3)
simplecov-html (~> 0.10.0)
Expand Down
4 changes: 2 additions & 2 deletions features/support/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
require f
end

require "active_admin/dependency"
require_relative "../../tasks/test_application"

require_relative "../../tmp/rails/rails-#{ActiveAdmin::Dependency.rails_version}/config/environment"
require "#{ActiveAdmin::TestApplication.new.full_app_dir}/config/environment.rb"

require_relative 'rails'

Expand Down
8 changes: 4 additions & 4 deletions gemfiles/rails_50.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ GEM
responders
warden (~> 1.2.3)
diff-lcs (1.3)
docile (1.3.1)
docile (1.3.2)
draper (3.1.0)
actionpack (>= 5.0)
activemodel (>= 5.0)
Expand Down Expand Up @@ -160,8 +160,8 @@ GEM
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
jruby-openssl (0.10.1-java)
json (2.1.0)
json (2.1.0-java)
json (2.2.0)
json (2.2.0-java)
kaminari (1.1.1)
activesupport (>= 4.1.0)
kaminari-actionview (= 1.1.1)
Expand Down Expand Up @@ -287,7 +287,7 @@ GEM
selenium-webdriver (3.141.0)
childprocess (~> 0.5)
rubyzip (~> 1.2, >= 1.2.2)
simplecov (0.16.1)
simplecov (0.17.0)
docile (~> 1.1)
json (>= 1.8, < 3)
simplecov-html (~> 0.10.0)
Expand Down
8 changes: 4 additions & 4 deletions gemfiles/rails_51.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ GEM
responders
warden (~> 1.2.3)
diff-lcs (1.3)
docile (1.3.1)
docile (1.3.2)
draper (3.1.0)
actionpack (>= 5.0)
activemodel (>= 5.0)
Expand Down Expand Up @@ -160,8 +160,8 @@ GEM
railties (>= 4.2.0)
thor (>= 0.14, < 2.0)
jruby-openssl (0.10.1-java)
json (2.1.0)
json (2.1.0-java)
json (2.2.0)
json (2.2.0-java)
kaminari (1.1.1)
activesupport (>= 4.1.0)
kaminari-actionview (= 1.1.1)
Expand Down Expand Up @@ -287,7 +287,7 @@ GEM
selenium-webdriver (3.141.0)
childprocess (~> 0.5)
rubyzip (~> 1.2, >= 1.2.2)
simplecov (0.16.1)
simplecov (0.17.0)
docile (~> 1.1)
json (>= 1.8, < 3)
simplecov-html (~> 0.10.0)
Expand Down
4 changes: 2 additions & 2 deletions gemfiles/rails_60.gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ GEM
responders
warden (~> 1.2.3)
diff-lcs (1.3)
docile (1.3.1)
docile (1.3.2)
draper (3.1.0)
actionpack (>= 5.0)
activemodel (>= 5.0)
Expand Down Expand Up @@ -310,7 +310,7 @@ GEM
selenium-webdriver (3.141.0)
childprocess (~> 0.5)
rubyzip (~> 1.2, >= 1.2.2)
simplecov (0.16.1)
simplecov (0.17.0)
docile (~> 1.1)
json (>= 1.8, < 3)
simplecov-html (~> 0.10.0)
Expand Down
4 changes: 0 additions & 4 deletions lib/active_admin/dependency.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,6 @@ def self.[](name)
Matcher.new name.to_s
end

def self.rails_version
rails.spec.version
end

def self.supports_zeitwerk?
rails >= "6.0.0.beta3" && RUBY_ENGINE != "jruby"
end
Expand Down
4 changes: 2 additions & 2 deletions spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

ENV['RAILS_ENV'] = 'test'

require "active_admin/dependency"
require_relative "../tasks/test_application"

require_relative "../tmp/rails/rails-#{ActiveAdmin::Dependency.rails_version}/config/environment"
require "#{ActiveAdmin::TestApplication.new.full_app_dir}/config/environment.rb"

require 'rspec/rails'

Expand Down
53 changes: 0 additions & 53 deletions tasks/application_generator.rb

This file was deleted.

15 changes: 8 additions & 7 deletions tasks/local.rake
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
require_relative "application_generator"

desc 'Run a command against the local sample application'
task :local do
app_folder = ActiveAdmin::ApplicationGenerator.new(
require_relative "test_application"

test_application = ActiveAdmin::TestApplication.new(
rails_env: 'development',
template: 'rails_template_with_data'
).generate
)

test_application.generate

# Discard the "local" argument (name of the task)
argv = ARGV[1..-1]
Expand All @@ -17,10 +19,9 @@ task :local do
end

command = ['bundle', 'exec', *argv].join(' ')
gemfile = ENV['BUNDLE_GEMFILE'] || File.expand_path("../Gemfile", __dir__)
env = { 'BUNDLE_GEMFILE' => gemfile }
env = { 'BUNDLE_GEMFILE' => test_application.expanded_gemfile }

Dir.chdir(app_folder) do
Dir.chdir(test_application.app_dir) do
Bundler.with_original_env { Kernel.exec(env, command) }
end
end
Expand Down
47 changes: 42 additions & 5 deletions tasks/test.rake
Original file line number Diff line number Diff line change
@@ -1,11 +1,48 @@
require_relative "application_generator"

desc "Run the full suite using parallel_tests to run on multiple cores"
task test: [:setup, :spec, :cucumber]

desc "Create a test rails app for the parallel specs to run against"
task :setup, [:rails_env, :template] do |_t, opts|
ActiveAdmin::ApplicationGenerator.new(opts).generate
desc "Create a test rails app for the parallel specs to run against if it doesn't exist already"
task setup: :"setup:create"

namespace :setup do
desc "Forcefully create a test rails app for the parallel specs to run against"
task :force, [:rails_env, :template] => [:require, :rm, :run]

desc "Create a test rails app for the parallel specs to run against if it doesn't exist already"
task :create, [:rails_env, :template] => [:require, :guard, :run]

desc "Makes test app creation code available"
task :require do
if ENV["COVERAGE"] == "true"
require "simplecov"

SimpleCov.command_name "test app creation"
end

require_relative "test_application"
end

desc "Create a test rails app for the parallel specs to run against"
task :run, [:rails_env, :template] do |_t, opts|
ActiveAdmin::TestApplication.new(opts).generate
end

desc "Aborts if the test app already exists"
task :guard, [:rails_env, :template] do |_t, opts|
test_app = ActiveAdmin::TestApplication.new(opts)

app_dir = test_app.app_dir

if File.exist? app_dir
abort "test app #{app_dir} already exists; skipping test app generation"
end
end

task :rm, [:rails_env, :template] do |_t, opts|
test_app = ActiveAdmin::TestApplication.new(opts)

FileUtils.rm_rf test_app.app_dir
end
end

task spec: :"spec:all"
Expand Down
Loading
0