diff --git a/Gemfile b/Gemfile index f517f1b..e35704c 100644 --- a/Gemfile +++ b/Gemfile @@ -6,11 +6,13 @@ gem "pg", "~> 1.5" gem "rake", "~> 13.0" -gem "rspec", "~> 3.0" - -gem "rubocop", "~> 1.21" - -gem "rubocop-rspec", "~> 3.1.0" +group :test do + gem "rspec", "~> 3.0" + gem "rubocop", "~> 1.21" + gem "rubocop-rspec", "~> 3.1.0" + gem "simplecov" + gem "simplecov-cobertura" +end if ENV["RAILS_VERSION"] gem "activerecord", ENV["RAILS_VERSION"] diff --git a/Rakefile b/Rakefile index cca7175..0157e85 100644 --- a/Rakefile +++ b/Rakefile @@ -10,3 +10,16 @@ require "rubocop/rake_task" RuboCop::RakeTask.new task default: %i[spec rubocop] + +namespace :coverage do + desc "Collates all result sets generated by the different test runners" + task :report do + require "simplecov" + + SimpleCov.collate Dir["coverage/**/.resultset.json"] do + add_group "PostgreSQL" do |src_file| + [/postgresql/, /postgre_sql/].any? { |pattern| pattern.match?(src_file.filename) } + end + end + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index fa42b08..1008bf8 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,5 +1,31 @@ # frozen_string_literal: true +require "simplecov" +require "simplecov_json_formatter" +require "active_support/core_ext/object/blank" + +simple_cov_formatters = [SimpleCov::Formatter::JSONFormatter] +simple_cov_formatters << SimpleCov::Formatter::HTMLFormatter unless ENV["CI"] + +SimpleCov.start do + self.formatters = simple_cov_formatters + add_filter "/spec/" + add_group "PostgreSQL" do |src_file| + [/postgresql/, /postgre_sql/].any? { |pattern| pattern.match?(src_file.filename) } + end + + sanitize = ->(filename) { filename.tr(".", "-").tr("~>", "").strip } + ruby_version = sanitize.call(ENV.fetch("RUBY_VERSION", "")) + ar_version = sanitize.call(ENV.fetch("RAILS_VERSION", "")) + coverage_path = [ + "ruby", + ruby_version, + "ar", + ar_version + ].reject(&:blank?).join("-") + + coverage_dir "coverage/#{coverage_path}" +end require "active_record_proxy_adapters" require "active_record_proxy_adapters/connection_handling"