Skip to content

Commit

Permalink
ci: Fix coverage collection due to SimpleCov load timing (#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
exoego authored Jun 28, 2023
1 parent 2a1579b commit d83c10f
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 9 deletions.
8 changes: 6 additions & 2 deletions .simplecov_spawn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

SimpleCov.command_name 'spawn'
SimpleCov.at_fork.call(Process.pid)
SimpleCov.formatter SimpleCov::Formatter::CoberturaFormatter
SimpleCov.start
SimpleCov.formatter SimpleCov::Formatter::MultiFormatter.new([
SimpleCov::Formatter::CoberturaFormatter,
])
SimpleCov.start do
add_filter '/spec/'
end
end
11 changes: 11 additions & 0 deletions scripts/rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

# (The MIT License)
# Copyright (c) 2012 Chad Humphries, David Chelimsky, Myron Marston
# Copyright (c) 2009 Chad Humphries, David Chelimsky
# Copyright (c) 2006 David Chelimsky, The RSpec Development Team
# Copyright (c) 2005 Steven Baker

require 'rspec/core'
RSpec::Core::Runner.invoke
50 changes: 50 additions & 0 deletions scripts/rspec_with_simplecov
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

# (The MIT License)
# Copyright (c) 2012 Chad Humphries, David Chelimsky, Myron Marston
# Copyright (c) 2009 Chad Humphries, David Chelimsky
# Copyright (c) 2006 David Chelimsky, The RSpec Development Team
# Copyright (c) 2005 Steven Baker

# Turn on verbose to make sure we not generating any ruby warning
$VERBOSE = true

# So our "did they run the rspec command?" detection logic thinks
# that we run `rspec`.
$0 = 'rspec'

# This is necessary for when `--standalone` is being used.
$:.unshift File.expand_path '../bundle', __dir__

# For the travis build we put the bundle directory up a directory
# so it can be shared among the repos for faster bundle installs.
$:.unshift File.expand_path '../../bundle', __dir__

require 'bundler/setup'

# To use simplecov while running rspec-core's test suite, we must
# load simplecov _before_ loading any of rspec-core's files.
# So, this executable exists purely as a wrapper script that
# first loads simplecov, and then loads rspec.
begin
# Simplecov emits some ruby warnings when loaded, so silence them.
old_verbose = $VERBOSE
$VERBOSE = false

unless ENV['COVERAGE'] && ENV['COVERAGE'].empty? || RUBY_VERSION < '1.9.3'
require 'simplecov'

SimpleCov.start do
add_filter './bundle/'
add_filter './tmp/'
add_filter './spec/'
minimum_coverage(RUBY_PLATFORM == 'java' ? 94 : 97)
end
end
rescue LoadError
ensure
$VERBOSE = old_verbose
end

load File.expand_path('rspec', __dir__)
10 changes: 5 additions & 5 deletions spec/rails/doc/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ paths:
database:
id: 2
name: production
null_sample:
null_sample:
storage_size: 12.3
created_at: '2020-07-17T00:00:00+00:00'
updated_at: '2020-07-17T00:00:00+00:00'
Expand Down Expand Up @@ -207,7 +207,7 @@ paths:
database:
id: 2
name: production
null_sample:
null_sample:
storage_size: 12.3
created_at: '2020-07-17T00:00:00+00:00'
updated_at: '2020-07-17T00:00:00+00:00'
Expand Down Expand Up @@ -272,7 +272,7 @@ paths:
database:
id: 2
name: production
null_sample:
null_sample:
storage_size: 12.3
created_at: '2020-07-17T00:00:00+00:00'
updated_at: '2020-07-17T00:00:00+00:00'
Expand Down Expand Up @@ -374,7 +374,7 @@ paths:
database:
id: 2
name: production
null_sample:
null_sample:
storage_size: 12.3
created_at: '2020-07-17T00:00:00+00:00'
updated_at: '2020-07-17T00:00:00+00:00'
Expand Down Expand Up @@ -438,7 +438,7 @@ paths:
database:
id: 2
name: production
null_sample:
null_sample:
storage_size: 12.3
created_at: '2020-07-17T00:00:00+00:00'
updated_at: '2020-07-17T00:00:00+00:00'
Expand Down
7 changes: 5 additions & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ def assert_run(*args)
end

def run_tests(*args, command:, openapi: false, output: :yaml)
env = { 'OPENAPI' => ('1' if openapi), 'OPENAPI_OUTPUT' => output.to_s }.compact
env = {
'OPENAPI' => ('1' if openapi),
'OPENAPI_OUTPUT' => output.to_s,
}.compact
Bundler.public_send(Bundler.respond_to?(:with_unbundled_env) ? :with_unbundled_env : :with_clean_env) do
Dir.chdir(repo_root) do
assert_run env, 'bundle', 'exec', command, '-r./.simplecov_spawn', *args
Expand All @@ -23,7 +26,7 @@ def run_tests(*args, command:, openapi: false, output: :yaml)
end

def rspec(*args, openapi: false, output: :yaml)
run_tests(*args, command: 'rspec', openapi: openapi, output: output)
run_tests(*args, command: 'scripts/rspec_with_simplecov', openapi: openapi, output: output)
end

def minitest(*args, openapi: false, output: :yaml)
Expand Down

0 comments on commit d83c10f

Please sign in to comment.