|
| 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 |
0 commit comments