Skip to content

Commit 314b7d1

Browse files
committed
Update to Minitest 6; update testing dependencies; add and configure simplecov
1 parent ae29e7d commit 314b7d1

File tree

3 files changed

+61
-8
lines changed

3 files changed

+61
-8
lines changed

.simplecov

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# frozen_string_literal: true
2+
3+
# SimpleCov configuration file (auto-loaded before test suite)
4+
# This keeps test_helper.rb clean and follows best practices
5+
6+
SimpleCov.start do
7+
# Use SimpleFormatter for terminal-only output (no HTML generation)
8+
formatter SimpleCov::Formatter::SimpleFormatter
9+
10+
# Track coverage for the lib directory (gem source code)
11+
add_filter "/test/"
12+
13+
# Exclude Rails engine components that require integration testing
14+
# These are tested via Appraisal with a full Rails app
15+
add_filter "/lib/profitable/engine.rb"
16+
add_filter "/app/"
17+
18+
# Exclude the main profitable.rb entry point - it loads the engine and
19+
# defines the Profitable module. Our unit tests use a test-specific
20+
# Profitable module (defined in test_helper.rb) to avoid Rails dependencies.
21+
# The core logic is tested via the individual lib/profitable/*.rb files.
22+
add_filter "/lib/profitable.rb"
23+
24+
# Track the lib directory (core gem logic)
25+
track_files "lib/**/*.rb"
26+
27+
# Enable branch coverage for more detailed metrics
28+
enable_coverage :branch
29+
30+
# Set minimum coverage threshold for the core calculation logic
31+
# The Rails engine/controllers are tested separately via Appraisal
32+
minimum_coverage line: 80, branch: 70
33+
34+
# Disambiguate parallel test runs
35+
command_name "Job #{ENV['TEST_ENV_NUMBER']}" if ENV['TEST_ENV_NUMBER']
36+
end
37+
38+
# Print coverage summary to terminal after tests complete
39+
SimpleCov.at_exit do
40+
SimpleCov.result.format!
41+
puts "\n" + "=" * 60
42+
puts "COVERAGE SUMMARY"
43+
puts "=" * 60
44+
puts "Line Coverage: #{SimpleCov.result.covered_percent.round(2)}%"
45+
puts "Branch Coverage: #{SimpleCov.result.coverage_statistics[:branch]&.percent&.round(2) || 'N/A'}%"
46+
puts "=" * 60
47+
end

Gemfile

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,21 @@
22

33
source "https://rubygems.org"
44

5-
# Specify your gem's dependencies in profitable.gemspec
5+
# Specify your gem's dependencies in slugifiable.gemspec
66
gemspec
77

88
gem "rake", "~> 13.0"
99

10-
group :development do
11-
gem "appraisal", "~> 2.5"
12-
end
10+
group :development, :test do
11+
gem "appraisal"
12+
gem "minitest", "~> 6.0"
13+
gem "minitest-mock"
14+
gem "minitest-reporters"
15+
gem "rack-test"
16+
gem "simplecov", require: false
17+
gem "sqlite3", ">= 2.1"
1318

14-
group :test do
15-
gem "minitest", "~> 5.0"
16-
gem "minitest-reporters", "~> 1.6"
1719
gem "mocha", "~> 2.1"
1820
gem "activerecord", ">= 7.0"
1921
gem "actionview", ">= 7.0"
20-
gem "sqlite3"
2122
end

test/test_helper.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,16 @@
22

33
$LOAD_PATH.unshift File.expand_path("../lib", __dir__)
44

5+
# SimpleCov must be loaded BEFORE any application code
6+
# Configuration is auto-loaded from .simplecov file
7+
require "simplecov"
8+
59
require "bundler/setup"
610
require "active_record"
711
require "active_support/all"
812
require "action_view"
913
require "minitest/autorun"
14+
require "minitest/mock"
1015
require "minitest/reporters"
1116
require "mocha/minitest"
1217

0 commit comments

Comments
 (0)