Skip to content

Commit

Permalink
Add coverage report
Browse files Browse the repository at this point in the history
  • Loading branch information
mateuscruz committed Nov 30, 2024
1 parent 7c563d2 commit ad1c7c0
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 5 deletions.
12 changes: 7 additions & 5 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
13 changes: 13 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
26 changes: 26 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -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"

Expand Down

0 comments on commit ad1c7c0

Please sign in to comment.