Skip to content

Commit

Permalink
simpler test tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
ddnexus committed Apr 19, 2021
1 parent e5ee4e7 commit 5e6f749
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 38 deletions.
81 changes: 43 additions & 38 deletions Rakefile
Expand Up @@ -4,48 +4,53 @@ require 'bundler/setup'
require 'bundler/gem_tasks'
require 'rake/testtask'

# The extras that override the built-in methods need to be tested in isolation in order
# to prevent them to change also the behavior and the result of the built-in tests.
# We create a single task for each of them
@test_tasks = {}
# Separate tasks for each test that must run a process
# in isolation in order to avoid affecting also other tests.
test_tasks = {}

def define_test_task(name, *files)
@test_tasks[name] = files
Rake::TestTask.new(name) do |t|
t.libs += %w[test lib]
t.test_files = FileList[*files]
%w[ headers
i18n
overflow
support
oj_shared
shared
trim
items_trim
items_countless
items_elasticsearch
elasticsearch_rails
searchkick
].each do |name|
task_name = :"test_#{name}"
file_path = "test/**/#{name}_test.rb"
test_tasks[task_name] = file_path
Rake::TestTask.new(task_name) do |t|
test_files = FileList.new file_path
t.test_files = test_files
t.description = "Run tests in #{test_files.join(', ')}"
end
end

define_test_task :test_extra_items_and_countless, 'test/**/items_and_countless_test.rb'
define_test_task :test_extra_items_and_elasticsearch, 'test/**/items_and_elasticsearch_test.rb'
define_test_task :test_extra_headers, 'test/**/headers_test.rb'
define_test_task :test_extra_i18n, 'test/**/i18n_test.rb'
define_test_task :test_extra_overflow, 'test/**/overflow_test.rb'
define_test_task :test_extra_trim, 'test/**/trim_test.rb'
define_test_task :test_extra_elasticsearch, 'test/**/elasticsearch_rails_test.rb', 'test/**/searchkick_test.rb'
define_test_task :test_support, 'test/**/support_test.rb'
define_test_task :test_shared,'test/**/oj_shared_test.rb'
define_test_task :test_shared,'test/**/shared_test.rb'
define_test_task :test_shared_items_trim, 'test/**/shared_items_trim_test.rb'

# We exclude the files of the other tasks from the :test_main task
Rake::TestTask.new(:test_main) do |t|
t.libs += %w[test lib]
t.test_files = FileList.new
.include('test/**/*_test.rb')
.exclude(@test_tasks.values.flatten)
# Collect the other tests
Rake::TestTask.new(:test_others) do |t|
test_files = FileList.new.include('test/**/*_test.rb').exclude(*test_tasks.values)
t.test_files = test_files
t.description = "Run tests in #{test_files.join(', ')}"
end

desc 'Run all the individual test tasks'
task test: [:test_main, *@test_tasks.keys]
desc "Run all the test tasks: #{test_tasks.keys.join(', ')}"
task test: [*test_tasks.keys, :test_others]

task default: ( if ENV['RUN_RUBOCOP'] == 'true'
require 'rubocop/rake_task'
RuboCop::RakeTask.new(:rubocop) do |t|
t.options = `git ls-files | grep -E '\\.rb$'`.split("\n") # limit rubocop to the files in the repo
end
%i[test rubocop]
else
[:test]
end )

task default: (if ENV['RUN_RUBOCOP'] == 'true'
require 'rubocop/rake_task'
RuboCop::RakeTask.new(:rubocop) do |t|
t.options = `git ls-files | grep -E '\\.rb$'`.split("\n") # limit rubocop to the files in the repo
end
%i[test rubocop]
else
[:test]
end)
# get the full list of of all the test tasks
# (and test files that each task run) with:
# rake -D test_*
File renamed without changes.
File renamed without changes.

0 comments on commit 5e6f749

Please sign in to comment.