Skip to content

Commit ef81fa8

Browse files
authored
Merge pull request #157 from joyofrails/chore/codecov
Add code coverage tools
2 parents 4eb8d03 + 77486b9 commit ef81fa8

File tree

8 files changed

+104
-1
lines changed

8 files changed

+104
-1
lines changed

.github/workflows/verify.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,11 @@ jobs:
9292
RAILS_ENV: test
9393
run: bin/rspec
9494

95+
- name: Upload coverage reports to Codecov
96+
uses: codecov/[email protected]
97+
with:
98+
token: ${{ secrets.CODECOV_TOKEN }}
99+
95100
setup:
96101
name: Setup
97102
runs-on: ubuntu-latest
@@ -164,6 +169,11 @@ jobs:
164169
run: |
165170
npm run test -- --watch=false
166171
172+
- name: Upload coverage reports to Codecov
173+
uses: codecov/[email protected]
174+
with:
175+
token: ${{ secrets.CODECOV_TOKEN }}
176+
167177
assets:
168178
name: Assets
169179
runs-on: ubuntu-latest

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,5 @@ config/litestream/*.yml
7070

7171
# Ignore rspec failure file
7272
spec/failures.txt
73+
74+
/coverage

.simplecov

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# frozen_string_literal: true
2+
3+
if ENV["CI"]
4+
require "simplecov-cobertura"
5+
SimpleCov.formatter = SimpleCov::Formatter::CoberturaFormatter
6+
else
7+
require "simplecov-tailwindcss"
8+
SimpleCov.formatter = SimpleCov::Formatter::TailwindFormatter
9+
end
10+
11+
SimpleCov.profiles.define :joyofrails do
12+
load_profile "test_frameworks"
13+
14+
add_group "Controllers", "app/controllers"
15+
add_group "Content", "app/content"
16+
add_group "Helpers", "app/helpers"
17+
add_group "Jobs", "app/jobs"
18+
add_group "Libraries", "lib"
19+
add_group "Mailers", "app/mailers"
20+
add_group "Models", "app/models"
21+
add_group "Notifiers", "app/notifiers"
22+
add_group "Views", "app/views"
23+
24+
add_filter %r{^/bin/}
25+
add_filter %r{^/config/}
26+
add_filter %r{^/db/}
27+
add_filter %r{^/log/}
28+
add_filter %r{^/storage/}
29+
add_filter %r{^/node_modules/}
30+
add_filter %r{^/docs/}
31+
add_filter %r{^/public/}
32+
add_filter %r{^/tmp/}
33+
add_filter %r{^/vendor/}
34+
35+
add_filter %r{^/app/assets/}
36+
add_filter %r{^/app/javascript/}
37+
38+
add_filter %r{^/lib/assets/}
39+
add_filter %r{^/lib/rails-wasm/}
40+
41+
track_files "{app,lib}/**/*.rb"
42+
end
43+
44+
SimpleCov.start :joyofrails

Gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ group :test do
5757
gem "capybara" # Acceptance test framework for web applications [https://github.com/teamcapybara/capybara]
5858
gem "selenium-webdriver" # Ruby bindings for Selenium [https://www.rubydoc.info/gems/selenium-webdriver/frames]
5959
gem "cuprite", git: "https://github.com/rubycdp/cuprite"
60+
gem "simplecov", require: false # Code coverage for Ruby [https://github.com/simplecov-ruby/simplecov]
61+
gem "simplecov-tailwindcss", require: false # Alternative HTML formatter for SimpleCov [https://github.com/chiefpansancolt/simplecov-tailwindcss]
62+
gem "simplecov-cobertura", require: false # Produces Cobertura formatted XML from SimpleCov. [https://github.com/dashingrocket/simplecov-cobertura]
6063
gem "webmock", require: false # Library for stubbing HTTP requests [https://github.com/bblimke/webmock]
6164
end
6265

Gemfile.lock

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ GEM
138138
reline (>= 0.3.8)
139139
device_detector (1.1.2)
140140
diff-lcs (1.5.1)
141+
docile (1.4.0)
141142
dotenv (3.1.0)
142143
drb (2.2.1)
143144
dry-cli (1.0.0)
@@ -432,6 +433,17 @@ GEM
432433
rubyzip (>= 1.2.2, < 3.0)
433434
websocket (~> 1.0)
434435
sexp_processor (4.17.1)
436+
simplecov (0.22.0)
437+
docile (~> 1.1)
438+
simplecov-html (~> 0.11)
439+
simplecov_json_formatter (~> 0.1)
440+
simplecov-cobertura (2.1.0)
441+
rexml
442+
simplecov (~> 0.19)
443+
simplecov-html (0.12.3)
444+
simplecov-tailwindcss (2.2.0)
445+
simplecov (~> 0.16)
446+
simplecov_json_formatter (0.1.4)
435447
sitepress-core (4.0.2)
436448
mime-types (>= 2.99)
437449
sitepress-rails (4.0.2)
@@ -564,6 +576,9 @@ DEPENDENCIES
564576
rspec-rails
565577
ruby_wasm (~> 2.5)
566578
selenium-webdriver
579+
simplecov
580+
simplecov-cobertura
581+
simplecov-tailwindcss
567582
sitepress-rails
568583
solid_cache
569584
solid_queue

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# joyofrails.com
22

3+
[![Build Status](https://github.com/joyofrails/joyofrails.com/workflows/verify.yml/badge.svg)](https://github.com/joyofrails/joyofrails.com/actions)
4+
[![Deploy Status](https://github.com/joyofrails/joyofrails.com/workflows/deploy.yml/badge.svg)](https://github.com/joyofrails/joyofrails.com/actions)
5+
[![Code Coverage](https://codecov.io/gh/joyofrails/joyofrails.com/graph/badge.svg?token=PRKDIXWQ7I)](https://codecov.io/gh/joyofrails/joyofrails.com)
6+
37
A place to learn and celebrate the joy of using Ruby on Rails
48

59
https://www.joyofrails.com
@@ -20,9 +24,10 @@ Building a Rails application to help people learn more about building Rails appl
2024

2125
Use a Ruby version manager to install and manage Ruby versions, such as
2226

27+
- [chruby](https://github.com/postmodern/chruby)
2328
- [asdf](https://asdf-vm.com/)
2429
- [rvm](https://rvm.io/)
25-
- [chruby](https://github.com/postmodern/chruby)
30+
- [rbenv](https://github.com/rbenv/rbenv)
2631

2732
To use YJIT, Rust must first be installed and be found on `PATH`:
2833

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
require "rails_helper"
2+
3+
RSpec.describe Emails::HeartbeatJob do
4+
describe "#perform" do
5+
it "sends a heartbeat email to admin users to exercise email provider integration" do
6+
admin_user = FactoryBot.create(:admin_user)
7+
8+
Emails::HeartbeatJob.perform_later
9+
10+
perform_enqueued_jobs_and_subsequently_enqueued_jobs
11+
12+
expect(ActionMailer::Base.deliveries.count).to eq(1)
13+
14+
mail = find_mail_to(admin_user.email)
15+
16+
expect(mail.subject).to eq("It’s alive!")
17+
end
18+
end
19+
end

spec/rails_helper.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1+
# frozen_string_literal: true
2+
13
# This file is copied to spec/ when you run 'rails generate rspec:install'
24
require "spec_helper"
35
ENV["RAILS_ENV"] ||= "test"
6+
7+
require "simplecov"
8+
49
require_relative "../config/environment"
510
# Prevent database truncation if the environment is production
611
abort("The Rails environment is running in production mode!") if Rails.env.production?

0 commit comments

Comments
 (0)