{"id":16070628,"url":"https://github.com/danmayer/coverage-bug","last_synced_at":"2026-04-23T15:36:22.233Z","repository":{"id":17901299,"uuid":"20856175","full_name":"danmayer/coverage-bug","owner":"danmayer","description":"This shows a bug with Ruby's Coverage","archived":false,"fork":false,"pushed_at":"2018-01-15T21:39:41.000Z","size":11,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-19T15:48:02.634Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/danmayer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-06-15T13:35:49.000Z","updated_at":"2018-01-13T19:48:13.000Z","dependencies_parsed_at":"2022-08-31T20:24:43.044Z","dependency_job_id":null,"html_url":"https://github.com/danmayer/coverage-bug","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danmayer%2Fcoverage-bug","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danmayer%2Fcoverage-bug/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danmayer%2Fcoverage-bug/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/danmayer%2Fcoverage-bug/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/danmayer","download_url":"https://codeload.github.com/danmayer/coverage-bug/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243307334,"owners_count":20270256,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-09T07:05:54.250Z","updated_at":"2025-12-26T16:02:45.644Z","avatar_url":"https://github.com/danmayer.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"Ruby coverage-bug\n============\n\nThis shows a bug with Ruby's Coverage, as tracked on [ruby bug tracker #9572](https://bugs.ruby-lang.org/issues/9572).\n\nto execute just run: `ruby ./example.rb`\n\nThis demonstrates why Coverage from the ruby std-lib isn't useful for the kind of data I want to get from coverband.\n\nprevious output (Ruby \u003c= 2.1.1)\n\n```ruby\nmethod_a called\n{\"/Users/danmayer/projects/coverage-bug/covercheck.rb\"=\u003e[1, 1, nil, nil, 1, 0, nil, nil, 1, 1, nil, 0, nil, 0, 0, 0, nil, nil, nil, nil, nil, nil, nil, nil, nil]}\nthis doesn't matter and is between coverage\nmethod_b_called\n{\"/Users/danmayer/projects/coverage-bug/covercheck.rb\"=\u003e[]}\n```\n\ncurrent output:\n\n```ruby\nmethod_a called\n{\"/Users/danmayer/projects/coverage-bug/covercheck.rb\"=\u003e[1, 1, nil, nil, 1, 0, nil, nil, 1, 1, nil, 0, nil, 0, 0, 0, nil, nil, nil, nil, nil, nil, nil, nil, nil]}\nthis doesn't matter and is between coverage\nmethod_b_called\n{}\n```\n\ndesired output:\n\n```ruby\nmethod_a called\n{\"/Users/danmayer/projects/coverage-bug/covercheck.rb\"=\u003e[1, 1, nil, nil, 1, 0, nil, nil, 1, 1, nil, 0, nil, 0, 0, 0, nil, nil, nil, nil, nil, nil, nil, nil, nil]}\nthis doesn't matter and is between coverage\nmethod_b_called\n{\"/Users/danmayer/projects/coverage-bug/covercheck.rb\"=\u003e[0, 0, nil, nil, 1, 1, nil, nil, 0, 0, nil, 0, nil, 1, 1, 1, nil, nil, nil, nil, nil, nil, nil, nil, nil]}\n```\n\n# Proposal\n\nI would still like to have access to a re-entrant coverage, but given upstream chances since this initial bug, Ruby no longer returns `{'file.rb' =\u003e []}` as it was inaccurate to say the file had nothing. Currently, Ruby has removed all the files that were required prior to the initial coverage.start call. The method is re-entrant, but only works for **newly required** files.\n\nI am thinking perhaps that functionality is intended and used for some use cases. It doesn't fit my use case or expectations. I am now considering a different approach to achieve what I would like. I think my needs would be better met with a new API with additional functionality for the Coverage object. This is similar to how `peek_result` was added to coverage. That didn't change the current expectations of any of the existing public API.\n\nThoughts are we could add the below methods to the public API:\n\n```ruby \nCoverage.pause # removes event hooks, leaving data intact\nCoverage.reset # leaves all data tracking, but resets counts to 0\nCoverage.resume # adds back event hooks\n```\n\nWhich could be used to collect coverage results on demand over time, enabling and disabling as needed. The example below illustrates basic usage\n\n`example.rb`\n\n```ruby\nrequire 'coverage'\nCoverage.start\nrequire './covercheck'\n```\n\n`covercheck.rb`\n\n```ruby\ndef method_a\n  puts \"method_a called\"\nend\n \ndef method_b\n  puts \"method_b_called\"\nend\n\nmethod_a\n\nputs Coverage.pause\nputs Coverage.peek_result\nputs Coverage.reset\n \nputs \"this line is run between coverage being enabled and shouldn't get tracked\"\n \nCoverage.resume\nmethod_b\nputs Coverage.result\n```\n\nThe expected results would be something like below:\n\n```ruby\nmethod_a called\n{\"/Users/danmayer/projects/coverage-bug/covercheck.rb\"=\u003e[1, 1, nil, nil, 1, 0, nil, nil, 1, 1, nil, 0, nil, 0, 0, 0]}\nputs \"this line is run between coverage being enabled and shouldn't get tracked\"\nmethod_b_called\n{\"/Users/danmayer/projects/coverage-bug/covercheck.rb\"=\u003e[0, 0, nil, nil, 1, 1, nil, nil, 1, 1, nil, 0, nil, 1, 1, 1]}\n```\n\nThis could allow some extremely interesting code usage tracking, such as pausing and resuming in before / after hooks in Rails to track usage only in particular routes, controllers, modules, or etc. Using reset you could get just changes during a given run, or user could not reset the data and build up a results set over time, but still only incur the performance overhead on a very specific section of code.\n\nI intend to be able to expand the capabilities of [Coverband](https://github.com/danmayer/coverband) using this feature as well as reduce the performance costs it currently incurs to run it.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanmayer%2Fcoverage-bug","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdanmayer%2Fcoverage-bug","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdanmayer%2Fcoverage-bug/lists"}