Skip to content

Commit fa8c75d

Browse files
committed
Add Codecov setup with SimpleCov for unit test coverage tracking
- Add simplecov dev dependency to gemspec - Create spec/test_helper.rb to initialise SimpleCov before tests - Update Rakefile unit_tests task to load test_helper via ruby_opts - Add .codecov.yml with 80% patch coverage target - Add .circleci/config.yml with test job and codecov/upload step Made-with: Cursor
1 parent b1a57bf commit fa8c75d

5 files changed

Lines changed: 86 additions & 0 deletions

File tree

.circleci/config.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
version: 2.1
2+
3+
orbs:
4+
codecov: codecov/codecov@5.0.3
5+
6+
defaults: &defaults
7+
working_directory: ~/project
8+
docker:
9+
- image: cimg/ruby:3.2
10+
11+
jobs:
12+
bundle_install:
13+
<<: *defaults
14+
steps:
15+
- checkout
16+
- restore_cache:
17+
key: gem-cache-v1-{{ checksum "Gemfile.lock" }}
18+
- run:
19+
name: Install dependencies
20+
command: bundle install --jobs 4 --retry 3
21+
- save_cache:
22+
key: gem-cache-v1-{{ checksum "Gemfile.lock" }}
23+
paths:
24+
- vendor/bundle
25+
26+
test:
27+
<<: *defaults
28+
steps:
29+
- checkout
30+
- restore_cache:
31+
key: gem-cache-v1-{{ checksum "Gemfile.lock" }}
32+
- run:
33+
name: Install dependencies
34+
command: bundle install --jobs 4 --retry 3
35+
- run:
36+
name: Run unit tests with coverage
37+
command: bundle exec rake unit_tests
38+
- codecov/upload:
39+
token: CODECOV_TOKEN
40+
slug: trolley/ruby-sdk
41+
files: coverage/.resultset.json
42+
when: always
43+
44+
workflows:
45+
version: 2
46+
build:
47+
jobs:
48+
- test:
49+
context: org-global
50+
filters:
51+
tags:
52+
ignore: /.*/

.codecov.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
codecov:
2+
require_ci_to_pass: true
3+
notify:
4+
after_n_builds: 1
5+
wait_for_ci: true
6+
allow_coverage_offsets: true
7+
ci:
8+
- circleci.com
9+
10+
coverage:
11+
precision: 2
12+
round: down
13+
range: "70...100"
14+
status:
15+
project:
16+
default:
17+
target: auto
18+
threshold: 1%
19+
patch:
20+
default:
21+
target: 80%
22+
23+
comment:
24+
layout: "reach, diff, flags, files"
25+
behavior: default

Rakefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ require 'rake/testtask'
33

44
Rake::TestTask.new(:unit_tests) do |t|
55
t.libs << 'lib'
6+
t.libs << 'spec'
7+
t.ruby_opts << '-r test_helper'
68
t.test_files = FileList['spec/unit/*Test.rb']
79
end
810

spec/test_helper.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
require 'simplecov'
2+
3+
SimpleCov.start do
4+
add_filter '/spec/'
5+
coverage_dir 'coverage'
6+
end

trolley.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Gem::Specification.new do |s|
1414
s.add_development_dependency 'dotenv', '~> 2'
1515
s.add_development_dependency 'rake', '~> 13'
1616
s.add_development_dependency 'rubocop', '~> 1'
17+
s.add_development_dependency 'simplecov', '~> 0.22'
1718
s.add_development_dependency 'test-unit', '~> 3'
1819
s.metadata = {
1920
"bug_tracker_uri" => "https://github.com/trolley/ruby-sdk/issues",

0 commit comments

Comments
 (0)