active_model_serializers/Rakefile
João Moura 952ab0438f AMS Benchmark tests #832
Adding a benchmak test structure to help contributors to keep track
of how their PR will impact overall performance.

It enables developers to create test inside of tests/benchmark.

This implementation adds a rake task: ```rake benchmark``` that checkout
one commit before, run the test of  tests/benchmark, then mover back to
the last commit and run it again. By comparing the benchmark results between
both commits the contributor will notice if and how much  his contribution
will impact overall performance.
2016-03-09 12:42:25 -06:00

112 lines
3.0 KiB
Ruby

begin
require 'simplecov'
rescue LoadError
end
require 'bundler/gem_tasks'
begin
require 'rubocop'
require 'rubocop/rake_task'
rescue LoadError
else
Rake::Task[:rubocop].clear if Rake::Task.task_defined?(:rubocop)
require 'rbconfig'
# https://github.com/bundler/bundler/blob/1b3eb2465a/lib/bundler/constants.rb#L2
windows_platforms = /(msdos|mswin|djgpp|mingw)/
if RbConfig::CONFIG['host_os'] =~ windows_platforms
desc 'No-op rubocop on Windows-- unsupported platform'
task :rubocop do
puts 'Skipping rubocop on Windows'
end
elsif defined?(::Rubinius)
desc 'No-op rubocop to avoid rbx segfault'
task :rubocop do
puts 'Skipping rubocop on rbx due to segfault'
puts 'https://github.com/rubinius/rubinius/issues/3499'
end
else
Rake::Task[:rubocop].clear if Rake::Task.task_defined?(:rubocop)
desc 'Execute rubocop'
RuboCop::RakeTask.new(:rubocop) do |task|
task.options = ['--display-cop-names', '--display-style-guide']
task.fail_on_error = true
end
end
end
require 'rake/testtask'
Rake::TestTask.new do |t|
t.libs << 'test'
t.test_files = FileList['test/**/*_test.rb']
t.ruby_opts = ['-r./test/test_helper.rb']
t.verbose = true
end
desc 'Run isolated tests'
task isolated: ['test:isolated']
namespace :test do
task :isolated do
desc 'Run isolated tests for Railtie'
require 'shellwords'
dir = File.dirname(__FILE__)
dir = Shellwords.shellescape(dir)
isolated_test_files = FileList['test/**/*_test_isolated.rb']
# https://github.com/rails/rails/blob/3d590add45/railties/lib/rails/generators/app_base.rb#L345-L363
_bundle_command = Gem.bin_path('bundler', 'bundle')
require 'bundler'
Bundler.with_clean_env do
isolated_test_files.all? do |test_file|
command = "-w -I#{dir}/lib -I#{dir}/test #{Shellwords.shellescape(test_file)}"
full_command = %("#{Gem.ruby}" #{command})
system(full_command)
end or fail 'Failures' # rubocop:disable Style/AndOr
end
end
end
if ENV['RAILS_VERSION'].to_s > '4.0' && RUBY_ENGINE == 'ruby'
task default: [:isolated, :test, :rubocop]
else
task default: [:test, :rubocop]
end
desc 'CI test task'
task :ci => [:default]
require 'git'
require 'benchmark'
Rake::TestTask.new :benchmark_tests do |t|
t.libs << "test"
t.test_files = FileList['test/**/*_benchmark.rb']
t.ruby_opts = ['-r./test/test_helper.rb']
t.verbose = true
end
task :benchmark do
@git = Git.init('.')
ref = @git.current_branch
actual = run_benchmark_spec ref
master = run_benchmark_spec 'master'
@git.checkout(ref)
puts "\n\nResults ============================\n"
puts "------------------------------------~> (Branch) MASTER"
puts master
puts "------------------------------------\n\n"
puts "------------------------------------~> (Actual Branch) #{ref}"
puts actual
puts "------------------------------------"
end
def run_benchmark_spec(ref)
@git.checkout(ref)
response = Benchmark.realtime { Rake::Task['benchmark_tests'].invoke }
Rake::Task['benchmark_tests'].reenable
response
end