Skip to content

Commit ec35613

Browse files
committed
Add code coverage
1 parent 08f4ff4 commit ec35613

File tree

5 files changed

+51
-9
lines changed

5 files changed

+51
-9
lines changed

.github/workflows/ruby.yml

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,22 @@ name: Ruby
99

1010
on:
1111
push:
12+
branches:
13+
- '**' # run on all branches
14+
tags-ignore:
15+
- '**' # skip all tags
1216
pull_request_target:
13-
types: [opened, reopened]
17+
types: [opened, reopened, synchronize]
1418

1519
jobs:
1620
test:
17-
1821
runs-on: ubuntu-latest
1922
strategy:
2023
fail-fast: false
2124
matrix:
2225
ruby-version: ['3.1']
2326
steps:
24-
- uses: actions/checkout@v3
27+
- uses: actions/checkout@v5
2528
- name: Set up Ruby
2629
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
2730
# change this to (see https://github.com/ruby/setup-ruby#versioning):
@@ -30,8 +33,13 @@ jobs:
3033
ruby-version: ${{ matrix.ruby-version }}
3134
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
3235
- name: set up config file
33-
run: cp config/config.test.rb config/config.rb
36+
run: cp config/config.test.rb config/config.rb
3437
- name: Run tests
3538
env:
3639
UT_APIKEY: ${{ secrets.UT_APIKEY }}
3740
run: bundle exec rake test TESTOPTS="-v"
41+
- name: Upload coverage to Codecov
42+
uses: codecov/codecov-action@v5
43+
with:
44+
flags: ${{ matrix.ruby-version }}
45+
verbose: true

.gitignore

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
*.gem
22
.DS_Store
3-
config/config.rb
3+
/config/config.rb
44

55
# Specific to IntelliJ
66
.idea/
77

88
# Specific to rbenv
9-
.ruby-version
9+
.ruby-version
10+
11+
# Codecov local cache
12+
/coverage/

Gemfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@ gemspec
77
gem 'pry'
88
gem 'rake'
99
gem 'rubocop', '~> 1.43'
10+
gem "simplecov", require: false
11+
gem "simplecov-cobertura", require: false

Gemfile.lock

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ GEM
3636
coderay (1.1.3)
3737
concurrent-ruby (1.3.5)
3838
connection_pool (2.5.4)
39+
docile (1.4.1)
3940
drb (2.2.3)
4041
excon (1.3.1)
4142
logger
@@ -50,11 +51,11 @@ GEM
5051
faraday (>= 1, < 3)
5152
faraday-multipart (1.1.1)
5253
multipart-post (~> 2.0)
53-
faraday-net_http (3.4.1)
54-
net-http (>= 0.5.0)
54+
faraday-net_http (3.4.2)
55+
net-http (~> 0.5)
5556
i18n (1.14.7)
5657
concurrent-ruby (~> 1.0)
57-
json (2.15.2)
58+
json (2.16.0)
5859
language_server-protocol (3.17.0.5)
5960
lint_roller (1.1.0)
6061
logger (1.7.0)
@@ -84,6 +85,7 @@ GEM
8485
rainbow (3.1.1)
8586
rake (13.3.1)
8687
regexp_parser (2.11.3)
88+
rexml (3.4.4)
8789
rubocop (1.81.7)
8890
json (~> 2.3)
8991
language_server-protocol (~> 3.17.0.2)
@@ -100,6 +102,15 @@ GEM
100102
prism (~> 1.4)
101103
ruby-progressbar (1.13.0)
102104
securerandom (0.4.1)
105+
simplecov (0.22.0)
106+
docile (~> 1.1)
107+
simplecov-html (~> 0.11)
108+
simplecov_json_formatter (~> 0.1)
109+
simplecov-cobertura (3.1.0)
110+
rexml
111+
simplecov (~> 0.19)
112+
simplecov-html (0.13.2)
113+
simplecov_json_formatter (0.1.4)
103114
tzinfo (2.0.6)
104115
concurrent-ruby (~> 1.0)
105116
unicode-display_width (3.2.0)
@@ -119,6 +130,8 @@ DEPENDENCIES
119130
pry
120131
rake
121132
rubocop (~> 1.43)
133+
simplecov
134+
simplecov-cobertura
122135

123136
BUNDLED WITH
124137
2.6.9

test/test_case.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
11
# frozen_string_literal: true
2+
# Start simplecov if this is a coverage task or if it is run in the CI pipeline
3+
if ENV['COVERAGE'] || ENV['CI']
4+
require 'simplecov'
5+
require 'simplecov-cobertura'
6+
7+
SimpleCov.formatters = SimpleCov::Formatter::MultiFormatter.new([
8+
SimpleCov::Formatter::HTMLFormatter,
9+
SimpleCov::Formatter::CoberturaFormatter, # writes coverage/cobertura.xml
10+
])
11+
12+
SimpleCov.start do
13+
enable_coverage :branch
14+
add_filter %w[/test/ /config/]
15+
end
16+
end
17+
218
require 'bundler/setup'
319
require 'pry'
420
require 'minitest/autorun'

0 commit comments

Comments
 (0)