repo
stringlengths
5
92
file_url
stringlengths
80
287
file_path
stringlengths
5
197
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
7 values
commit_sha
stringlengths
40
40
retrieved_at
stringdate
2026-01-04 15:37:27
2026-01-04 17:58:21
truncated
bool
2 classes
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/encodings/spec/simple_spec.rb
test_projects/encodings/spec/simple_spec.rb
require_relative "spec_helper" describe Fun do it "call things" do expect(subject.🇯🇵).to eq "tada!" end end
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/encodings/spec/spec_helper.rb
test_projects/encodings/spec/spec_helper.rb
# frozen_string_literal: true require "simplecov" SimpleCov.start do track_files "lib/euc_jp_not_declared_tracked.rb" end require_relative "../lib/utf8.rb" require_relative "../lib/euc_jp.rb" require_relative "../lib/euc_jp_not_declared.rb"
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/encodings/lib/utf8.rb
test_projects/encodings/lib/utf8.rb
# frozen_string_literal: true class Fun MSG = "おはよう" def 🇯🇵 "tada!" end end
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/encodings/lib/euc_jp_not_declared.rb
test_projects/encodings/lib/euc_jp_not_declared.rb
# frozen_string_literal: true class Fun3 # ruby actually breaks on the not decalred multibyte characters, # which is nice I guess MSG = "Something Else" def no_moji "tada!" end end
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/rails/rspec_rails/app/jobs/application_job.rb
test_projects/rails/rspec_rails/app/jobs/application_job.rb
class ApplicationJob < ActiveJob::Base # Automatically retry jobs that encountered a deadlock # retry_on ActiveRecord::Deadlocked # Most jobs are safe to ignore if the underlying records are no longer available # discard_on ActiveJob::DeserializationError end
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/rails/rspec_rails/app/helpers/application_helper.rb
test_projects/rails/rspec_rails/app/helpers/application_helper.rb
module ApplicationHelper end
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/rails/rspec_rails/app/controllers/application_controller.rb
test_projects/rails/rspec_rails/app/controllers/application_controller.rb
class ApplicationController < ActionController::Base end
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/rails/rspec_rails/app/models/foo.rb
test_projects/rails/rspec_rails/app/models/foo.rb
class Foo def bar "bar" end end
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/rails/rspec_rails/app/models/application_record.rb
test_projects/rails/rspec_rails/app/models/application_record.rb
class ApplicationRecord < ActiveRecord::Base self.abstract_class = true end
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/rails/rspec_rails/spec/foo_spec.rb
test_projects/rails/rspec_rails/spec/foo_spec.rb
require "rails_helper" RSpec.describe Foo do describe "#bar" do it "bars" do expect(subject.bar).to eq "bar" end end end
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/rails/rspec_rails/spec/rails_helper.rb
test_projects/rails/rspec_rails/spec/rails_helper.rb
# This file is copied to spec/ when you run 'rails generate rspec:install' require 'spec_helper' ENV['RAILS_ENV'] ||= 'test' require File.expand_path('../config/environment', __dir__) # Prevent database truncation if the environment is production abort("The Rails environment is running in production mode!") if Rails.env.production? require 'rspec/rails' begin ActiveRecord::Migration.maintain_test_schema! rescue ActiveRecord::PendingMigrationError => e puts e.to_s.strip exit 1 end RSpec.configure do |config| # RSpec Rails can automatically mix in different behaviours to your tests # based on their file location, for example enabling you to call `get` and # `post` in specs under `spec/controllers`. # # You can disable this behaviour by removing the line below, and instead # explicitly tag your specs with their type, e.g.: # # RSpec.describe UsersController, :type => :controller do # # ... # end # # The different available types are documented in the features, such as in # https://relishapp.com/rspec/rspec-rails/docs config.infer_spec_type_from_file_location! # Filter lines from Rails gems in backtraces. config.filter_rails_from_backtrace! # arbitrary gems may also be filtered via: # config.filter_gems_from_backtrace("gem name") end
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/rails/rspec_rails/spec/spec_helper.rb
test_projects/rails/rspec_rails/spec/spec_helper.rb
require "simplecov" SimpleCov.start "rails"
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/rails/rspec_rails/config/application.rb
test_projects/rails/rspec_rails/config/application.rb
require_relative "boot" require "logger" require "rails" # Pick the frameworks you want: require "active_model/railtie" require "active_job/railtie" require "active_record/railtie" # require "active_storage/engine" require "action_controller/railtie" # require "action_mailer/railtie" # require "action_mailbox/engine" # require "action_text/engine" require "action_view/railtie" # require "action_cable/engine" # require "sprockets/railtie" require "rails/test_unit/railtie" # Require the gems listed in Gemfile, including any gems # you've limited to :test, :development, or :production. Bundler.require(*Rails.groups) module RspecRails class Application < Rails::Application # Initialize configuration defaults for originally generated Rails version. config.load_defaults 6.1 # Configuration for the application, engines, and railties goes here. # # These settings can be overridden in specific environments using the files # in config/environments, which are processed later. # # config.time_zone = "Central Time (US & Canada)" # config.eager_load_paths << Rails.root.join("extras") end end
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/rails/rspec_rails/config/environment.rb
test_projects/rails/rspec_rails/config/environment.rb
# Load the Rails application. require_relative "application" # Initialize the Rails application. Rails.application.initialize!
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/rails/rspec_rails/config/puma.rb
test_projects/rails/rspec_rails/config/puma.rb
# Puma can serve each request in a thread from an internal thread pool. # The `threads` method setting takes two numbers: a minimum and maximum. # Any libraries that use thread pools should be configured to match # the maximum value specified for Puma. Default is set to 5 threads for minimum # and maximum; this matches the default thread size of Active Record. # max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count } threads min_threads_count, max_threads_count # Specifies the `worker_timeout` threshold that Puma will use to wait before # terminating a worker in development environments. # worker_timeout 3600 if ENV.fetch("RAILS_ENV", "development") == "development" # Specifies the `port` that Puma will listen on to receive requests; default is 3000. # port ENV.fetch("PORT") { 3000 } # Specifies the `environment` that Puma will run in. # environment ENV.fetch("RAILS_ENV") { "development" } # Specifies the `pidfile` that Puma will use. pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" } # Specifies the number of `workers` to boot in clustered mode. # Workers are forked web server processes. If using threads and workers together # the concurrency of the application would be max `threads` * `workers`. # Workers do not work on JRuby or Windows (both of which do not support # processes). # # workers ENV.fetch("WEB_CONCURRENCY") { 2 } # Use the `preload_app!` method when specifying a `workers` number. # This directive tells Puma to first boot the application and load code # before forking the application. This takes advantage of Copy On Write # process behavior so workers use less memory. # # preload_app! # Allow puma to be restarted by `rails restart` command. plugin :tmp_restart
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/rails/rspec_rails/config/routes.rb
test_projects/rails/rspec_rails/config/routes.rb
Rails.application.routes.draw do # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html end
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/rails/rspec_rails/config/spring.rb
test_projects/rails/rspec_rails/config/spring.rb
Spring.watch( ".ruby-version", ".rbenv-vars", "tmp/restart.txt", "tmp/caching-dev.txt" )
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/rails/rspec_rails/config/boot.rb
test_projects/rails/rspec_rails/config/boot.rb
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) require "bundler/setup" # Set up gems listed in the Gemfile.
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/rails/rspec_rails/config/initializers/filter_parameter_logging.rb
test_projects/rails/rspec_rails/config/initializers/filter_parameter_logging.rb
# Be sure to restart your server when you modify this file. # Configure sensitive parameters which will be filtered from the log file. Rails.application.config.filter_parameters += [ :passw, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn ]
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/rails/rspec_rails/config/initializers/wrap_parameters.rb
test_projects/rails/rspec_rails/config/initializers/wrap_parameters.rb
# Be sure to restart your server when you modify this file. # This file contains settings for ActionController::ParamsWrapper which # is enabled by default. # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. ActiveSupport.on_load(:action_controller) do wrap_parameters format: [:json] end # To enable root element in JSON for ActiveRecord objects. # ActiveSupport.on_load(:active_record) do # self.include_root_in_json = true # end
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/rails/rspec_rails/config/initializers/cookies_serializer.rb
test_projects/rails/rspec_rails/config/initializers/cookies_serializer.rb
# Be sure to restart your server when you modify this file. # Specify a serializer for the signed and encrypted cookie jars. # Valid options are :json, :marshal, and :hybrid. Rails.application.config.action_dispatch.cookies_serializer = :json
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/rails/rspec_rails/config/environments/test.rb
test_projects/rails/rspec_rails/config/environments/test.rb
require "active_support/core_ext/integer/time" # The test environment is used exclusively to run your application's # test suite. You never need to work with it otherwise. Remember that # your test database is "scratch space" for the test suite and is wiped # and recreated between test runs. Don't rely on the data there! Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. config.cache_classes = true # Do not eager load code on boot. This avoids loading your whole application # just for the purpose of running a single test. If you are using a tool that # preloads Rails for running tests, you may have to set it to true. config.eager_load = false # Configure public file server for tests with Cache-Control for performance. config.public_file_server.enabled = true config.public_file_server.headers = { 'Cache-Control' => "public, max-age=#{1.hour.to_i}" } # Show full error reports and disable caching. config.consider_all_requests_local = true config.action_controller.perform_caching = false config.cache_store = :null_store # Raise exceptions instead of rendering exception templates. config.action_dispatch.show_exceptions = false # Disable request forgery protection in test environment. config.action_controller.allow_forgery_protection = false # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr # Raise exceptions for disallowed deprecations. config.active_support.disallowed_deprecation = :raise # Tell Active Support which deprecation messages to disallow. config.active_support.disallowed_deprecation_warnings = [] # Raises error for missing translations. # config.i18n.raise_on_missing_translations = true # Annotate rendered view with file names. # config.action_view.annotate_rendered_view_with_filenames = true end
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/rails/rspec_rails/config/environments/development.rb
test_projects/rails/rspec_rails/config/environments/development.rb
require "active_support/core_ext/integer/time" Rails.application.configure do # Settings specified here will take precedence over those in config/application.rb. # In the development environment your application's code is reloaded any time # it changes. This slows down response time but is perfect for development # since you don't have to restart the web server when you make code changes. config.cache_classes = false # Do not eager load code on boot. config.eager_load = false # Show full error reports. config.consider_all_requests_local = true # Enable/disable caching. By default caching is disabled. # Run rails dev:cache to toggle caching. if Rails.root.join('tmp', 'caching-dev.txt').exist? config.action_controller.perform_caching = true config.action_controller.enable_fragment_cache_logging = true config.cache_store = :memory_store config.public_file_server.headers = { 'Cache-Control' => "public, max-age=#{2.days.to_i}" } else config.action_controller.perform_caching = false config.cache_store = :null_store end # Print deprecation notices to the Rails logger. config.active_support.deprecation = :log # Raise exceptions for disallowed deprecations. config.active_support.disallowed_deprecation = :raise # Tell Active Support which deprecation messages to disallow. config.active_support.disallowed_deprecation_warnings = [] # Raise an error on page load if there are pending migrations. config.active_record.migration_error = :page_load # Highlight code that triggered database queries in logs. config.active_record.verbose_query_logs = true # Raises error for missing translations. # config.i18n.raise_on_missing_translations = true # Annotate rendered view with file names. # config.action_view.annotate_rendered_view_with_filenames = true # Use an evented file watcher to asynchronously detect changes in source code, # routes, locales, etc. This feature depends on the listen gem. config.file_watcher = ActiveSupport::EventedFileUpdateChecker # Uncomment if you wish to allow Action Cable access from any origin. # config.action_cable.disable_request_forgery_protection = true end
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/subprocesses/.simplecov_spawn.rb
test_projects/subprocesses/.simplecov_spawn.rb
require 'bundler/setup' require 'simplecov' SimpleCov.command_name 'spawn' SimpleCov.at_fork.call(Process.pid) SimpleCov.start
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/subprocesses/spec/spawn_spec.rb
test_projects/subprocesses/spec/spawn_spec.rb
require 'spec_helper' require 'open3' describe 'spawn' do it 'calls things' do Dir.chdir(File.expand_path('..', __dir__)) do stdout, exitstatus = Open3.capture2("ruby -r./.simplecov_spawn lib/command") expect(stdout.chomp).to eq 'done' end end end
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/subprocesses/spec/simple_spec.rb
test_projects/subprocesses/spec/simple_spec.rb
require_relative "spec_helper" describe Subprocesses do it "call things" do expect(subject.run).to be true end end
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/subprocesses/spec/spec_helper.rb
test_projects/subprocesses/spec/spec_helper.rb
# frozen_string_literal: true require "simplecov" SimpleCov.start require_relative "../lib/subprocesses.rb"
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/subprocesses/lib/subprocesses.rb
test_projects/subprocesses/lib/subprocesses.rb
class Subprocesses def run method_called_in_parent_process pid = Process.fork do method_called_by_subprocess end Process.wait(pid) true end def method_called_in_parent_process true end def method_called_by_subprocess true end end
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/faked_project/minitest/some_test.rb
test_projects/faked_project/minitest/some_test.rb
# frozen_string_literal: true require "test_helper" require "faked_project/some_class" class SomeTest < Minitest::Test def setup @instance = SomeClass.new("foo") end def test_reverse assert_equal "oof", @instance.reverse end def test_comparison assert @instance.compare_with("foo") end end
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/faked_project/minitest/test_helper.rb
test_projects/faked_project/minitest/test_helper.rb
# frozen_string_literal: true require "bundler/setup" # We're injecting simplecov_config via aruba in cucumber here # depending on what the test case is... begin require File.join(File.dirname(__FILE__), "simplecov_config") rescue LoadError warn "No SimpleCov config file found!" end require "minitest/autorun"
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/faked_project/minitest/other_test.rb
test_projects/faked_project/minitest/other_test.rb
# frozen_string_literal: true require "bundler/setup" begin require File.expand_path("simplecov_config", __dir__) rescue LoadError warn "No SimpleCov config file found!" end require "minitest/autorun" require "faked_project/some_class" class OtherTest < Minitest::Test def setup @instance = SomeClass.new("foo") end def test_reverse assert_equal "oof", @instance.reverse end def test_comparison assert @instance.compare_with("foo") end end
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/faked_project/test/test_helper.rb
test_projects/faked_project/test/test_helper.rb
# frozen_string_literal: true require "bundler/setup" # We're injecting simplecov_config via aruba in cucumber here # depending on what the test case is... begin require File.join(File.dirname(__FILE__), "simplecov_config") rescue LoadError warn "No SimpleCov config file found!" end require "faked_project" require "test/unit"
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/faked_project/test/faked_test.rb
test_projects/faked_project/test/faked_test.rb
# frozen_string_literal: true require_relative "test_helper" class FakedTest < Test::Unit::TestCase def test_something assert_equal "bar", FakedProject.foo end def test_framework_specific assert_equal "Only tested in Test/Unit", FrameworkSpecific.test_unit end end
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/faked_project/test/meta_magic_test.rb
test_projects/faked_project/test/meta_magic_test.rb
# frozen_string_literal: true require_relative "test_helper" class MetaMagicTest < Test::Unit::TestCase def test_class_methods assert_equal "this is a mixed-in class method", FakedProject.a_class_method end def test_instance_methods p = FakedProject.new assert_equal "this is a mixed-in instance method", p.an_instance_method assert_equal "A dynamically defined instance method", p.dynamic end end
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/faked_project/test/some_class_test.rb
test_projects/faked_project/test/some_class_test.rb
# frozen_string_literal: true require_relative "test_helper" class SomeClassTest < Test::Unit::TestCase def setup @instance = SomeClass.new("foo") end def test_reverse assert_equal "oof", @instance.reverse end def test_comparison assert @instance.compare_with("foo") end end
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/faked_project/features/support/env.rb
test_projects/faked_project/features/support/env.rb
# frozen_string_literal: true require "bundler/setup" # We're injecting simplecov_config via aruba in cucumber here # depending on what the test case is... begin require File.join(File.dirname(__FILE__), "simplecov_config") rescue LoadError warn "No SimpleCov config file found!" end $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "/../../lib")) require "faked_project"
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/faked_project/features/step_definitions/my_steps.rb
test_projects/faked_project/features/step_definitions/my_steps.rb
# frozen_string_literal: true Given(/^I want to keep stuff simple$/) do expect(1).to eq(1) end When(/^I write my cukes for the fake project$/) do expect(1).to eq(1) end Then(/^I make all necessary tests in a single step$/) do expect(FakedProject.foo).to eq("bar") expect(FrameworkSpecific.cucumber).to eq("Only tested in Cucumber") expect(FakedProject.a_class_method).to eq("this is a mixed-in class method") expect(FakedProject.new.an_instance_method).to eq("this is a mixed-in instance method") expect(FakedProject.new.dynamic).to eq("A dynamically defined instance method") something = SomeClass.new("foo") expect(something.reverse).to eq("oof") expect(something.compare_with("foo")).to be true end
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/faked_project/spec/meta_magic_spec.rb
test_projects/faked_project/spec/meta_magic_spec.rb
# frozen_string_literal: true require "spec_helper" describe FakedProject do it "should have added a class method to FakedProject" do expect(FakedProject.a_class_method).to eq("this is a mixed-in class method") end it "should have added a mixed-in instance method to FakedProject" do expect(subject.an_instance_method).to eq("this is a mixed-in instance method") end it "should have added a dynamically-defined instance method to FakedProject" do expect(subject.dynamic).to eq("A dynamically defined instance method") end end
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/faked_project/spec/some_class_spec.rb
test_projects/faked_project/spec/some_class_spec.rb
# frozen_string_literal: true require "spec_helper" describe SomeClass do subject { SomeClass.new("foo") } it "should be reversible" do expect(subject.reverse).to eq("oof") end it "should compare with 'foo'" do expect(subject.compare_with("foo")).to be true end end
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/faked_project/spec/forking_spec.rb
test_projects/faked_project/spec/forking_spec.rb
# frozen_string_literal: true require "spec_helper" describe "forking" do it do # TODO: The defined?(RUBY_ENGINE) check can be dropped for simplecov 1.0.0 Process.waitpid(Kernel.fork {}) unless defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby" end end
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/faked_project/spec/spec_helper.rb
test_projects/faked_project/spec/spec_helper.rb
# frozen_string_literal: true require "bundler/setup" # We're injecting simplecov_config via aruba in cucumber here # depending on what the test case is... begin require File.join(File.dirname(__FILE__), "simplecov_config") rescue LoadError warn "No SimpleCov config file found!" end require "faked_project"
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/faked_project/spec/faked_spec.rb
test_projects/faked_project/spec/faked_spec.rb
# frozen_string_literal: true require "spec_helper" describe FakedProject do it "should return proper foo" do expect(FakedProject.foo).to eq("bar") end it "should test it's framework specific method" do expect(FrameworkSpecific.rspec).to eq("Only tested in RSpec") end end
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/faked_project/lib/faked_project.rb
test_projects/faked_project/lib/faked_project.rb
# frozen_string_literal: true class FakedProject def self.foo "bar" end end Dir[File.join(File.dirname(__FILE__), "faked_project/*.rb")].reject { |f| /untested/.match(f) }.each do |file| require file # Require all source files in project dynamically so we can inject some stuff depending on test situation end FakedProject.include MetaMagic
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/faked_project/lib/faked_project/untested_class.rb
test_projects/faked_project/lib/faked_project/untested_class.rb
# frozen_string_literal: true class UntestedClass def initialize(yogurts) @yogurts = yogurts end def power_level @yogurts.map do |yo| yo.experience_points**2 end.reduce(0, &:+) end end
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/faked_project/lib/faked_project/some_class.rb
test_projects/faked_project/lib/faked_project/some_class.rb
# frozen_string_literal: true class SomeClass attr_reader :label attr_accessor :some_attr def initialize(label) @label = label end def reverse label.reverse end def compare_with(item) if item == label true else raise "Item does not match label" end rescue StandardError false end private def uncovered "private method" end end
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/faked_project/lib/faked_project/framework_specific.rb
test_projects/faked_project/lib/faked_project/framework_specific.rb
# frozen_string_literal: true # A pile of methods that only get tested in their frameworks # and thus make this file only 100% covered when all framework test # results are merged module FrameworkSpecific class << self def cucumber "Only tested in Cucumber" end def rspec "Only tested in RSpec" end def test_unit "Only tested in Test/Unit" end end end
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/faked_project/lib/faked_project/meta_magic.rb
test_projects/faked_project/lib/faked_project/meta_magic.rb
# frozen_string_literal: true module MetaMagic module ClassMethods def a_class_method "this is a mixed-in class method" end end module InstanceMethods def an_instance_method "this is a mixed-in instance method" end end def self.included(base) base.send :extend, ClassMethods base.send :include, InstanceMethods base.class_eval do define_method :dynamic do "A dynamically defined instance method" end end end end
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/faked_project/bad_spec/failing_spec.rb
test_projects/faked_project/bad_spec/failing_spec.rb
require_relative "spec_helper" RSpec.describe "failing" do it "fails" do exoect(1).to eq 2 end end
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/faked_project/bad_spec/fail_with_5.rb
test_projects/faked_project/bad_spec/fail_with_5.rb
require_relative "spec_helper" exit(5)
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/faked_project/bad_spec/spec_helper.rb
test_projects/faked_project/bad_spec/spec_helper.rb
# frozen_string_literal: true require "bundler/setup" require "simplecov" SimpleCov.start require "faked_project"
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/old_coverage_json/spec/code_spec.rb
test_projects/old_coverage_json/spec/code_spec.rb
# frozen_string_literal: true require "spec_helper" RSpec.describe Code do it "#foo returns :foo being passed 42" do expect(subject.foo(42)).to eq :foo end end
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/old_coverage_json/spec/spec_helper.rb
test_projects/old_coverage_json/spec/spec_helper.rb
# frozen_string_literal: true require "simplecov" SimpleCov.start require_relative "../lib/code"
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/old_coverage_json/lib/code.rb
test_projects/old_coverage_json/lib/code.rb
# frozen_string_literal: true class Code def foo(arg) if arg == 42 :foo else :bar end end end
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/pagination/spec/spec_helper.rb
test_projects/pagination/spec/spec_helper.rb
# frozen_string_literal: true require "simplecov" SimpleCov.start Dir["lib/*.rb"].each {|file| require_relative "../#{file}" }
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/pagination/lib/e.rb
test_projects/pagination/lib/e.rb
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/pagination/lib/c.rb
test_projects/pagination/lib/c.rb
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/pagination/lib/i.rb
test_projects/pagination/lib/i.rb
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/pagination/lib/k.rb
test_projects/pagination/lib/k.rb
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/pagination/lib/g.rb
test_projects/pagination/lib/g.rb
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/pagination/lib/d.rb
test_projects/pagination/lib/d.rb
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/pagination/lib/a.rb
test_projects/pagination/lib/a.rb
# nothing to see here
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/pagination/lib/h.rb
test_projects/pagination/lib/h.rb
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/pagination/lib/j.rb
test_projects/pagination/lib/j.rb
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/pagination/lib/l.rb
test_projects/pagination/lib/l.rb
# nothing to see here
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/pagination/lib/f.rb
test_projects/pagination/lib/f.rb
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/pagination/lib/b.rb
test_projects/pagination/lib/b.rb
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/parallel_tests/spec/a_spec.rb
test_projects/parallel_tests/spec/a_spec.rb
# frozen_string_literal: true require "spec_helper" describe A do it "foo" do expect(subject.foo).to eq :foo end it "cond" do expect(subject.cond(false)).to eq :no end end
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/parallel_tests/spec/b_spec.rb
test_projects/parallel_tests/spec/b_spec.rb
# frozen_string_literal: true require "spec_helper" describe B do it "bar" do expect(subject.bar).to eq :bar end end
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/parallel_tests/spec/d_spec.rb
test_projects/parallel_tests/spec/d_spec.rb
# frozen_string_literal: true require "spec_helper" describe D do it "case 4" do expect(subject.case(4)).to eq :foo end it "case nil" do expect(subject.case(nil)).to eq :nope end end
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/parallel_tests/spec/c_spec.rb
test_projects/parallel_tests/spec/c_spec.rb
# frozen_string_literal: true require "spec_helper" describe C do it "guard" do expect(subject.guard(42)).to be_nil end end
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/parallel_tests/spec/spec_helper.rb
test_projects/parallel_tests/spec/spec_helper.rb
# frozen_string_literal: true # We're injecting simplecov_config via aruba in cucumber here # depending on what the test case is... begin require File.join(File.dirname(__FILE__), "simplecov_config") rescue LoadError warn "No SimpleCov config file found!" end require_relative "../lib/all"
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/parallel_tests/lib/c.rb
test_projects/parallel_tests/lib/c.rb
# frozen_string_literal: true class C def guard(arg) return if arg == 42 :super end end
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/parallel_tests/lib/d.rb
test_projects/parallel_tests/lib/d.rb
# frozen_string_literal: true class D def case(arg) case arg when 0...23 :foo when 40..50 :bar when Integer :baz else :nope end end end
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/parallel_tests/lib/a.rb
test_projects/parallel_tests/lib/a.rb
# frozen_string_literal: true class A def foo :foo end def cond(arg) if arg :yes else :no end end end
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/parallel_tests/lib/b.rb
test_projects/parallel_tests/lib/b.rb
# frozen_string_literal: true class B def foo :foo end def bar :bar end end
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/parallel_tests/lib/all.rb
test_projects/parallel_tests/lib/all.rb
# frozen_string_literal: true require_relative "a" require_relative "b" require_relative "c" require_relative "d"
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/monorepo/base/lib/monorepo/base.rb
test_projects/monorepo/base/lib/monorepo/base.rb
# frozen_string_literal: true module Monorepo class Base def initialize(label) @label = label end def reverse @label.reverse end end end
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/monorepo/extra/spec/extra_spec.rb
test_projects/monorepo/extra/spec/extra_spec.rb
# frozen_string_literal: true require "spec_helper" require "monorepo/extra" RSpec.describe Monorepo::Extra do describe "#identity" do it "returns the same string" do expect(described_class.new("foo").identity).to eq("foo") end end end
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/monorepo/extra/spec/spec_helper.rb
test_projects/monorepo/extra/spec/spec_helper.rb
# frozen_string_literal: true require "simplecov" require "monorepo/base"
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/test_projects/monorepo/extra/lib/monorepo/extra.rb
test_projects/monorepo/extra/lib/monorepo/extra.rb
# frozen_string_literal: true require "monorepo/base" module Monorepo class Extra def initialize(label) @label = label end def identity Base.new(Base.new(@label).reverse).reverse end end end
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/lib/simplecov.rb
lib/simplecov.rb
# frozen_string_literal: true require "English" # Coverage may be inaccurate under JRUBY. if defined?(JRUBY_VERSION) && defined?(JRuby) && !org.jruby.RubyInstanceConfig.FULL_TRACE_ENABLED # @see https://github.com/jruby/jruby/issues/1196 # @see https://github.com/metricfu/metric_fu/pull/226 # @see https://github.com/simplecov-ruby/simplecov/issues/420 # @see https://github.com/simplecov-ruby/simplecov/issues/86 # @see https://jira.codehaus.org/browse/JRUBY-6106 warn 'Coverage may be inaccurate; set the "--debug" command line option, ' \ 'or do JRUBY_OPTS="--debug" ' \ 'or set the "debug.fullTrace=true" option in your .jrubyrc' end # # Code coverage for ruby. Please check out README for a full introduction. # module SimpleCov class << self attr_accessor :running, :pid # Basically, should we take care of at_exit behavior or something else? # Used by the minitest plugin. See lib/minitest/simplecov_plugin.rb attr_accessor :external_at_exit alias external_at_exit? external_at_exit # # Sets up SimpleCov to run against your project. # You can optionally specify a profile to use as well as configuration with a block: # SimpleCov.start # OR # SimpleCov.start 'rails' # using rails profile # OR # SimpleCov.start do # add_filter 'test' # end # OR # SimpleCov.start 'rails' do # add_filter 'test' # end # # Please check out the RDoc for SimpleCov::Configuration to find about available config options # def start(profile = nil, &block) require "coverage" initial_setup(profile, &block) require_relative "simplecov/process" if SimpleCov.enabled_for_subprocesses? && ::Process.respond_to?(:fork) make_parallel_tests_available @result = nil self.pid = Process.pid start_coverage_measurement end # # Collate a series of SimpleCov result files into a single SimpleCov output. # # You can optionally specify configuration with a block: # SimpleCov.collate Dir["simplecov-resultset-*/.resultset.json"] # OR # SimpleCov.collate Dir["simplecov-resultset-*/.resultset.json"], 'rails' # using rails profile # OR # SimpleCov.collate Dir["simplecov-resultset-*/.resultset.json"] do # add_filter 'test' # end # OR # SimpleCov.collate Dir["simplecov-resultset-*/.resultset.json"], 'rails' do # add_filter 'test' # end # # Please check out the RDoc for SimpleCov::Configuration to find about # available config options, or checkout the README for more in-depth # information about coverage collation # # By default `collate` ignores the merge_timeout so all results of all files specified will be # merged together. If you want to honor the merge_timeout then provide the keyword argument # `ignore_timeout: false`. # def collate(result_filenames, profile = nil, ignore_timeout: true, &block) raise "There are no reports to be merged" if result_filenames.empty? initial_setup(profile, &block) # Use the ResultMerger to produce a single, merged result, ready to use. @result = ResultMerger.merge_and_store(*result_filenames, ignore_timeout: ignore_timeout) run_exit_tasks! end # # Returns the result for the current coverage run, merging it across test suites # from cache using SimpleCov::ResultMerger if use_merging is activated (default) # def result return @result if result? # Collect our coverage result process_coverage_result if running # If we're using merging of results, store the current result # first (if there is one), then merge the results and return those if use_merging wait_for_other_processes SimpleCov::ResultMerger.store_result(@result) if result? @result = SimpleCov::ResultMerger.merged_result end @result ensure self.running = false end # # Returns nil if the result has not been computed # Otherwise, returns the result # def result? defined?(@result) && @result end # # Applies the configured filters to the given array of SimpleCov::SourceFile items # def filtered(files) result = files.clone filters.each do |filter| result = result.reject { |source_file| filter.matches?(source_file) } end SimpleCov::FileList.new result end # # Applies the configured groups to the given array of SimpleCov::SourceFile items # def grouped(files) grouped = {} grouped_files = [] groups.each do |name, filter| grouped[name] = SimpleCov::FileList.new(files.select { |source_file| filter.matches?(source_file) }) grouped_files += grouped[name] end if !groups.empty? && !(other_files = files.reject { |source_file| grouped_files.include?(source_file) }).empty? grouped["Ungrouped"] = SimpleCov::FileList.new(other_files) end grouped end # # Applies the profile of given name on SimpleCov configuration # def load_profile(name) profiles.load(name) end def load_adapter(name) warn "#{Kernel.caller.first}: [DEPRECATION] #load_adapter is deprecated. Use #load_profile instead." load_profile(name) end # # Clear out the previously cached .result. Primarily useful in testing # def clear_result @result = nil end def at_exit_behavior # If we are in a different process than called start, don't interfere. return if SimpleCov.pid != Process.pid # If SimpleCov is no longer running then don't run exit tasks SimpleCov.run_exit_tasks! if SimpleCov.running end # @api private # # Called from at_exit block # def run_exit_tasks! error_exit_status = exit_status_from_exception at_exit.call exit_and_report_previous_error(error_exit_status) if previous_error?(error_exit_status) process_results_and_report_error if ready_to_process_results? end # # @api private # # Returns the exit status from the exit exception # def exit_status_from_exception # Capture the current exception if it exists @exit_exception = $ERROR_INFO return nil unless @exit_exception if @exit_exception.is_a?(SystemExit) @exit_exception.status else SimpleCov::ExitCodes::EXCEPTION end end # @api private def previous_error?(error_exit_status) # Normally it'd be enough to check for previous error but when running test_unit # status is 0 error_exit_status && error_exit_status != SimpleCov::ExitCodes::SUCCESS end # # @api private # # Thinking: Move this behavior earlier so if there was an error we do nothing? def exit_and_report_previous_error(exit_status) warn("Stopped processing SimpleCov as a previous error not related to SimpleCov has been detected") if print_error_status Kernel.exit(exit_status) end # @api private def ready_to_process_results? final_result_process? && result? end def process_results_and_report_error exit_status = process_result(result) # Force exit with stored status (see github issue #5) if exit_status.positive? warn("SimpleCov failed with exit #{exit_status} due to a coverage related error") if print_error_status Kernel.exit exit_status end end # @api private # # Usage: # exit_status = SimpleCov.process_result(SimpleCov.result, exit_status) # def process_result(result) result_exit_status = result_exit_status(result) write_last_run(result) if result_exit_status == SimpleCov::ExitCodes::SUCCESS result_exit_status end # @api private CoverageLimits = Struct.new(:minimum_coverage, :minimum_coverage_by_file, :maximum_coverage_drop, keyword_init: true) def result_exit_status(result) coverage_limits = CoverageLimits.new( minimum_coverage: minimum_coverage, minimum_coverage_by_file: minimum_coverage_by_file, maximum_coverage_drop: maximum_coverage_drop ) ExitCodes::ExitCodeHandling.call(result, coverage_limits: coverage_limits) end # # @api private # def final_result_process? # checking for ENV["TEST_ENV_NUMBER"] to determine if the tests are being run in parallel !defined?(ParallelTests) || !ENV["TEST_ENV_NUMBER"] || ParallelTests.last_process? end # # @api private # def wait_for_other_processes return unless defined?(ParallelTests) && final_result_process? ParallelTests.wait_for_other_processes_to_finish end # # @api private # def write_last_run(result) SimpleCov::LastRun.write(result: result.coverage_statistics.transform_values do |stats| round_coverage(stats.percent) end) end # # @api private # # Rounding down to be extra strict, see #679 def round_coverage(coverage) coverage.floor(2) end private def initial_setup(profile, &block) load_profile(profile) if profile configure(&block) if block self.running = true end # # Trigger Coverage.start depends on given config coverage_criterion # # With Positive branch it supports all coverage measurement types # With Negative branch it supports only line coverage measurement type # def start_coverage_measurement # This blog post gives a good run down of the coverage criterias introduced # in Ruby 2.5: https://blog.bigbinary.com/2018/04/11/ruby-2-5-supports-measuring-branch-and-method-coverages.html # There is also a nice writeup of the different coverage criteria made in this # comment https://github.com/simplecov-ruby/simplecov/pull/692#discussion_r281836176 : # Ruby < 2.5: # https://github.com/ruby/ruby/blob/v1_9_3_374/ext/coverage/coverage.c # traditional mode (Array) # # Ruby 2.5: # https://bugs.ruby-lang.org/issues/13901 # https://github.com/ruby/ruby/blob/v2_5_3/ext/coverage/coverage.c # default: traditional/compatible mode (Array) # :lines - like traditional mode but using Hash # :branches # :methods # :all - same as lines + branches + methods # # Ruby >= 2.6: # https://bugs.ruby-lang.org/issues/15022 # https://github.com/ruby/ruby/blob/v2_6_3/ext/coverage/coverage.c # default: traditional/compatible mode (Array) # :lines - like traditional mode but using Hash # :branches # :methods # :oneshot_lines - can not be combined with lines # :all - same as lines + branches + methods # if coverage_start_arguments_supported? start_coverage_with_criteria else Coverage.start unless coverage_running? end end def start_coverage_with_criteria start_arguments = coverage_criteria.map do |criterion| [lookup_corresponding_ruby_coverage_name(criterion), true] end.to_h start_arguments[:eval] = true if coverage_for_eval_enabled? Coverage.start(start_arguments) unless coverage_running? end def coverage_running? # for ruby versions which do not implement Coverage.running?, # Coverage.start may be called multiple times without raising. Coverage.respond_to?(:running?) && Coverage.running? end CRITERION_TO_RUBY_COVERAGE = { branch: :branches, line: :lines }.freeze def lookup_corresponding_ruby_coverage_name(criterion) CRITERION_TO_RUBY_COVERAGE.fetch(criterion) end # # Finds files that were to be tracked but were not loaded and initializes # the line-by-line coverage to zero (if relevant) or nil (comments / whitespace etc). # def add_not_loaded_files(result) if tracked_files result = result.dup Dir[tracked_files].each do |file| absolute_path = File.expand_path(file) result[absolute_path] ||= SimulateCoverage.call(absolute_path) end end result end # # Call steps that handle process coverage result # # @return [Hash] # def process_coverage_result adapt_coverage_result remove_useless_results result_with_not_loaded_files end # # Unite the result so it wouldn't matter what coverage type was called # # @return [Hash] # def adapt_coverage_result @result = SimpleCov::ResultAdapter.call(Coverage.result) end # # Filter coverage result # The result before filter also has result of coverage for files # are not related to the project like loaded gems coverage. # # @return [Hash] # def remove_useless_results @result = SimpleCov::UselessResultsRemover.call(@result) end # # Initialize result with files that are not included by coverage # and added inside the config block # # @return [Hash] # def result_with_not_loaded_files @result = SimpleCov::Result.new(add_not_loaded_files(@result)) end # parallel_tests isn't always available, see: https://github.com/grosser/parallel_tests/issues/772 def make_parallel_tests_available return if defined?(ParallelTests) return unless probably_running_parallel_tests? require "parallel_tests" rescue LoadError warn("SimpleCov guessed you were running inside parallel tests but couldn't load it. Please file a bug report with us!") end def probably_running_parallel_tests? ENV.fetch("TEST_ENV_NUMBER", nil) && ENV.fetch("PARALLEL_TEST_GROUPS", nil) end end end # requires are down here here for a load order reason I'm not sure what it is about require "set" require "forwardable" require_relative "simplecov/configuration" SimpleCov.extend SimpleCov::Configuration require_relative "simplecov/coverage_statistics" require_relative "simplecov/exit_codes" require_relative "simplecov/profiles" require_relative "simplecov/source_file/line" require_relative "simplecov/source_file/branch" require_relative "simplecov/source_file" require_relative "simplecov/file_list" require_relative "simplecov/result" require_relative "simplecov/filter" require_relative "simplecov/formatter" require_relative "simplecov/last_run" require_relative "simplecov/lines_classifier" require_relative "simplecov/result_merger" require_relative "simplecov/command_guesser" require_relative "simplecov/version" require_relative "simplecov/result_adapter" require_relative "simplecov/combine" require_relative "simplecov/combine/branches_combiner" require_relative "simplecov/combine/files_combiner" require_relative "simplecov/combine/lines_combiner" require_relative "simplecov/combine/results_combiner" require_relative "simplecov/useless_results_remover" require_relative "simplecov/simulate_coverage" # Load default config require_relative "simplecov/defaults" unless ENV["SIMPLECOV_NO_DEFAULTS"]
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/lib/minitest/simplecov_plugin.rb
lib/minitest/simplecov_plugin.rb
# frozen_string_literal: true # How minitest plugins. See https://github.com/simplecov-ruby/simplecov/pull/756 for why we need this. # https://github.com/seattlerb/minitest#writing-extensions module Minitest def self.plugin_simplecov_init(_options) if defined?(SimpleCov) SimpleCov.external_at_exit = true Minitest.after_run do SimpleCov.at_exit_behavior end end end end
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/lib/simplecov/exit_codes.rb
lib/simplecov/exit_codes.rb
# frozen_string_literal: true module SimpleCov module ExitCodes SUCCESS = 0 EXCEPTION = 1 MINIMUM_COVERAGE = 2 MAXIMUM_COVERAGE_DROP = 3 end end require_relative "exit_codes/exit_code_handling" require_relative "exit_codes/maximum_coverage_drop_check" require_relative "exit_codes/minimum_coverage_by_file_check" require_relative "exit_codes/minimum_overall_coverage_check"
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/lib/simplecov/command_guesser.rb
lib/simplecov/command_guesser.rb
# frozen_string_literal: true module SimpleCov # # Helper that tries to find out what test suite is running (for SimpleCov.command_name) # module CommandGuesser class << self # Storage for the original command line call that invoked the test suite. # This has got to be stored as early as possible because i.e. rake and test/unit 2 # have a habit of tampering with ARGV, which makes i.e. the automatic distinction # between rails unit/functional/integration tests impossible without this cached # item. attr_accessor :original_run_command def guess from_env || from_command_line_options || from_defined_constants end private def from_env # If being run from inside parallel_tests set the command name according to the process number return unless ENV["PARALLEL_TEST_GROUPS"] && ENV["TEST_ENV_NUMBER"] number = ENV.fetch("TEST_ENV_NUMBER", nil) number = "1" if number.empty? "(#{number}/#{ENV.fetch('PARALLEL_TEST_GROUPS', nil)})" end def from_command_line_options case original_run_command when /test\/functional\//, /test\/\{.*functional.*\}\// "Functional Tests" when /test\/integration\// "Integration Tests" when /test\// "Unit Tests" when /spec/ "RSpec" when /cucumber/, /features/ "Cucumber Features" end end def from_defined_constants # If the command regexps fail, let's try checking defined constants. if defined?(RSpec) "RSpec" elsif defined?(Test::Unit) "Unit Tests" elsif defined?(Minitest) "Minitest" elsif defined?(MiniTest) "MiniTest" else # TODO: Provide link to docs/wiki article warn "SimpleCov failed to recognize the test framework and/or suite used. Please specify manually using SimpleCov.command_name 'Unit Tests'." "Unknown Test Framework" end end end end end
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/lib/simplecov/profiles.rb
lib/simplecov/profiles.rb
# frozen_string_literal: true module SimpleCov # # Profiles are SimpleCov configuration procs that can be easily # loaded using SimpleCov.start :rails and defined using # SimpleCov.profiles.define :foo do # # SimpleCov configuration here, same as in SimpleCov.configure # end # class Profiles < Hash # # Define a SimpleCov profile: # SimpleCov.profiles.define 'rails' do # # Same as SimpleCov.configure do .. here # end # def define(name, &blk) name = name.to_sym raise "SimpleCov Profile '#{name}' is already defined" unless self[name].nil? self[name] = blk end # # Applies the profile of given name on SimpleCov.configure # def load(name) name = name.to_sym raise "Could not find SimpleCov Profile called '#{name}'" unless key?(name) SimpleCov.configure(&self[name]) end end end
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/lib/simplecov/version.rb
lib/simplecov/version.rb
# frozen_string_literal: true module SimpleCov VERSION = "0.22.0" end
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/lib/simplecov/result_adapter.rb
lib/simplecov/result_adapter.rb
# frozen_string_literal: true module SimpleCov # # Responsible for adapting the format of the coverage result whether it's default or with statistics # class ResultAdapter attr_reader :result def initialize(result) @result = result end def self.call(*args) new(*args).adapt end def adapt return unless result result.each_with_object({}) do |(file_name, cover_statistic), adapted_result| if cover_statistic.is_a?(Array) adapted_result.merge!(file_name => {"lines" => cover_statistic}) else adapted_result.merge!(file_name => cover_statistic) end end end end end
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/lib/simplecov/simulate_coverage.rb
lib/simplecov/simulate_coverage.rb
# frozen_string_literal: true module SimpleCov # # Responsible for producing file coverage metrics. # module SimulateCoverage module_function # # Simulate normal file coverage report on # ruby 2.5 and return similar hash with lines and branches keys # # Happens when a file wasn't required but still tracked. # # @return [Hash] # def call(absolute_path) lines = File.foreach(absolute_path) { "lines" => LinesClassifier.new.classify(lines), # we don't want to parse branches ourselves... # requiring files can have side effects and we don't want to trigger that "branches" => {} } end end end
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/lib/simplecov/source_file.rb
lib/simplecov/source_file.rb
# frozen_string_literal: true module SimpleCov # # Representation of a source file including it's coverage data, source code, # source lines and featuring helpers to interpret that data. # class SourceFile # The full path to this source file (e.g. /User/colszowka/projects/simplecov/lib/simplecov/source_file.rb) attr_reader :filename # The array of coverage data received from the Coverage.result attr_reader :coverage_data def initialize(filename, coverage_data) @filename = filename @coverage_data = coverage_data end # The path to this source file relative to the projects directory def project_filename @filename.delete_prefix(SimpleCov.root) end # The source code for this file. Aliased as :source def src # We intentionally read source code lazily to # suppress reading unused source code. @src ||= load_source end alias source src def coverage_statistics @coverage_statistics ||= { **line_coverage_statistics, **branch_coverage_statistics } end # Returns all source lines for this file as instances of SimpleCov::SourceFile::Line, # and thus including coverage data. Aliased as :source_lines def lines @lines ||= build_lines end alias source_lines lines # Returns all covered lines as SimpleCov::SourceFile::Line def covered_lines @covered_lines ||= lines.select(&:covered?) end # Returns all lines that should have been, but were not covered # as instances of SimpleCov::SourceFile::Line def missed_lines @missed_lines ||= lines.select(&:missed?) end # Returns all lines that are not relevant for coverage as # SimpleCov::SourceFile::Line instances def never_lines @never_lines ||= lines.select(&:never?) end # Returns all lines that were skipped as SimpleCov::SourceFile::Line instances def skipped_lines @skipped_lines ||= lines.select(&:skipped?) end # Returns the number of relevant lines (covered + missed) def lines_of_code coverage_statistics[:line]&.total end # Access SimpleCov::SourceFile::Line source lines by line number def line(number) lines[number - 1] end # The coverage for this file in percent. 0 if the file has no coverage lines def covered_percent coverage_statistics[:line]&.percent end def covered_strength coverage_statistics[:line]&.strength end def no_lines? lines.empty? || (lines.length == never_lines.size) end def relevant_lines lines.size - never_lines.size - skipped_lines.size end # # Return all the branches inside current source file def branches @branches ||= build_branches end def no_branches? total_branches.empty? end def branches_coverage_percent coverage_statistics[:branch]&.percent end # # Return the relevant branches to source file def total_branches @total_branches ||= covered_branches + missed_branches end # # Return hash with key of line number and branch coverage count as value def branches_report @branches_report ||= build_branches_report end # # Select the covered branches # Here we user tree schema because some conditions like case may have additional # else that is not in declared inside the code but given by default by coverage report # # @return [Array] # def covered_branches @covered_branches ||= branches.select(&:covered?) end # # Select the missed branches with coverage equal to zero # # @return [Array] # def missed_branches @missed_branches ||= branches.select(&:missed?) end def branches_for_line(line_number) branches_report.fetch(line_number, []) end # # Check if any branches missing on given line number # # @param [Integer] line_number # # @return [Boolean] # def line_with_missed_branch?(line_number) branches_for_line(line_number).any? { |_type, count| count.zero? } end private # no_cov_chunks is zero indexed to work directly with the array holding the lines def no_cov_chunks @no_cov_chunks ||= build_no_cov_chunks end def build_no_cov_chunks no_cov_lines = src.map.with_index(1).select { |line_src, _index| LinesClassifier.no_cov_line?(line_src) } # if we have an uneven number of nocovs we assume they go to the # end of the file, the source doesn't really matter # Can't deal with this within the each_slice due to differing # behavior in JRuby: jruby/jruby#6048 no_cov_lines << ["", src.size] if no_cov_lines.size.odd? no_cov_lines.each_slice(2).map do |(_line_src_start, index_start), (_line_src_end, index_end)| index_start..index_end end end def load_source lines = [] # The default encoding is UTF-8 File.open(filename, "rb:UTF-8") do |file| current_line = file.gets if shebang?(current_line) lines << current_line current_line = file.gets end read_lines(file, lines, current_line) end end SHEBANG_REGEX = /\A#!/.freeze def shebang?(line) SHEBANG_REGEX.match?(line) end def read_lines(file, lines, current_line) return lines unless current_line set_encoding_based_on_magic_comment(file, current_line) lines.concat([current_line], ensure_remove_undefs(file.readlines)) end RUBY_FILE_ENCODING_MAGIC_COMMENT_REGEX = /\A#\s*(?:-\*-)?\s*(?:en)?coding:\s*(\S+)\s*(?:-\*-)?\s*\z/.freeze def set_encoding_based_on_magic_comment(file, line) # Check for encoding magic comment # Encoding magic comment must be placed at first line except for shebang if (match = RUBY_FILE_ENCODING_MAGIC_COMMENT_REGEX.match(line)) file.set_encoding(match[1], "UTF-8") end end def ensure_remove_undefs(file_lines) # invalid/undef replace are technically not really necessary but nice to # have and work around a JRuby incompatibility. Also moved here from # simplecov-html to have encoding shenaningans in one place. See #866 # also setting these option on `file.set_encoding` doesn't seem to work # properly so it has to be done here. file_lines.each do |line| line.encode!("UTF-8", invalid: :replace, undef: :replace) unless line.encoding == Encoding::UTF_8 end end def build_lines coverage_exceeding_source_warn if coverage_data["lines"].size > src.size lines = src.map.with_index(1) do |src, i| SimpleCov::SourceFile::Line.new(src, i, coverage_data["lines"][i - 1]) end process_skipped_lines(lines) end def process_skipped_lines(lines) # the array the lines are kept in is 0-based whereas the line numbers in the nocov # chunks are 1-based and are expected to be like this in other parts (and it's also # arguably more understandable) no_cov_chunks.each { |chunk| lines[(chunk.begin - 1)..(chunk.end - 1)].each(&:skipped!) } lines end def lines_strength lines.sum { |line| line.coverage.to_i } end # Warning to identify condition from Issue #56 def coverage_exceeding_source_warn warn "Warning: coverage data provided by Coverage [#{coverage_data['lines'].size}] exceeds number of lines in #{filename} [#{src.size}]" end # # Build full branches report # Root branches represent the wrapper of all condition state that # have inside the branches # # @return [Hash] # def build_branches_report branches.reject(&:skipped?).each_with_object({}) do |branch, coverage_statistics| coverage_statistics[branch.report_line] ||= [] coverage_statistics[branch.report_line] << branch.report end end # # Call recursive method that transform our static hash to array of objects # @return [Array] # def build_branches coverage_branch_data = coverage_data.fetch("branches", {}) branches = coverage_branch_data.flat_map do |condition, coverage_branches| build_branches_from(condition, coverage_branches) end process_skipped_branches(branches) end def process_skipped_branches(branches) return branches if no_cov_chunks.empty? branches.each do |branch| branch.skipped! if no_cov_chunks.any? { |no_cov_chunk| branch.overlaps_with?(no_cov_chunk) } end branches end # Since we are dumping to and loading from JSON, and we have arrays as keys those # don't make their way back to us intact e.g. just as a string # # We should probably do something different here, but as it stands these are # our data structures that we write so eval isn't _too_ bad. # # See #801 # def restore_ruby_data_structure(structure) # Tests use the real data structures (except for integration tests) so no need to # put them through here. return structure if structure.is_a?(Array) # rubocop:disable Security/Eval eval structure # rubocop:enable Security/Eval end def build_branches_from(condition, branches) # the format handed in from the coverage data is like this: # # [:then, 4, 6, 6, 6, 10] # # which is [type, id, start_line, start_col, end_line, end_col] _condition_type, _condition_id, condition_start_line, * = restore_ruby_data_structure(condition) branches.map do |branch_data, hit_count| branch_data = restore_ruby_data_structure(branch_data) build_branch(branch_data, hit_count, condition_start_line) end end def build_branch(branch_data, hit_count, condition_start_line) type, _id, start_line, _start_col, end_line, _end_col = branch_data SourceFile::Branch.new( start_line: start_line, end_line: end_line, coverage: hit_count, inline: start_line == condition_start_line, type: type ) end def line_coverage_statistics { line: CoverageStatistics.new( total_strength: lines_strength, covered: covered_lines.size, missed: missed_lines.size ) } end def branch_coverage_statistics { branch: CoverageStatistics.new( covered: covered_branches.size, missed: missed_branches.size ) } end end end
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/lib/simplecov/filter.rb
lib/simplecov/filter.rb
# frozen_string_literal: true module SimpleCov # # Base filter class. Inherit from this to create custom filters, # and overwrite the passes?(source_file) instance method # # # A sample class that rejects all source files. # class StupidFilter < SimpleCov::Filter # def passes?(source_file) # false # end # end # class Filter attr_reader :filter_argument def initialize(filter_argument) @filter_argument = filter_argument end def matches?(_source_file) raise "The base filter class is not intended for direct use" end def passes?(source_file) warn "#{Kernel.caller.first}: [DEPRECATION] #passes? is deprecated. Use #matches? instead." matches?(source_file) end def self.build_filter(filter_argument) return filter_argument if filter_argument.is_a?(SimpleCov::Filter) class_for_argument(filter_argument).new(filter_argument) end def self.class_for_argument(filter_argument) case filter_argument when String SimpleCov::StringFilter when Regexp SimpleCov::RegexFilter when Array SimpleCov::ArrayFilter when Proc SimpleCov::BlockFilter else raise ArgumentError, "You have provided an unrecognized filter type" end end end class StringFilter < SimpleCov::Filter # Returns true when the given source file's filename matches the # string configured when initializing this Filter with StringFilter.new('somestring') def matches?(source_file) source_file.project_filename.include?(filter_argument) end end class RegexFilter < SimpleCov::Filter # Returns true when the given source file's filename matches the # regex configured when initializing this Filter with RegexFilter.new(/someregex/) def matches?(source_file) (source_file.project_filename =~ filter_argument) end end class BlockFilter < SimpleCov::Filter # Returns true if the block given when initializing this filter with BlockFilter.new {|src_file| ... } # returns true for the given source file. def matches?(source_file) filter_argument.call(source_file) end end class ArrayFilter < SimpleCov::Filter def initialize(filter_argument) filter_objects = filter_argument.map do |arg| Filter.build_filter(arg) end super(filter_objects) end # Returns true if any of the filters in the array match the given source file. # Configure this Filter like StringFilter.new(['some/path', /^some_regex/, Proc.new {|src_file| ... }]) def matches?(source_files_list) filter_argument.any? do |arg| arg.matches?(source_files_list) end end end end
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/lib/simplecov/last_run.rb
lib/simplecov/last_run.rb
# frozen_string_literal: true require "json" module SimpleCov module LastRun class << self def last_run_path File.join(SimpleCov.coverage_path, ".last_run.json") end def read return nil unless File.exist?(last_run_path) json = File.read(last_run_path) return nil if json.strip.empty? JSON.parse(json, symbolize_names: true) end def write(json) File.open(last_run_path, "w+") do |f| f.puts JSON.pretty_generate(json) end end end end end
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/lib/simplecov/result.rb
lib/simplecov/result.rb
# frozen_string_literal: true require "digest/sha1" require "forwardable" module SimpleCov # # A simplecov code coverage result, initialized from the Hash Ruby's built-in coverage # library generates (Coverage.result). # class Result extend Forwardable # Returns the original Coverage.result used for this instance of SimpleCov::Result attr_reader :original_result # Returns all files that are applicable to this result (sans filters!) as instances of SimpleCov::SourceFile. Aliased as :source_files attr_reader :files alias source_files files # Explicitly set the Time this result has been created attr_writer :created_at # Explicitly set the command name that was used for this coverage result. Defaults to SimpleCov.command_name attr_writer :command_name def_delegators :files, :covered_percent, :covered_percentages, :least_covered_file, :covered_strength, :covered_lines, :missed_lines, :total_branches, :covered_branches, :missed_branches, :coverage_statistics, :coverage_statistics_by_file def_delegator :files, :lines_of_code, :total_lines # Initialize a new SimpleCov::Result from given Coverage.result (a Hash of filenames each containing an array of # coverage data) def initialize(original_result, command_name: nil, created_at: nil) result = original_result @original_result = result.freeze @command_name = command_name @created_at = created_at @files = SimpleCov::FileList.new(result.map do |filename, coverage| SimpleCov::SourceFile.new(filename, JSON.parse(JSON.dump(coverage))) if File.file?(filename) end.compact.sort_by(&:filename)) filter! end # Returns all filenames for source files contained in this result def filenames files.map(&:filename) end # Returns a Hash of groups for this result. Define groups using SimpleCov.add_group 'Models', 'app/models' def groups @groups ||= SimpleCov.grouped(files) end # Applies the configured SimpleCov.formatter on this result def format! SimpleCov.formatter.new.format(self) end # Defines when this result has been created. Defaults to Time.now def created_at @created_at ||= Time.now end # The command name that launched this result. # Delegated to SimpleCov.command_name if not set manually def command_name @command_name ||= SimpleCov.command_name end # Returns a hash representation of this Result that can be used for marshalling it into JSON def to_hash { command_name => { "coverage" => coverage, "timestamp" => created_at.to_i } } end # Loads a SimpleCov::Result#to_hash dump def self.from_hash(hash) hash.map do |command_name, data| new(data.fetch("coverage"), command_name: command_name, created_at: Time.at(data["timestamp"])) end end private def coverage keys = original_result.keys & filenames keys.zip(original_result.values_at(*keys)).to_h end # Applies all configured SimpleCov filters on this result's source files def filter! @files = SimpleCov.filtered(files) end end end
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/lib/simplecov/combine.rb
lib/simplecov/combine.rb
# frozen_string_literal: true module SimpleCov # Functionally for combining coverage results # module Combine module_function # # Combine two coverage based on the given combiner_module. # # Combiners should always be called through this interface, # as it takes care of short-circuiting of one of the coverages is nil. # # @return [Hash] def combine(combiner_module, coverage_a, coverage_b) return existing_coverage(coverage_a, coverage_b) if empty_coverage?(coverage_a, coverage_b) combiner_module.combine(coverage_a, coverage_b) end def empty_coverage?(coverage_a, coverage_b) !(coverage_a && coverage_b) end def existing_coverage(coverage_a, coverage_b) coverage_a || coverage_b end end end
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/lib/simplecov/no_defaults.rb
lib/simplecov/no_defaults.rb
# frozen_string_literal: true ENV["SIMPLECOV_NO_DEFAULTS"] = "yes, no defaults" require_relative "../simplecov"
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/lib/simplecov/useless_results_remover.rb
lib/simplecov/useless_results_remover.rb
# frozen_string_literal: true module SimpleCov # # Select the files that related to working scope directory of SimpleCov # module UselessResultsRemover def self.call(coverage_result) coverage_result.select do |path, _coverage| path =~ root_regx end end def self.root_regx @root_regx ||= /\A#{Regexp.escape(SimpleCov.root + File::SEPARATOR)}/i end end end
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/lib/simplecov/configuration.rb
lib/simplecov/configuration.rb
# frozen_string_literal: true require "fileutils" require "docile" require_relative "formatter/multi_formatter" module SimpleCov # # Bundles the configuration options used for SimpleCov. All methods # defined here are usable from SimpleCov directly. Please check out # SimpleCov documentation for further info. # module Configuration attr_writer :filters, :groups, :formatter, :print_error_status # # The root for the project. This defaults to the # current working directory. # # Configure with SimpleCov.root('/my/project/path') # def root(root = nil) return @root if defined?(@root) && root.nil? @coverage_path = nil # invalidate cache @root = File.expand_path(root || Dir.getwd) end # # The name of the output and cache directory. Defaults to 'coverage' # # Configure with SimpleCov.coverage_dir('cov') # def coverage_dir(dir = nil) return @coverage_dir if defined?(@coverage_dir) && dir.nil? @coverage_path = nil # invalidate cache @coverage_dir = dir || "coverage" end # # Returns the full path to the output directory using SimpleCov.root # and SimpleCov.coverage_dir, so you can adjust this by configuring those # values. Will create the directory if it's missing # def coverage_path @coverage_path ||= begin coverage_path = File.expand_path(coverage_dir, root) FileUtils.mkdir_p coverage_path coverage_path end end # # Coverage results will always include files matched by this glob, whether # or not they were explicitly required. Without this, un-required files # will not be present in the final report. # def track_files(glob) @tracked_files = glob end # # Returns the glob that will be used to include files that were not # explicitly required. # def tracked_files @tracked_files if defined?(@tracked_files) end # # Returns the list of configured filters. Add filters using SimpleCov.add_filter. # def filters @filters ||= [] end # The name of the command (a.k.a. Test Suite) currently running. Used for result # merging and caching. It first tries to make a guess based upon the command line # arguments the current test suite is running on and should automatically detect # unit tests, functional tests, integration tests, rpsec and cucumber and label # them properly. If it fails to recognize the current command, the command name # is set to the shell command that the current suite is running on. # # You can specify it manually with SimpleCov.command_name("test:units") - please # also check out the corresponding section in README.rdoc def command_name(name = nil) @name = name unless name.nil? @name ||= SimpleCov::CommandGuesser.guess @name end # # Gets or sets the configured formatter. # # Configure with: SimpleCov.formatter(SimpleCov::Formatter::SimpleFormatter) # def formatter(formatter = nil) return @formatter if defined?(@formatter) && formatter.nil? @formatter = formatter raise "No formatter configured. Please specify a formatter using SimpleCov.formatter = SimpleCov::Formatter::SimpleFormatter" unless @formatter @formatter end # # Sets the configured formatters. # def formatters=(formatters) @formatter = SimpleCov::Formatter::MultiFormatter.new(formatters) end # # Gets the configured formatters. # def formatters if @formatter.is_a?(SimpleCov::Formatter::MultiFormatter) @formatter.formatters else Array(formatter) end end # # Whether we should print non-success status codes. This can be # configured with the #print_error_status= method. # def print_error_status defined?(@print_error_status) ? @print_error_status : true end # # Certain code blocks (i.e. Ruby-implementation specific code) can be excluded from # the coverage metrics by wrapping it inside # :nocov: comment blocks. The nocov token # can be configured to be any other string using this. # # Configure with SimpleCov.nocov_token('skip') or it's alias SimpleCov.skip_token('skip') # def nocov_token(nocov_token = nil) return @nocov_token if defined?(@nocov_token) && nocov_token.nil? @nocov_token = nocov_token || "nocov" end alias skip_token nocov_token # # Returns the configured groups. Add groups using SimpleCov.add_group # def groups @groups ||= {} end # # Returns the hash of available profiles # def profiles @profiles ||= SimpleCov::Profiles.new end def adapters warn "#{Kernel.caller.first}: [DEPRECATION] #adapters is deprecated. Use #profiles instead." profiles end # # Allows you to configure simplecov in a block instead of prepending SimpleCov to all config methods # you're calling. # # SimpleCov.configure do # add_filter 'foobar' # end # # This is equivalent to SimpleCov.add_filter 'foobar' and thus makes it easier to set a bunch of configure # options at once. # def configure(&block) Docile.dsl_eval(self, &block) end # # Gets or sets the behavior to process coverage results. # # By default, it will call SimpleCov.result.format! # # Configure with: # # SimpleCov.at_exit do # puts "Coverage done" # SimpleCov.result.format! # end # def at_exit(&block) return Proc.new unless running || block @at_exit = block if block @at_exit ||= proc { SimpleCov.result.format! } end # gets or sets the enabled_for_subprocess configuration # when true, this will inject SimpleCov code into Process.fork def enable_for_subprocesses(value = nil) return @enable_for_subprocesses if defined?(@enable_for_subprocesses) && value.nil? @enable_for_subprocesses = value || false end # gets the enabled_for_subprocess configuration def enabled_for_subprocesses? enable_for_subprocesses end # # Gets or sets the behavior to start a new forked Process. # # By default, it will add " (Process #{pid})" to the command_name, and start SimpleCov in quiet mode # # Configure with: # # SimpleCov.at_fork do |pid| # SimpleCov.start do # # This needs a unique name so it won't be ovewritten # SimpleCov.command_name "#{SimpleCov.command_name} (subprocess: #{pid})" # # be quiet, the parent process will be in charge of using the regular formatter and checking coverage totals # SimpleCov.print_error_status = false # SimpleCov.formatter SimpleCov::Formatter::SimpleFormatter # SimpleCov.minimum_coverage 0 # # start # SimpleCov.start # end # end # def at_fork(&block) @at_fork = block if block @at_fork ||= lambda { |pid| # This needs a unique name so it won't be ovewritten SimpleCov.command_name "#{SimpleCov.command_name} (subprocess: #{pid})" # be quiet, the parent process will be in charge of using the regular formatter and checking coverage totals SimpleCov.print_error_status = false SimpleCov.formatter SimpleCov::Formatter::SimpleFormatter SimpleCov.minimum_coverage 0 # start SimpleCov.start } end # # Returns the project name - currently assuming the last dirname in # the SimpleCov.root is this. # def project_name(new_name = nil) return @project_name if defined?(@project_name) && @project_name && new_name.nil? @project_name = new_name if new_name.is_a?(String) @project_name ||= File.basename(root.split("/").last).capitalize.tr("_", " ") end # # Defines whether to use result merging so all your test suites (test:units, test:functionals, cucumber, ...) # are joined and combined into a single coverage report # def use_merging(use = nil) @use_merging = use unless use.nil? @use_merging = true unless defined?(@use_merging) && @use_merging == false end # # Defines the maximum age (in seconds) of a resultset to still be included in merged results. # i.e. If you run cucumber features, then later rake test, if the stored cucumber resultset is # more seconds ago than specified here, it won't be taken into account when merging (and is also # purged from the resultset cache) # # Of course, this only applies when merging is active (e.g. SimpleCov.use_merging is not false!) # # Default is 600 seconds (10 minutes) # # Configure with SimpleCov.merge_timeout(3600) # 1hr # def merge_timeout(seconds = nil) @merge_timeout = seconds if seconds.is_a?(Integer) @merge_timeout ||= 600 end # # Defines the minimum overall coverage required for the testsuite to pass. # SimpleCov will return non-zero if the current coverage is below this threshold. # # Default is 0% (disabled) # def minimum_coverage(coverage = nil) return @minimum_coverage ||= {} unless coverage coverage = {primary_coverage => coverage} if coverage.is_a?(Numeric) raise_on_invalid_coverage(coverage, "minimum_coverage") @minimum_coverage = coverage end def raise_on_invalid_coverage(coverage, coverage_setting) coverage.each_key { |criterion| raise_if_criterion_disabled(criterion) } coverage.each_value do |percent| minimum_possible_coverage_exceeded(coverage_setting) if percent && percent > 100 end end # # Defines the maximum coverage drop at once allowed for the testsuite to pass. # SimpleCov will return non-zero if the coverage decreases by more than this threshold. # # Default is 100% (disabled) # def maximum_coverage_drop(coverage_drop = nil) return @maximum_coverage_drop ||= {} unless coverage_drop coverage_drop = {primary_coverage => coverage_drop} if coverage_drop.is_a?(Numeric) raise_on_invalid_coverage(coverage_drop, "maximum_coverage_drop") @maximum_coverage_drop = coverage_drop end # # Defines the minimum coverage per file required for the testsuite to pass. # SimpleCov will return non-zero if the current coverage of the least covered file # is below this threshold. # # Default is 0% (disabled) # def minimum_coverage_by_file(coverage = nil) return @minimum_coverage_by_file ||= {} unless coverage coverage = {primary_coverage => coverage} if coverage.is_a?(Numeric) raise_on_invalid_coverage(coverage, "minimum_coverage_by_file") @minimum_coverage_by_file = coverage end # # Refuses any coverage drop. That is, coverage is only allowed to increase. # SimpleCov will return non-zero if the coverage decreases. # def refuse_coverage_drop(*criteria) criteria = coverage_criteria if criteria.empty? maximum_coverage_drop(criteria.map { |c| [c, 0] }.to_h) end # # Add a filter to the processing chain. # There are four ways to define a filter: # # * as a String that will then be matched against all source files' file paths, # SimpleCov.add_filter 'app/models' # will reject all your models # * as a block which will be passed the source file in question and should either # return a true or false value, depending on whether the file should be removed # SimpleCov.add_filter do |src_file| # File.basename(src_file.filename) == 'environment.rb' # end # Will exclude environment.rb files from the results # * as an array of strings that are matched against all source files' file # paths and then ignored (basically string filter multiple times) # SimpleCov.add_filter ['app/models', 'app/helpers'] # ignores both dirs # * as an instance of a subclass of SimpleCov::Filter. See the documentation there # on how to define your own filter classes # def add_filter(filter_argument = nil, &filter_proc) filters << parse_filter(filter_argument, &filter_proc) end # # Define a group for files. Works similar to add_filter, only that the first # argument is the desired group name and files PASSING the filter end up in the group # (while filters exclude when the filter is applicable). # def add_group(group_name, filter_argument = nil, &filter_proc) groups[group_name] = parse_filter(filter_argument, &filter_proc) end SUPPORTED_COVERAGE_CRITERIA = %i[line branch].freeze DEFAULT_COVERAGE_CRITERION = :line # # Define which coverage criterion should be evaluated. # # Possible coverage criteria: # * :line - coverage based on lines aka has this line been executed? # * :branch - coverage based on branches aka has this branch (think conditions) been executed? # # If not set the default is `:line` # # @param [Symbol] criterion # def coverage_criterion(criterion = nil) return @coverage_criterion ||= primary_coverage unless criterion raise_if_criterion_unsupported(criterion) @coverage_criterion = criterion end def enable_coverage(criterion) raise_if_criterion_unsupported(criterion) coverage_criteria << criterion end def primary_coverage(criterion = nil) if criterion.nil? @primary_coverage ||= DEFAULT_COVERAGE_CRITERION else raise_if_criterion_disabled(criterion) @primary_coverage = criterion end end def coverage_criteria @coverage_criteria ||= Set[primary_coverage] end def coverage_criterion_enabled?(criterion) coverage_criteria.member?(criterion) end def clear_coverage_criteria @coverage_criteria = nil end def branch_coverage? branch_coverage_supported? && coverage_criterion_enabled?(:branch) end def coverage_start_arguments_supported? # safe to cache as within one process this value should never # change return @coverage_start_arguments_supported if defined?(@coverage_start_arguments_supported) @coverage_start_arguments_supported = begin require "coverage" !Coverage.method(:start).arity.zero? end end def branch_coverage_supported? coverage_start_arguments_supported? && RUBY_ENGINE != "jruby" end def coverage_for_eval_supported? require "coverage" defined?(Coverage.supported?) && Coverage.supported?(:eval) end def coverage_for_eval_enabled? @coverage_for_eval_enabled ||= false end def enable_coverage_for_eval if coverage_for_eval_supported? @coverage_for_eval_enabled = true else warn "Coverage for eval is not available; Use Ruby 3.2.0 or later" end end private def raise_if_criterion_disabled(criterion) raise_if_criterion_unsupported(criterion) # rubocop:disable Style/IfUnlessModifier unless coverage_criterion_enabled?(criterion) raise "Coverage criterion #{criterion}, is disabled! Please enable it first through enable_coverage #{criterion} (if supported)" end # rubocop:enable Style/IfUnlessModifier end def raise_if_criterion_unsupported(criterion) # rubocop:disable Style/IfUnlessModifier unless SUPPORTED_COVERAGE_CRITERIA.member?(criterion) raise "Unsupported coverage criterion #{criterion}, supported values are #{SUPPORTED_COVERAGE_CRITERIA}" end # rubocop:enable Style/IfUnlessModifier end def minimum_possible_coverage_exceeded(coverage_option) warn "The coverage you set for #{coverage_option} is greater than 100%" end # # The actual filter processor. Not meant for direct use # def parse_filter(filter_argument = nil, &filter_proc) filter = filter_argument || filter_proc if filter SimpleCov::Filter.build_filter(filter) else raise ArgumentError, "Please specify either a filter or a block to filter with" end end end end
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/lib/simplecov/process.rb
lib/simplecov/process.rb
# frozen_string_literal: true module Process class << self def fork_with_simplecov(&block) if defined?(SimpleCov) && SimpleCov.running fork_without_simplecov do SimpleCov.at_fork.call(Process.pid) yield if block end else fork_without_simplecov(&block) end end alias fork_without_simplecov fork alias fork fork_with_simplecov end end
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/lib/simplecov/result_merger.rb
lib/simplecov/result_merger.rb
# frozen_string_literal: true require "json" module SimpleCov # # Singleton that is responsible for caching, loading and merging # SimpleCov::Results into a single result for coverage analysis based # upon multiple test suites. # module ResultMerger class << self # The path to the .resultset.json cache file def resultset_path File.join(SimpleCov.coverage_path, ".resultset.json") end def resultset_writelock File.join(SimpleCov.coverage_path, ".resultset.json.lock") end def merge_and_store(*file_paths, ignore_timeout: false) result = merge_results(*file_paths, ignore_timeout: ignore_timeout) store_result(result) if result result end def merge_results(*file_paths, ignore_timeout: false) # It is intentional here that files are only read in and parsed one at a time. # # In big CI setups you might deal with 100s of CI jobs and each one producing Megabytes # of data. Reading them all in easily produces Gigabytes of memory consumption which # we want to avoid. # # For similar reasons a SimpleCov::Result is only created in the end as that'd create # even more data especially when it also reads in all source files. initial_memo = valid_results(file_paths.shift, ignore_timeout: ignore_timeout) command_names, coverage = file_paths.reduce(initial_memo) do |memo, file_path| merge_coverage(memo, valid_results(file_path, ignore_timeout: ignore_timeout)) end create_result(command_names, coverage) end def valid_results(file_path, ignore_timeout: false) results = parse_file(file_path) merge_valid_results(results, ignore_timeout: ignore_timeout) end def parse_file(path) data = read_file(path) parse_json(data) end def read_file(path) return unless File.exist?(path) data = File.read(path) return if data.nil? || data.length < 2 data end def parse_json(content) return {} unless content JSON.parse(content) || {} rescue StandardError warn "[SimpleCov]: Warning! Parsing JSON content of resultset file failed" {} end def merge_valid_results(results, ignore_timeout: false) results = results.select { |_command_name, data| within_merge_timeout?(data) } unless ignore_timeout command_plus_coverage = results.map do |command_name, data| [[command_name], adapt_result(data.fetch("coverage"))] end # one file itself _might_ include multiple test runs merge_coverage(*command_plus_coverage) end def within_merge_timeout?(data) time_since_result_creation(data) < SimpleCov.merge_timeout end def time_since_result_creation(data) Time.now - Time.at(data.fetch("timestamp")) end def create_result(command_names, coverage) return nil unless coverage command_name = command_names.reject(&:empty?).sort.join(", ") SimpleCov::Result.new(coverage, command_name: command_name) end def merge_coverage(*results) return [[""], nil] if results.empty? return results.first if results.size == 1 results.reduce do |(memo_command, memo_coverage), (command, coverage)| # timestamp is dropped here, which is intentional (we merge it, it gets a new time stamp as of now) merged_coverage = Combine.combine(Combine::ResultsCombiner, memo_coverage, coverage) merged_command = memo_command + command [merged_command, merged_coverage] end end # # Gets all SimpleCov::Results stored in resultset, merges them and produces a new # SimpleCov::Result with merged coverage data and the command_name # for the result consisting of a join on all source result's names def merged_result # conceptually this is just doing `merge_results(resultset_path)` # it's more involved to make syre `synchronize_resultset` is only used around reading resultset_hash = read_resultset command_names, coverage = merge_valid_results(resultset_hash) create_result(command_names, coverage) end def read_resultset resultset_content = synchronize_resultset do read_file(resultset_path) end parse_json(resultset_content) end # Saves the given SimpleCov::Result in the resultset cache def store_result(result) synchronize_resultset do # Ensure we have the latest, in case it was already cached new_resultset = read_resultset # A single result only ever has one command_name, see `SimpleCov::Result#to_hash` command_name, data = result.to_hash.first new_resultset[command_name] = data File.open(resultset_path, "w+") do |f_| f_.puts JSON.pretty_generate(new_resultset) end end true end # Ensure only one process is reading or writing the resultset at any # given time def synchronize_resultset # make it reentrant return yield if defined?(@resultset_locked) && @resultset_locked begin @resultset_locked = true File.open(resultset_writelock, "w+") do |f| f.flock(File::LOCK_EX) yield end ensure @resultset_locked = false end end # We changed the format of the raw result data in simplecov, as people are likely # to have "old" resultsets lying around (but not too old so that they're still # considered we can adapt them). # See https://github.com/simplecov-ruby/simplecov/pull/824#issuecomment-576049747 def adapt_result(result) if pre_simplecov_0_18_result?(result) adapt_pre_simplecov_0_18_result(result) else result end end # pre 0.18 coverage data pointed from file directly to an array of line coverage def pre_simplecov_0_18_result?(result) _key, data = result.first data.is_a?(Array) end def adapt_pre_simplecov_0_18_result(result) result.transform_values do |line_coverage_data| {"lines" => line_coverage_data} end end end end end
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/lib/simplecov/default_formatter.rb
lib/simplecov/default_formatter.rb
# frozen_string_literal: true require "simplecov-html" module SimpleCov module Formatter class << self def from_env(env) formatters = [SimpleCov::Formatter::HTMLFormatter] # When running under a CI that uses CodeClimate, JSON output is expected if env.fetch("CC_TEST_REPORTER_ID", nil) require "simplecov_json_formatter" formatters.push(SimpleCov::Formatter::JSONFormatter) end formatters end end end end
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false
simplecov-ruby/simplecov
https://github.com/simplecov-ruby/simplecov/blob/afcf15e42fde20abbdb6fe9591a3e5d98acc088e/lib/simplecov/file_list.rb
lib/simplecov/file_list.rb
# frozen_string_literal: true module SimpleCov # An array of SimpleCov SourceFile instances with additional collection helper # methods for calculating coverage across them etc. class FileList include Enumerable extend Forwardable def_delegators :@files, # For Enumerable :each, # also delegating methods implemented in Enumerable as they have # custom Array implementations which are presumably better/more # resource efficient :size, :map, :count, # surprisingly not in Enumerable :empty?, :length, # still act like we're kinda an array :to_a, :to_ary def initialize(files) @files = files end def coverage_statistics @coverage_statistics ||= compute_coverage_statistics end def coverage_statistics_by_file @coverage_statistics_by_file ||= compute_coverage_statistics_by_file end # Returns the count of lines that have coverage def covered_lines coverage_statistics[:line]&.covered end # Returns the count of lines that have been missed def missed_lines coverage_statistics[:line]&.missed end # Returns the count of lines that are not relevant for coverage def never_lines return 0.0 if empty? map { |f| f.never_lines.count }.inject(:+) end # Returns the count of skipped lines def skipped_lines return 0.0 if empty? map { |f| f.skipped_lines.count }.inject(:+) end # Computes the coverage based upon lines covered and lines missed for each file # Returns an array with all coverage percentages def covered_percentages map(&:covered_percent) end # Finds the least covered file and returns that file's name def least_covered_file min_by(&:covered_percent).filename end # Returns the overall amount of relevant lines of code across all files in this list def lines_of_code coverage_statistics[:line]&.total end # Computes the coverage based upon lines covered and lines missed # @return [Float] def covered_percent coverage_statistics[:line]&.percent end # Computes the strength (hits / line) based upon lines covered and lines missed # @return [Float] def covered_strength coverage_statistics[:line]&.strength end # Return total count of branches in all files def total_branches coverage_statistics[:branch]&.total end # Return total count of covered branches def covered_branches coverage_statistics[:branch]&.covered end # Return total count of covered branches def missed_branches coverage_statistics[:branch]&.missed end def branch_covered_percent coverage_statistics[:branch]&.percent end private def compute_coverage_statistics_by_file @files.each_with_object(line: [], branch: []) do |file, together| together[:line] << file.coverage_statistics.fetch(:line) together[:branch] << file.coverage_statistics.fetch(:branch) if SimpleCov.branch_coverage? end end def compute_coverage_statistics coverage_statistics = {line: CoverageStatistics.from(coverage_statistics_by_file[:line])} coverage_statistics[:branch] = CoverageStatistics.from(coverage_statistics_by_file[:branch]) if SimpleCov.branch_coverage? coverage_statistics end end end
ruby
MIT
afcf15e42fde20abbdb6fe9591a3e5d98acc088e
2026-01-04T15:45:13.013465Z
false