Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set up code coverage metrics with simplecov #12798

Merged
merged 7 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions spec/fixtures/simplecov/customer/.resultset.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{
"RSpec": {
"coverage": {
"/Users/josephjohansen/code/open_food_foundation/openfoodnetwork/app/models/customer.rb": {
"lines": [
null,
null,
null,
null,
null,
null,
null,
null,
null,
1,
1,
null,
1,
null,
1,
null,
1,
1,
1,
1,
1,
1,
1,
null,
1,
1,
1,
null,
1,
1,
1,
null,
1,
1,
null,
null,
null,
null,
null,
8,
1,
6,
null,
2,
2,
null,
1,
null,
1,
0,
null,
null,
1,
null,
1,
31,
null,
null,
1,
31,
null,
null,
1,
24,
null,
null,
1,
0,
0,
0,
null,
0,
null,
null
]
}
},
"timestamp": 1724235565
}
}
68 changes: 68 additions & 0 deletions spec/fixtures/simplecov/voucher/.resultset.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
{
"RSpec": {
"coverage": {
"/Users/josephjohansen/code/open_food_foundation/openfoodnetwork/app/models/voucher.rb": {
"lines": [
null,
null,
1,
1,
null,
1,
null,
1,
null,
null,
null,
1,
null,
null,
null,
null,
1,
null,
1,
null,
1,
15,
null,
null,
null,
null,
null,
null,
null,
null,
1,
null,
3,
null,
null,
null,
null,
null,
null,
null,
null,
3,
null,
null,
null,
1,
1,
null,
null,
1,
1,
null,
null,
1,
1,
null,
null
]
}
},
"timestamp": 1724239602
}
}
30 changes: 30 additions & 0 deletions spec/lib/tasks/simplecov_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# frozen_string_literal: true
dacook marked this conversation as resolved.
Show resolved Hide resolved

require 'spec_helper'
require 'rake'

RSpec.describe "simplecov.rake" do
let(:output_dir) { "tmp/test_#{Process.pid}_coverage" }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not cleaned up after the test run. What do you think about using Dir.mktmpdir?


before(:all) do
Rake.application.rake_require("tasks/simplecov")
end

describe "simplecov:collate_results" do
context "when there are reports to merge" do
let(:input_dir) { Rails.root.join("spec/fixtures/simplecov") }

it "creates a new combined report" do
expect {
Rake.application.invoke_task "simplecov:collate_results[#{input_dir},#{output_dir}]"
}.to change { Dir.exist? output_dir }.
from(false).
to(true).

and change { File.exist? File.join(output_dir, "index.html") }.
from(false).
to(true)
end
end
end
end