pax_global_header 0000666 0000000 0000000 00000000064 14351411403 0014506 g ustar 00root root 0000000 0000000 52 comment=0e35b257e24381e4ec2c99b321954509ae21eaf0
simplecov-0.22.0/ 0000775 0000000 0000000 00000000000 14351411403 0013570 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/.github/ 0000775 0000000 0000000 00000000000 14351411403 0015130 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/.github/workflows/ 0000775 0000000 0000000 00000000000 14351411403 0017165 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/.github/workflows/stable.yml 0000664 0000000 0000000 00000001661 14351411403 0021166 0 ustar 00root root 0000000 0000000 name: stable
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
ruby: [2.7, '3.0', 3.1, ruby-head, jruby-9.3]
env:
BUNDLE_WITHOUT: "benchmark"
JRUBY_OPTS: "--debug"
steps:
- uses: actions/checkout@v2
- name: Get sqlite for Rails test projects
run: sudo apt-get install libsqlite3-dev
- name: Setup ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true # 'bundle install' and cache
- name: Get the newest rubygems version to rid ourselves of warnings
run: gem update --system --no-document
- name: Install bundler
run: gem i bundler --no-document
- name: Install dependencies
run: |
bundle config set --local without benchmark
bundle install --jobs=3
- name: Run tests
run: bundle exec rake
simplecov-0.22.0/.github/workflows/unstable.yml 0000664 0000000 0000000 00000002277 14351411403 0021535 0 ustar 00root root 0000000 0000000 name: unstable
on:
schedule:
- cron: '0 0 * * *'
jobs:
test:
runs-on: ubuntu-16.04
strategy:
matrix:
ruby: [ruby-head, jruby-head]
steps:
- uses: actions/checkout@v2
- name: Set up RVM
run: curl -sSL https://get.rvm.io | bash
- name: Set up Ruby
run: |
source $HOME/.rvm/scripts/rvm
rvm install ${{ matrix.ruby }} --binary --autolibs=disable
rvm --default use ${{ matrix.ruby }}
- name: Install java
run: sudo apt-get -y install openjdk-8-jre-headless
if: matrix.ruby == 'jruby-head'
- name: Get sqlite for Rails test projects
run: sudo apt-get install libsqlite3-dev
- name: Install dependencies
run: |
source $HOME/.rvm/scripts/rvm
bundle config set --local without benchmark
bundle install --jobs=3
- name: Run tests (MRI)
run: |
source $HOME/.rvm/scripts/rvm
bundle exec rake
if: matrix.ruby == 'ruby-head'
- name: Run tests (JRuby)
run: |
source $HOME/.rvm/scripts/rvm
JRUBY_OPTS=--debug bundle exec rake
if: matrix.ruby == 'jruby-head'
simplecov-0.22.0/.gitignore 0000664 0000000 0000000 00000000456 14351411403 0015565 0 ustar 00root root 0000000 0000000 .bundle
## MAC OS
.DS_Store
.document
## TEXTMATE
*.tmproj
tmtags
## EMACS
*~
\#*
.\#*
## VIM
*.swp
## PROJECT::GENERAL
/coverage
rdoc
pkg
tmp
.rvmrc
## PROJECT::SPECIFIC
.yardoc
spec/fixtures/coverage
spec/fixtures/frameworks/coverage
spec/fixtures/eval_test/coverage
test_projects/**/coverage
simplecov-0.22.0/.rspec 0000664 0000000 0000000 00000000041 14351411403 0014700 0 ustar 00root root 0000000 0000000 --color
--order random
--warning
simplecov-0.22.0/.rubocop.yml 0000664 0000000 0000000 00000020072 14351411403 0016043 0 ustar 00root root 0000000 0000000 AllCops:
Exclude:
- "spec/fixtures/iso-8859.rb"
- "spec/fixtures/utf-8.rb"
- "spec/fixtures/utf-8-magic.rb"
- "spec/fixtures/euc-jp.rb"
- "spec/fixtures/empty_euc-jp.rb"
- "spec/fixtures/euc-jp-shebang.rb"
- "test_projects/**/*"
- "tmp/**/*"
- "vendor/bundle/**/*"
- "vendor/bundle/**/.*"
TargetRubyVersion: 2.5
# we might wanna adopt rspec and rake but it's a bit annoying for now
SuggestExtensions: false
Bundler/OrderedGems:
Description: Gems should be alphabetically sorted within groups.
Enabled: false
Layout/AccessModifierIndentation:
Description: Modifiers should be indented as deep as method definitions,
or as deep as the class/module keyword, depending on configuration.
EnforcedStyle: outdent
Layout/EmptyLinesAroundAttributeAccessor:
Description: Keep blank lines around attribute accessors.
Enabled: true
# Open for revision would like table style but the impact
# would probably be huge
Layout/HashAlignment:
Enabled: false
Layout/HeredocIndentation:
Description: Checks the indentation of the here document bodies.
Enabled: false
Layout/LineLength:
Description: Checks the length of lines in the source code.
AllowURI: true
Enabled: false
Layout/SpaceAroundMethodCallOperator:
Description: Checks method call operators to not have spaces around them.
Enabled: true
Layout/SpaceBeforeBrackets:
Enabled: true
Layout/SpaceInsideHashLiteralBraces:
Description: Use spaces inside hash literal braces - or don't.
StyleGuide: https://github.com/rubocop-hq/ruby-style-guide#spaces-operators
EnforcedStyle: no_space
Lint/AmbiguousAssignment:
Enabled: true
Lint/AmbiguousRegexpLiteral:
Description: Checks for ambiguous regexp literals in the first argument of a method invocation without parentheses.
Exclude:
- "features/**/*_steps.rb"
- "spec/**/*_steps.rb"
- "tmp/**/*_steps.rb"
Lint/BinaryOperatorWithIdenticalOperands:
Enabled: true
Lint/ConstantDefinitionInBlock:
Exclude:
- "spec/**/*_spec.rb"
Lint/DeprecatedConstants:
Enabled: true
Lint/DeprecatedOpenSSLConstant:
Description: Don't use algorithm constants for `OpenSSL::Cipher` and `OpenSSL::Digest`.
Enabled: true
Lint/DuplicateBranch:
Enabled: true
Lint/DuplicateElsifCondition:
Enabled: true
Lint/DuplicateRegexpCharacterClassElement:
Enabled: true
Lint/DuplicateRescueException:
Enabled: true
Lint/EmptyBlock:
Enabled: true
Lint/EmptyClass:
Enabled: true
Lint/EmptyConditionalBody:
Enabled: true
Lint/FloatComparison:
Enabled: true
Lint/LambdaWithoutLiteralBlock:
Enabled: true
Lint/MissingSuper:
Enabled: true
Lint/MixedRegexpCaptureTypes:
Description: Do not mix named captures and numbered captures in a Regexp literal.
Enabled: true
Lint/NoReturnInBeginEndBlocks:
Enabled: true
Lint/NumberedParameterAssignment:
Enabled: true
Lint/OrAssignmentToConstant:
Enabled: true
Lint/OutOfRangeRegexpRef:
Enabled: true
Lint/RaiseException:
Description: Checks for `raise` or `fail` statements which are raising `Exception` class.
Enabled: true
Lint/RedundantDirGlobSort:
Enabled: true
Lint/SelfAssignment:
Enabled: true
Lint/StructNewOverride:
Description: Disallow overriding the `Struct` built-in methods via `Struct.new`.
Enabled: true
Lint/SymbolConversion:
Enabled: true
Lint/ToEnumArguments:
Enabled: true
Lint/TopLevelReturnWithArgument:
Enabled: true
Lint/TripleQuotes:
Enabled: true
Lint/UnexpectedBlockArity:
Enabled: true
Lint/UnmodifiedReduceAccumulator:
Enabled: true
Lint/UnreachableLoop:
Enabled: true
Metrics/AbcSize:
Description: Checks that the ABC size of methods is not higher than the configured maximum.
Max: 25 # TODO: Lower to 15
Metrics/BlockLength:
Description: Checks if the length of a block exceeds some maximum value.
Exclude:
- "spec/**/*.rb"
Metrics/BlockNesting:
Description: Avoid excessive block nesting.
StyleGuide: https://github.com/rubocop-hq/ruby-style-guide#three-is-the-number-thou-shalt-count
Max: 2
Metrics/ClassLength:
Max: 300
Metrics/MethodLength:
Description: Checks if the length of a method exceeds some maximum value.
CountComments: false
Max: 12 # TODO: Lower to 10
Metrics/ModuleLength:
Description: Avoid modules longer than 100 lines of code.
Max: 300
Exclude:
- "lib/simplecov.rb"
Metrics/ParameterLists:
Description: Avoid parameter lists longer than three or four parameters.
StyleGuide: https://github.com/rubocop-hq/ruby-style-guide#too-many-params
Max: 4
CountKeywordArgs: true
Naming/FileName:
Description: makes sure that Ruby source files have snake_case names.
Exclude:
- "spec/fixtures/utf-8.rb"
Style/AccessorGrouping:
Enabled: true
Style/ArgumentsForwarding:
Enabled: true
Style/ArrayCoercion:
Enabled: true
Style/BisectedAttrAccessor:
Enabled: true
Style/CaseLikeIf:
Enabled: true
Style/CollectionCompact:
Enabled: true
Style/CollectionMethods:
Description: Enforces the use of consistent method names from the Enumerable module.
PreferredMethods:
map: "collect"
reduce: "inject"
find: "detect"
find_all: "select"
Style/Documentation:
Description: Checks for missing top-level documentation of classes and modules.
Enabled: false
Style/DoubleNegation:
Description: Checks for uses of double negation (!!).
StyleGuide: https://github.com/rubocop-hq/ruby-style-guide#no-bang-bang
Enabled: false
Style/DocumentDynamicEvalDefinition:
Enabled: true
Style/EndlessMethod:
Enabled: true
Style/ExplicitBlockArgument:
# capturing as a proc has a performance hit, so is a case by case choice
Enabled: false
Style/ExponentialNotation:
Description: When using exponential notation, favor a mantissa between 1 (inclusive) and 10 (exclusive).
Enabled: true
Style/FrozenStringLiteralComment:
Description:
Add the frozen_string_literal comment to the top of files to help transition
from Ruby 2.3.0 to Ruby 3.0.
Enabled: true
EnforcedStyle: always
Exclude:
- "spec/fixtures/**/*"
Style/GlobalStdStream:
Enabled: true
Style/GuardClause:
Description: Use a guard clause instead of wrapping the code inside a conditional expression.
Enabled: false
Style/HashAsLastArrayItem:
Enabled: true
Style/HashEachMethods:
Description: Use Hash#each_key and Hash#each_value.
Enabled: true
Style/HashExcept:
Enabled: true
Style/HashLikeCase:
Enabled: true
Style/HashTransformKeys:
Description: Prefer `transform_keys` over `each_with_object` and `map`.
Enabled: true
Style/HashTransformValues:
Description: Prefer `transform_values` over `each_with_object` and `map`.
Enabled: true
Style/HashSyntax:
Description: Checks hash literal syntax.
EnforcedStyle: ruby19
Style/IfWithBooleanLiteralBranches:
Enabled: true
Style/NegatedIfElseCondition:
Enabled: true
Style/NilLambda:
Enabled: true
Style/OptionalBooleanParameter:
Enabled: true
Style/RedundantArgument:
Enabled: true
Style/RedundantAssignment:
Enabled: true
Style/RedundantFetchBlock:
Enabled: true
Style/RedundantFileExtensionInRequire:
Enabled: true
Style/RedundantRegexpCharacterClass:
Description: Checks for unnecessary single-element Regexp character classes.
Enabled: true
Style/RedundantRegexpEscape:
Description: Checks for redundant escapes in Regexps.
Enabled: true
Style/RegexpLiteral:
Description: Use / or %r around regular expressions.
StyleGuide: https://github.com/rubocop-hq/ruby-style-guide#percent-r
Enabled: false
Style/SingleArgumentDig:
Enabled: true
Style/SlicingWithRange:
Description: Checks array slicing is done with endless ranges when suitable.
Enabled: true
Style/SpecialGlobalVars:
Description: Looks for uses of Perl-style global variables.
Exclude:
- "spec/deleted_source_spec.rb"
- "spec/return_codes_spec.rb"
- "lib/simplecov/defaults.rb"
Style/StringConcatenation:
Enabled: true
Style/StringLiterals:
Description: Allow double-quoted strings without interpolation.
EnforcedStyle: double_quotes
Style/SwapValues:
Enabled: true
Style/TrailingCommaInArrayLiteral:
EnforcedStyleForMultiline: no_comma
Style/TrailingCommaInHashLiteral:
EnforcedStyleForMultiline: no_comma
simplecov-0.22.0/.yardopts 0000664 0000000 0000000 00000000012 14351411403 0015427 0 ustar 00root root 0000000 0000000 - **/*.md
simplecov-0.22.0/CHANGELOG.md 0000664 0000000 0000000 00000031622 14351411403 0015405 0 ustar 00root root 0000000 0000000 0.22.0 (2022-12-23)
==========
## Enhancements
* On Ruby 3.2+, you can now use the new Coverage library feature for `eval` - See https://github.com/simplecov-ruby/simplecov/pull/1037. Thanks [@mame](https://github.com/mame)!
## Bugfixes
* Fix for making the test suite pass against the upcoming Ruby 3.2 - See https://github.com/simplecov-ruby/simplecov/pull/1035. Thanks [@mame](https://github.com/mame)
0.21.2 (2021-01-09)
==========
## Bugfixes
* `maximum_coverage_drop` won't fail any more if `.last_run.json` is still in the old format. Thanks [@petertellgren](https://github.com/petertellgren)
* `maximum_coverage_drop` won't fail if an expectation is specified for a previous unrecorded criterion, it will just pass (there's nothing, so nothing to drop)
* fixed bug in `maximum_coverage_drop` calculation that could falsely report it had dropped for minimal differences
0.21.1 (2021-01-04)
==========
## Bugfixes
* `minimum_coverage_by_file` works again as expected (errored out before 😱)
0.21.0 (2021-01-03)
==========
The "Collate++" release making it more viable for big CI setups by limiting memory consumption. Also includes some nice new additions for branch coverage settings.
## Enhancements
* Performance of `SimpleCov.collate` improved - it should both run faster and consume much less memory esp. when run with many files (memory consumption should not increase with number of files any more)
* Can now define the minimum_coverage_by_file, maximum_coverage_drop and refuse_coverage_drop by branch as well as line coverage. Thanks to [@jemmaissroff](https://github.com/jemmaissroff)
* Can set primary coverage to something other than line by setting `primary_coverage :branch` in SimpleCov Configuration. Thanks to [@jemmaissroff](https://github.com/jemmaissroff)
## Misc
* reduce gem size by splitting Changelog into `Changelog.md` and a pre 0.18 `Changelog.old.md`, the latter of which is not included in the gem
* The interface of `ResultMeger.merge_and_store` is changed to support the `collate` performance improvements mentioned above. It's not considered an official API, hence this is not in the breaking section. For people using it to merge results from different machines, it's recommended to migrate to [collate](https://github.com/simplecov-ruby/simplecov#merging-test-runs-under-different-execution-environments).
0.20.0 (2020-11-29)
==========
The "JSON formatter" release. Starting now a JSON formatter is included by default in the release. This is mostly done for Code Climate reasons, you can find more details [in this issue](https://github.com/codeclimate/test-reporter/issues/413).
Shipping with so much by default is sub-optimal, we know. It's the long term plan to also provide `simplecov-core` without the HTML or JSON formatters for those who don't need them/for other formatters to rely on.
## Enhancements
* `simplecov_json_formatter` included by default ([docs](https://github.com/simplecov-ruby/simplecov#json-formatter)), this should enable the Code Climate test reporter to work again once it's updated
* invalidate internal cache after switching `SimpleCov.root`, should help with some bugs
0.19.1 (2020-10-25)
==========
## Bugfixes
* No more warnings triggered by `enable_for_subprocesses`. Thanks to [@mame](https://github.com/mame)
* Avoid trying to patch `Process.fork` when it isn't available. Thanks to [@MSP-Greg](https://github.com/MSP-Greg)
0.19.0 (2020-08-16)
==========
## Breaking Changes
* Dropped support for Ruby 2.4, it reached EOL
## Enhancements
* observe forked processes (enable with SimpleCov.enable_for_subprocesses). See [#881](https://github.com/simplecov-ruby/simplecov/pull/881), thanks to [@robotdana](https://github.com/robotdana)
* SimpleCov distinguishes better that it stopped processing because of a previous error vs. SimpleCov is the originator of said error due to coverage requirements.
## Bugfixes
* Changing the `SimpleCov.root` combined with the root filtering didn't work. Now they do! Thanks to [@deivid-rodriguez](https://github.com/deivid-rodriguez) and see [#894](https://github.com/simplecov-ruby/simplecov/pull/894)
* in parallel test execution it could happen that the last coverage result was written to disk when it didn't complete yet, changed to only write it once it's the final result
* if you run parallel tests only the final process will report violations of the configured test coverage, not all previous processes
* changed the parallel_tests merging mechanisms to do the waiting always in the last process, should reduce race conditions
## Noteworthy
* The repo has moved to https://github.com/simplecov-ruby/simplecov - everything stays the same, redirects should work but you might wanna update anyhow
* The primary development branch is now `main`, not `master` anymore. If you get simplecov directly from github change your reference. For a while `master` will still be occasionally updated but that's no long term solion.
0.18.5 (2020-02-25)
===================
Can you guess? Another bugfix release!
## Bugfixes
* minitest won't crash if SimpleCov isn't loaded - aka don't execute SimpleCov code in the minitest plugin if SimpleCov isn't loaded. Thanks to [@edariedl](https://github.com/edariedl) for the report of the peculiar problem in [#877](https://github.com/simplecov-ruby/simplecov/issues/877).
0.18.4 (2020-02-24)
===================
Another small bugfix release 🙈 Fixes SimpleCov running with rspec-rails, which was broken due to our fixed minitest integration.
## Bugfixes
* SimpleCov will run again correctly when used with rspec-rails. The excellent bug report [#873](https://github.com/simplecov-ruby/simplecov/issues/873) by [@odlp](https://github.com/odlp) perfectly details what went wrong. Thanks to [@adam12](https://github.com/adam12) for the fix [#874](https://github.com/simplecov-ruby/simplecov/pull/874).
0.18.3 (2020-02-23)
===========
Small bugfix release. It's especially recommended to upgrade simplecov-html as well because of bugs in the 0.12.0 release.
## Bugfixes
* Fix a regression related to file encodings as special characters were missing. Furthermore we now respect the magic `# encoding: ...` comment and read files in the right encoding. Thanks ([@Tietew](https://github.com/Tietew)) - see [#866](https://github.com/simplecov-ruby/simplecov/pull/866)
* Use `Minitest.after_run` hook to trigger post-run hooks if `Minitest` is present. See [#756](https://github.com/simplecov-ruby/simplecov/pull/756) and [#855](https://github.com/simplecov-ruby/simplecov/pull/855) thanks ([@adam12](https://github.com/adam12))
0.18.2 (2020-02-12)
===================
Small release just to allow you to use the new simplecov-html.
## Enhancements
* Relax simplecov-html requirement so that you're able to use [0.12.0](https://github.com/simplecov-ruby/simplecov-html/blob/main/CHANGELOG.md#0120-2020-02-12)
0.18.1 (2020-01-31)
===================
Small Bugfix release.
## Bugfixes
* Just putting `# :nocov:` on top of a file or having an uneven number of them in general works again and acts as if ignoring until the end of the file. See [#846](https://github.com/simplecov-ruby/simplecov/issues/846) and thanks [@DannyBen](https://github.com/DannyBen) for the report.
0.18.0 (2020-01-28)
===================
Huge release! Highlights are support for branch coverage (Ruby 2.5+) and dropping support for EOL'ed Ruby versions (< 2.4).
Please also read the other beta patch notes.
You can run with branch coverage by putting `enable_coverage :branch` into your SimpleCov configuration (like the `SimpleCov.start do .. end` block)
## Enhancements
* You can now define the minimum expected coverage by criterion like `minimum_coverage line: 90, branch: 80`
* Memoized some internal data structures that didn't change to reduce SimpleCov overhead
* Both `FileList` and `SourceFile` now have a `coverage` method that returns a hash that points from a coverage criterion to a `CoverageStatistics` object for uniform access to overall coverage statistics for both line and branch coverage
## Bugfixes
* we were losing precision by rounding the covered strength early, that has been removed. **For Formatters** this also means that you may need to round it yourself now.
* Removed an inconsistency in how we treat skipped vs. irrelevant lines (see [#565](https://github.com/simplecov-ruby/simplecov/issues/565)) - SimpleCov's definition of 100% is now "You covered everything that you could" so if coverage is 0/0 that's counted as a 100% no matter if the lines were irrelevant or ignored/skipped
## Noteworthy
* `FileList` stopped inheriting from Array, it includes Enumerable so if you didn't use Array specific methods on it in formatters you should be fine
* We needed to change an internal file format, which we use for merging across processes, to accommodate branch coverage. Sadly CodeClimate chose to use this file to report test coverage. Until a resolution is found the code climate test reporter won't work with SimpleCov for 0.18+, see [this issue on the test reporter](https://github.com/codeclimate/test-reporter/issues/413).
0.18.0.beta3 (2020-01-20)
========================
## Enhancements
* Instead of ignoring old `.resultset.json`s that are inside the merge timeout, adapt and respect them
## Bugfixes
* Remove the constant warning printing if you still have a `.resultset.json` in pre 0.18 layout that is within your merge timeout
0.18.0.beta2 (2020-01-19)
===================
## Enhancements
* only turn on the requested coverage criteria (when activating branch coverage before SimpleCov would also instruct Ruby to take Method coverage)
* Change how branch coverage is displayed, now it's `branch_type: hit_count` which should be more self explanatory. See [#830](https://github.com/simplecov-ruby/simplecov/pull/830) for an example and feel free to give feedback!
* Allow early running exit tasks and avoid the `at_exit` hook through the `SimpleCov.run_exit_tasks!` method. (thanks [@macumber](https://github.com/macumber))
* Allow manual collation of result sets through the `SimpleCov.collate` entrypoint. See the README for more details (thanks [@ticky](https://github.com/ticky))
* Within `case`, even if there is no `else` branch declared show missing coverage for it (aka no branch of it). See [#825](https://github.com/simplecov-ruby/simplecov/pull/825)
* Stop symbolizing all keys when loading cache (should lead to be faster and consume less memory)
* Cache whether we can use/are using branch coverage (should be slightly faster)
## Bugfixes
* Fix a crash that happened when an old version of our internal cache file `.resultset.json` was still present
0.18.0.beta1 (2020-01-05)
===================
This is a huge release highlighted by changing our support for ruby versions to 2.4+ (so things that aren't EOL'ed) and finally adding branch coverage support!
This release is still beta because we'd love for you to test out branch coverage and get your feedback before doing a full release.
On a personal note from [@PragTob](https://github.com/PragTob/) thanks to [ruby together](https://rubytogether.org/) for sponsoring this work on SimpleCov making it possible to deliver this and subsequent releases.
## Breaking
* Dropped support for all EOL'ed rubies meaning we only support 2.4+. Simplecov can no longer be installed on older rubies, but older simplecov releases should still work. (thanks [@deivid-rodriguez](https://github.com/deivid-rodriguez))
* Dropped the `rake simplecov` task that "magically" integreated with rails. It was always undocumented, caused some issues and [had some issues](https://github.com/simplecov-ruby/simplecov/issues/689#issuecomment-561572327). Use the integration as described in the README please :)
## Enhancements
* Branch coverage is here! Please try it out and test it! You can activate it with `enable_coverage :branch`. See the README for more details. This is thanks to a bunch of people most notably [@som4ik](https://github.com/som4ik), [@tycooon](https://github.com/tycooon), [@stepozer](https://github.com/stepozer), [@klyonrad](https://github.com/klyonrad) and your humble maintainers also contributed ;)
* If the minimum coverage is set to be greater than 100, a warning will be shown. See [#737](https://github.com/simplecov-ruby/simplecov/pull/737) (thanks [@belfazt](https://github.com/belfazt))
* Add a configuration option to disable the printing of non-successful exit statuses. See [#747](https://github.com/simplecov-ruby/simplecov/pull/746) (thanks [@JacobEvelyn](https://github.com/JacobEvelyn))
* Calculating 100% coverage is now stricter, so 100% means 100%. See [#680](https://github.com/simplecov-ruby/simplecov/pull/680) thanks [@gleseur](https://github.com/gleseur)
## Bugfixes
* Add new instance of `Minitest` constant. The `MiniTest` constant (with the capital T) will be removed in the next major release of Minitest. See [#757](https://github.com/simplecov-ruby/simplecov/pull/757) (thanks [@adam12](https://github.com/adam12))
Older Changelogs
================
Looking for older changelogs? Please check the [old Changelog](https://github.com/simplecov-ruby/simplecov/blob/main/CHANGELOG.old.md)
simplecov-0.22.0/CHANGELOG.old.md 0000664 0000000 0000000 00000075524 14351411403 0016173 0 ustar 00root root 0000000 0000000 Changelog for older releases, removed to keep the gem size down.
0.17.1 (2019-09-16)
===================
Bugfix release for problems with ParallelTests.
## Bugfixes
* Avoid hanging with parallel_tests. See [#746](https://github.com/simplecov-ruby/simplecov/pull/746) (thanks [@annaswims](https://github.com/annaswims))
0.17.0 (2019-07-02)
===================
Maintenance release with nice convenience features and important bugfixes.
Notably this **will be the last release to support ruby versions that have reached their end of life**. Moving forward official CRuby support will be 2.4+ and JRuby support will be 9.2+. Older versions might still work but no guarantees.
## Enhancements
* Per default filter hidden files and folders. See [#721](https://github.com/simplecov-ruby/simplecov/pull/721) (thanks [Renuo AG](https://www.renuo.ch))
* Print the exit status explicitly when it's not a successful build so it's easier figure out SimpleCov failed the build in the output. See [#688](https://github.com/simplecov-ruby/simplecov/pull/688) (thanks [@daemonsy](https://github.com/daemonsy))
## Bugfixes
* Avoid a premature failure exit code when setting `minimum_coverage` in combination with using [parallel_tests](https://github.com/grosser/parallel_tests). See [#706](https://github.com/simplecov-ruby/simplecov/pull/706) (thanks [@f1sherman](https://github.com/f1sherman))
* Project roots with special characters no longer cause crashes. See [#717](https://github.com/simplecov-ruby/simplecov/pull/717) (thanks [@deivid-rodriguez](https://github.com/deivid-rodriguez))
* Avoid continously overriding test results with manual `ResultMergere.store_results` usage. See [#674](https://github.com/simplecov-ruby/simplecov/pull/674) (thanks [@tomeon](https://github.com/tomeon))
0.16.1 (2018-03-16)
===================
## Bugfixes
* Include the LICENSE in the distributed gem again (accidentally removed in 0.16.0). (thanks @tas50)
0.16.0 (2018-03-15)
===================
## Enhancements
* Relax version constraint on `docile`, per SemVer
* exception that occurred on exit is available as `exit_exception`! See [#639](https://github.com/simplecov-ruby/simplecov/pull/639) (thanks @thomas07vt)
* Performance: processing results now runs from 2.5x to 3.75x faster. See [#662](https://github.com/simplecov-ruby/simplecov/pull/662) (thanks @BMorearty & @eregon)
* Decrease gem size by only shipping lib and docs
## Bugfixes
* (breaking) Stop handling string filters as regular expressions, use the dedicated regex filter if you need that behaviour. See [#616](https://github.com/simplecov-ruby/simplecov/pull/616) (thanks @yujinakayama)
* Avoid overwriting the last coverage results on unsuccessful test runs. See [#625](https://github.com/simplecov-ruby/simplecov/pull/625) (thanks @thomas07vt)
* Don't crash on invalid UTF-8 byte sequences. (thanks @BMorearty)
0.15.1 (2017-09-11) ([changes](https://github.com/simplecov-ruby/simplecov/compare/v0.15.0...v0.15.1))
=======
## Bugfixes
* Filter directories outside SimpleCov.root that have it as a prefix. See [#617](https://github.com/simplecov-ruby/simplecov/pull/617) (thanks @jenseng)
* Fix standard rails profile rails filter (didn't work). See [#618](https://github.com/simplecov-ruby/simplecov/pull/618) (thanks @jenseng again!)
0.15.0 (2017-08-14) ([changes](https://github.com/simplecov-ruby/simplecov/compare/v0.14.1...v0.15.0))
=======
## Enhancements
* Ability to use regex filters for removing files from the output. See [#589](https://github.com/simplecov-ruby/simplecov/pull/589) (thanks @jsteel)
## Bugfixes
* Fix merging race condition when running tests in parallel and merging them. See [#570](https://github.com/simplecov-ruby/simplecov/pull/570) (thanks @jenseng)
* Fix relevant lines for unloaded files - comments, skipped code etc. are correctly classified as irrelevant. See [#605](https://github.com/simplecov-ruby/simplecov/pull/605) (thanks @odlp)
* Allow using simplecov with frozen-string-literals enabled. See [#590](https://github.com/simplecov-ruby/simplecov/pull/590) (thanks @pat)
* Make sure Array Filter can use all other filter types. See [#589](https://github.com/simplecov-ruby/simplecov/pull/589) (thanks @jsteel)
* Make sure file names use `Simplecov.root` as base avoiding using full absolute project paths. See [#589](https://github.com/simplecov-ruby/simplecov/pull/589) (thanks @jsteel)
0.14.1 2017-03-18 ([changes](https://github.com/simplecov-ruby/simplecov/compare/v0.14.0...v0.14.1))
========
## Bugfixes
* Files that were skipped as a whole/had no relevant coverage could lead to Float errors. See [#564](https://github.com/simplecov-ruby/simplecov/pull/564) (thanks to @stevehanson for the report in [#563](https://github.com/simplecov-ruby/simplecov/issues/563))
0.14.0 2017-03-15 ([changes](https://github.com/simplecov-ruby/simplecov/compare/v0.13.0...v0.14.0))
==========
## Enhancements
* Officially support JRuby 9.1+ going forward (should also work with previous releases). See [#547](https://github.com/simplecov-ruby/simplecov/pull/547) (ping @PragTob when encountering issues)
* Add Channel group to Rails profile, when `ActionCable` is loaded. See [#492](https://github.com/simplecov-ruby/simplecov/pull/492) (thanks @BenMorganIO)
* Stop `extend`ing instances of `Array` and `Hash` during merging results avoiding problems frozen results while manually merging results. See [#558](https://github.com/simplecov-ruby/simplecov/pull/558) (thanks @aroben)
## Bugfixes
* Fix parallel_tests when a thread ends up running no tests. See [#533](https://github.com/simplecov-ruby/simplecov/pull/533) (thanks @cshaffer)
* Skip the `:nocov:` comments along with the code that they skip. See [#551](https://github.com/simplecov-ruby/simplecov/pull/551) (thanks @ebiven)
* Fix crash when Home environment variable is unset. See [#482](https://github.com/simplecov-ruby/simplecov/pull/482) (thanks @waldyr)
* Make track_files work again when explicitly setting it to nil. See [#463](https://github.com/simplecov-ruby/simplecov/pull/463) (thanks @craiglittle)
* Do not overwrite .last_run.json file when refuse_coverage_drop option is enabled and the coverage has dropped (lead to you being able to just rerun tests and everything was _fine_). See [#553](https://github.com/simplecov-ruby/simplecov/pull/553) (thanks @Miloshes)
0.13.0 2017-01-25 ([changes](https://github.com/simplecov-ruby/simplecov/compare/v0.12.0...v0.13.0))
==========
## Enhancements
* Faster run times when a very large number of files is loaded into SimpleCov. See [#520](https://github.com/simplecov-ruby/simplecov/pull/520) (thanks @alyssais)
* Only read in source code files that are actually used (faster when files are ignored etc.). See [#540](https://github.com/simplecov-ruby/simplecov/pull/540) (thanks @yui-knk)
## Bugfixes
* Fix merging of resultsets if a file is missing on one side. See [#513](https://github.com/simplecov-ruby/simplecov/pull/513) (thanks @hanazuki)
* Fix Ruby 2.4 deprecation warnings by using Integer instead of Fixnum. See [#523](https://github.com/simplecov-ruby/simplecov/pull/523) (thanks @nobu)
* Force Ruby 2 to json 2. See [dc7417d50](https://github.com/simplecov-ruby/simplecov/commit/dc7417d5049b1809cea214314c15dd93a5dd964f) (thanks @amatsuda)
* Various other gem dependency fixes for different gems on different ruby versions. (thanks @amatsuda)
0.12.0 2016-07-02 ([changes](https://github.com/simplecov-ruby/simplecov/compare/v0.11.2...v0.12.0))
=================
## Enhancements
* Add support for JSON versions 2.x
## Bugfixes
* Fix coverage rate of the parallel_tests. See [#441](https://github.com/simplecov-ruby/simplecov/pull/441) (thanks @sinsoku)
* Fix a regression on old rubies that failed to work with the recently introduced frozen VERSION string. See [#461](https://github.com/simplecov-ruby/simplecov/pull/461) (thanks @leafle)
0.11.2 2016-02-03 ([changes](https://github.com/simplecov-ruby/simplecov/compare/v0.11.1...v0.11.2))
=================
## Enhancements
* Do not globally pollute Array and Hash with `merge_resultset` utility methods. See [#449](https://github.com/simplecov-ruby/simplecov/pull/449) (thanks @amatsuda)
* Do not `mkdir_p` the `coverage_path` on every access of the method (See [#453](https://github.com/simplecov-ruby/simplecov/pull/453) (thanks @paddor)
* Fixes a Ruby warning related to the `track_files` configuration. See [#447](https://github.com/simplecov-ruby/simplecov/pull/447) (thanks @craiglittle)
* Add a group for background jobs to default Rails profile. See [#442](https://github.com/simplecov-ruby/simplecov/pull/442) (thanks @stve)
## Bugfixes
* Fix root_filter evaluates SimpleCov.root before initialization. See [#437](https://github.com/simplecov-ruby/simplecov/pull/437) (thanks @tmtm)
0.11.1 2015-12-01 ([changes](https://github.com/simplecov-ruby/simplecov/compare/v0.11.0...v0.11.1))
=================
## Enhancements
## Bugfixes
* Fixed regression in `MultiFormatter.[]` with multiple arguments. See [#431](https://github.com/simplecov-ruby/simplecov/pull/431) (thanks @dillondrobena)
0.11.0 2015-11-29 ([changes](https://github.com/simplecov-ruby/simplecov/compare/v0.10.0...v0.11.0))
=================
## Enhancements
* Added `SimpleCov.minimum_coverage_by_file` for per-file coverage thresholds. See [#392](https://github.com/simplecov-ruby/simplecov/pull/392) (thanks @ptashman)
* Added `track_files` configuration option to specify a glob to always include in coverage results, whether or not those files are required. By default, this is enabled in the Rails profile for common Rails directories. See [#422](https://github.com/simplecov-ruby/simplecov/pull/422) (thanks @hugopeixoto)
* Speed up `root_filter` by an order of magnitude. See [#396](https://github.com/simplecov-ruby/simplecov/pull/396) (thanks @raszi)
## Bugfixes
* Fix warning about global variable `$ERROR_INFO`. See [#400](https://github.com/simplecov-ruby/simplecov/pull/400) (thanks @amatsuda)
* Actually recurse upward looking for `.simplecov`, as claimed by the documentation, rather than only the working directory. See [#423](https://github.com/simplecov-ruby/simplecov/pull/423) (thanks @alexdowad)
0.10.0 2015-04-18 ([changes](https://github.com/simplecov-ruby/simplecov/compare/v0.9.2...v0.10.0))
=================
## Enhancements
* Add writeup about using with Spring to README. See [#341](https://github.com/simplecov-ruby/simplecov/issues/341) (thanks @swrobel and @onebree)
* Add support to pass in an Array when creating filter groups (original PR #104)
* Filter `/vendor/bundle` by default. See [#331](https://github.com/simplecov-ruby/simplecov/pull/331) (thanks @andyw8)
* Add some helpful singleton methods to the version string.
* Allow array to be passed in a filter. See [375](https://github.com/simplecov-ruby/simplecov/pull/375) (thanks @JanStevens)
* Enforce consistent code formatting with RuboCop.
## Bugfixes
* Fix order dependencies in unit tests. See [#376](https://github.com/simplecov-ruby/simplecov/pull/376) (thanks @hugopeixoto)
* Only run the at_exit behaviors if the current PID matches the PID that called SimpleCov.start. See [#377](https://github.com/simplecov-ruby/simplecov/pull/377) (thanks @coderanger)
0.9.2, 2015-02-18 ([changes](https://github.com/simplecov-ruby/simplecov/compare/v0.9.1...v0.9.2))
=================
This is a minor bugfix release for simplecov-html, released as `0.9.0`. Due to the tight version constraint in the gemspec
a new release of simplecov had to be shipped to allow using simplecov-html `~> 0.9.0`.
* The browser back / forward button should now work again. See [#36](https://github.com/simplecov-ruby/simplecov-html/pull/36) and
[#35](https://github.com/simplecov-ruby/simplecov-html/pull/35). Thanks @whatasunnyday and @justinsteele for submitting PRs to fix this.
* Fix "warning: possibly useless use of a variable in void context" See [#31](https://github.com/simplecov-ruby/simplecov-html/pull/31). Thanks @cbandy
* Always use binary file format. See [#32](https://github.com/simplecov-ruby/simplecov-html/pull/32). Thanks @andy128k
* Avoid slow file output with JRuby/Windows. See [#16](https://github.com/simplecov-ruby/simplecov-html/pull/16). Thanks @pschambacher
Other than the release includes a bunch of mostly documentation improvements:
* Update Rails path for Rails 4+. See [#336](https://github.com/simplecov-ruby/simplecov/pull/336). Thanks @yazinsai
* Encourage use of .simplecov to avoid lost files. See [#338](https://github.com/simplecov-ruby/simplecov/pull/338). thanks @dankohn
* Specified in the gemspec that simplecov needs ruby 1.8.7. See [#343](https://github.com/simplecov-ruby/simplecov/pull/343). thanks @iainbeeston
* Fix mispointed link in CHANGELOG.md. See [#353](https://github.com/simplecov-ruby/simplecov/pull/353). Thanks @dleve123
* Improve command name docs. See [#356](https://github.com/simplecov-ruby/simplecov/pull/356). Thanks @gtd
0.9.1, 2014-09-21 ([changes](https://github.com/simplecov-ruby/simplecov/compare/v0.9.0...v0.9.1))
=================
## Bugfixes
* In 0.9.0, we introduced a regression that made SimpleCov no-op mode fail on Ruby 1.8, while
dropping 1.8 support altogether is announced only for v1.0. This has been fixed.
See [#333](https://github.com/simplecov-ruby/simplecov/issues/333) (thanks (@sferik)
0.9.0, 2014-07-17 ([changes](https://github.com/simplecov-ruby/simplecov/compare/v0.8.2...v0.9.0))
=================
**A warm welcome and big thank you to the new contributors [@xaviershay](https://github.com/xaviershay), [@sferik](https://github.com/sferik) and especially [@bf4](https://github.com/bf4) for tackling a whole lot of issues and pull requests for this release!**
## Enhancements
* New interface to specify multiple formatters.
See [#317](https://github.com/simplecov-ruby/simplecov/pull/317) (thanks @sferik)
* Document in the README how to exclude code from coverage reports,
and that the feature shouldn't be abused for skipping untested
private code.
See [#304](https://github.com/simplecov-ruby/simplecov/issues/304)
* Clarify Ruby version support.
See [#279](https://github.com/simplecov-ruby/simplecov/pull/279) (thanks @deivid-rodriguez)
## Bugfixes
* Ensure calculations return Floats, not Fixnum or Rational. Fixes segfaults with mathn.
See [#245](https://github.com/simplecov-ruby/simplecov/pull/245) (thanks to @bf4)
* Using `Kernel.exit` instead of exit to avoid uncaught throw :IRB_EXIT when
exiting irb sessions.
See [#287](https://github.com/simplecov-ruby/simplecov/pull/287) (thanks @wless1)
See [#285](https://github.com/simplecov-ruby/simplecov/issues/285)
* Does not look for .simplecov in ~/ when $HOME is not set.
See [#311](https://github.com/simplecov-ruby/simplecov/pull/311) (thanks @lasseebert)
* Exit with code only if it's Numeric > 0.
See [#302](https://github.com/simplecov-ruby/simplecov/pull/302) (thanks @hajder)
* Make default filter case insensitive.
See [#280](https://github.com/simplecov-ruby/simplecov/pull/280) (thanks @ryanatball)
* Improve regexp that matches functional tests.
See [#276](https://github.com/simplecov-ruby/simplecov/pull/276) (thanks @sferik)
* Fix TravisCI [#272](https://github.com/simplecov-ruby/simplecov/pull/272) [#278](https://github.com/simplecov-ruby/simplecov/pull/278), [#302](https://github.com/simplecov-ruby/simplecov/pull/302)
* Fix global config load.
See [#311](https://github.com/simplecov-ruby/simplecov/pull/311) (thanks @lasseebert)
v0.8.2, 2013-11-20 ([changes](https://github.com/simplecov-ruby/simplecov/compare/v0.8.1...v0.8.2))
==================
## Bugfixes
* Replaced the locking behaviour [via lockfile gem](https://github.com/simplecov-ruby/simplecov/pull/185) with
plain Ruby explicit file locking when merging results. This should make simplecov merging to behave well
on Windows again.
See [#258](https://github.com/simplecov-ruby/simplecov/issues/258) and
[#223](https://github.com/simplecov-ruby/simplecov/pull/223) (thanks to @tomykaira)
v0.8.1, 2013-11-10 ([changes](https://github.com/simplecov-ruby/simplecov/compare/v0.8.0...v0.8.1))
==================
## Bugfixes
* Fixed a regression introduced in 0.8.0 - the Forwardable STDLIB module is now required explicitly.
See [#256](https://github.com/simplecov-ruby/simplecov/pull/256) (thanks to @kylev)
v0.8.0, 2013-11-10 ([changes](https://github.com/simplecov-ruby/simplecov/compare/v0.7.1...v0.8.0))
==================
**Note: Yanked the same day because of the regression that 0.8.1 fixes, see above**
## TL;DR
It's been way too long since the last official release 0.7.1, but this was partly due to it proving itself
quite stable in most circumstances. This release brings various further stability improvements to result set merging
(especially when working with parallel_tests), the configuration, source file encodings, and command name guessing.
The 0.8 line is the last one to cooperate with Ruby < 1.9. Starting with 0.9, SimpleCov will assume to be running in
Ruby 1.9+, and will not try to detect or bail silently on older Ruby versions. An appropriate deprecation warning
has been added.
## Features
* Configuration blocks now have access to variables and methods outside of the block's scope.
See [#238](https://github.com/simplecov-ruby/simplecov/pull/238) (thanks to @ms-tg)
* You can now have a global `~/.simplecov` configuration file.
See [#195](https://github.com/simplecov-ruby/simplecov/pull/195) (thanks to @spagalloco)
* simplecov-html now uses the MIT-licensed colorbox plugin. Some adjustments when viewing source files,
including retaining the currently open file on refresh have been added.
See [simplecov-html #15](https://github.com/simplecov-ruby/simplecov-html/pull/15) (thanks to @chetan)
* Adds support for Rails 4 command guessing, removes default group `vendor/plugins`.
See [#181](https://github.com/simplecov-ruby/simplecov/pull/181) and
[#203](https://github.com/simplecov-ruby/simplecov/pull/203) (thanks to @semanticart and @phallstrom)
* You can now load simplecov without the default settings by doing `require 'simplecov/no_defaults'`
or setting `ENV['SIMPLECOV_NO_DEFAULTS']`. Check `simplecov/defaults` to see what preconfigurations are getting
dropped by using this. See [#209](https://github.com/simplecov-ruby/simplecov/pull/209) (thanks to @ileitch)
* The result set merging now uses the `lockfile` gem to avoid race conditions.
See [#185](https://github.com/simplecov-ruby/simplecov/pull/185) (thanks to @jshraibman-mdsol).
* Automatically detect the usage of parallel_tests and adjust the command name with the test env number accordingly,
See [#64](https://github.com/simplecov-ruby/simplecov/issues/64) and
[#185](https://github.com/simplecov-ruby/simplecov/pull/185) (thanks to @jshraibman-mdsol).
## Enhancements
* Rename adapters to "profiles" given that they are bundles of settings. The old adapter methods are
deprecated, but remain available for now.
See [#207](https://github.com/simplecov-ruby/simplecov/pull/207) (thanks to @mikerobe)
* Tweaks to the automatic test suite naming. In particular, `rspec/features` should now
be correctly attributed to RSpec, not Cucumber.
See [#212](https://github.com/simplecov-ruby/simplecov/pull/212) (thanks to @ersatzryan and @betelgeuse)
* MiniTest should now be identified correctly by the command name guesser.
See [#244](https://github.com/simplecov-ruby/simplecov/pull/244) (thanks to @envygeeks)
* Makes SimpleCov resilient to inclusion of mathn library.
See [#175](https://github.com/simplecov-ruby/simplecov/pull/175) and
[#140](https://github.com/simplecov-ruby/simplecov/issues/140) (thanks to @scotje)
* Allow coverage_dir to be an absolute path.
* See [#190](https://github.com/simplecov-ruby/simplecov/pull/190) (thanks to @jshraibman-mdsol)
* The internal cucumber test suite now uses Capybara 2.
See [#206](https://github.com/simplecov-ruby/simplecov/pull/206) (thanks to @infertux)
* Work-arounds for the Coverage library shipped in JRuby 1.6 to behave in line with MRI.
See [#174](https://github.com/simplecov-ruby/simplecov/pull/174) (thanks to @grddev)
* Fix warning: instance variable @exit_status not initialized.
See [#242](https://github.com/simplecov-ruby/simplecov/pull/242) and
[#213](https://github.com/simplecov-ruby/simplecov/pull/213) (thanks to @sferik and @infertux)
## Bugfixes
* Correct result calculations for people using :nocov: tags.
See [#215](https://github.com/simplecov-ruby/simplecov/pull/215) (thanks to @aokolish)
* Average hits per line for groups of files is now computed correctly.
See [#192](http://github.com/simplecov-ruby/simplecov/pull/192) and
[#179](http://github.com/simplecov-ruby/simplecov/issues/179) (thanks to @graysonwright)
* Compatibility with BINARY internal encoding.
See [#194](https://github.com/simplecov-ruby/simplecov/pull/194) and
[#127](https://github.com/simplecov-ruby/simplecov/issues/127) (thanks to @justfalter)
* Special characters in `SimpleCov.root` are now correctly escaped before being used as a RegExp.
See [#204](https://github.com/simplecov-ruby/simplecov/issues/204) and
[#237](https://github.com/simplecov-ruby/simplecov/pull/237) (thanks to @rli9)
v0.7.1, 2012-10-12 ([changes](https://github.com/simplecov-ruby/simplecov/compare/v0.7.0...v0.7.1))
==================
* [BUGFIX] The gem packages of 0.7.0 (both simplecov and simplecov-html) pushed to Rubygems had some file
permission issues, leading to problems when installing SimpleCov in a root/system Rubygems install and then
trying to use it as a normal user (see https://github.com/simplecov-ruby/simplecov/issues/171, thanks @envygeeks
for bringing it up). The gem build process has been changed to always enforce proper permissions before packaging
to avoid this issue in the future.
v0.7.0, 2012-10-10 ([changes](https://github.com/simplecov-ruby/simplecov/compare/v0.6.4...v0.7.0))
==================
* [FEATURE] The new `maximum_coverage_drop` and `minimum_coverage` now allow you to fail your build when the
coverage dropped by more than what you allowed or is below a minimum value required. Also, `refuse_coverage_drop` disallows
any coverage drops between test runs.
See https://github.com/simplecov-ruby/simplecov/pull/151, https://github.com/simplecov-ruby/simplecov/issues/11,
https://github.com/simplecov-ruby/simplecov/issues/90, and https://github.com/simplecov-ruby/simplecov/issues/96 (thanks to @infertux)
* [FEATURE] SimpleCov now ships with a built-in MultiFormatter which allows the easy usage of multiple result formatters at
the same time without the need to write custom wrapper code.
See https://github.com/simplecov-ruby/simplecov/pull/158 (thanks to @nikitug)
* [BUGFIX] The usage of digits, hyphens and underscores in group names could lead to broken tab navigation
in the default simplecov-html reports. See https://github.com/simplecov-ruby/simplecov-html/pull/14 (thanks to @ebelgarts)
* [REFACTORING] A few more ruby warnings removed. See https://github.com/simplecov-ruby/simplecov/issues/106 and
https://github.com/simplecov-ruby/simplecov/pull/139. (thanks to @lukejahnke)
* A [Pledgie button](https://github.com/simplecov-ruby/simplecov/commit/63cfa99f8658fa5cc66a38c83b3195fdf71b9e93) for those that
feel generous :)
* The usual bunch of README fixes and documentation tweaks. Thanks to everyone who contributed those!
v0.6.4, 2012-05-10 ([changes](https://github.com/simplecov-ruby/simplecov/compare/v0.6.3...v0.6.4))
==================
* [BUGFIX]Â Encoding issues with ISO-8859-encoded source files fixed.
See https://github.com/simplecov-ruby/simplecov/pull/117. (thanks to @Deradon)
* [BUGFIX] Ensure ZeroDivisionErrors won't occur when calculating the coverage result, which previously
could happen in certain cases. See https://github.com/simplecov-ruby/simplecov/pull/128. (thanks to @japgolly)
* [REFACTORING] Changed a couple instance variable lookups so SimpleCov does not cause a lot of warnings when
running ruby at a higher warning level. See https://github.com/simplecov-ruby/simplecov/issues/106 and
https://github.com/simplecov-ruby/simplecov/pull/119. (thanks to @mvz and @gioele)
v0.6.3, 2012-05-10 ([changes](https://github.com/simplecov-ruby/simplecov/compare/v0.6.2...v0.6.3))
==================
* [BUGFIX] Modified the API-changes for newer multi_json versions introduced with #122 and v0.6.2 so
they are backwards-compatible with older multi_json gems in order to avoid simplecov polluting
the multi_json minimum version requirement for entire applications.
See https://github.com/simplecov-ruby/simplecov/issues/132
* Added appraisal gem to the test setup in order to run the test suite against both 1.0 and 1.3
multi_json gems and ensure the above actually works :)
v0.6.2, 2012-04-20 ([changes](https://github.com/simplecov-ruby/simplecov/compare/v0.6.1...v0.6.2))
==================
* [Updated to latest version of MultiJSON and its new API (thanks to @sferik and @ronen).
See https://github.com/simplecov-ruby/simplecov/pull/122
v0.6.1, 2012-02-24 ([changes](https://github.com/simplecov-ruby/simplecov/compare/v0.6.0...v0.6.1))
==================
* [BUGFIX] Don't force-load Railtie on Rails < 3. Fixes regression introduced with
#83. See https://github.com/simplecov-ruby/simplecov/issues/113
v0.6.0, 2012-02-22 ([changes](https://github.com/simplecov-ruby/simplecov/compare/v0.5.4...v0.6.0))
==================
* [FEATURE] Auto-magic `rake simplecov` task for rails
(see https://github.com/simplecov-ruby/simplecov/pull/83, thanks @sunaku)
* [BUGFIX] Treat source files as UTF-8 to avoid encoding errors
(see https://github.com/simplecov-ruby/simplecov/pull/103, thanks @joeyates)
* [BUGFIX] Store the invoking terminal command right after loading so they are safe from
other libraries tampering with ARGV. Among other makes automatic Rails test suite splitting
(Unit/Functional/Integration) work with recent rake versions again
(see https://github.com/simplecov-ruby/simplecov/issues/110)
* [FEATURE] If guessing command name from the terminal command fails, try guessing from defined constants
(see https://github.com/simplecov-ruby/simplecov/commit/37afca54ef503c33d888e910f950b3b943cb9a6c)
* Some refactorings and cleanups as usual. Please refer to the github compare view for a full
list of changes: https://github.com/simplecov-ruby/simplecov/compare/v0.5.4...v0.6.0
v0.5.4, 2011-10-12 ([changes](https://github.com/simplecov-ruby/simplecov/compare/v0.5.3...v0.5.4))
==================
* Do not give exit code 0 when there are exceptions prior to tests
(see https://github.com/simplecov-ruby/simplecov/issues/41, thanks @nbogie)
* The API for building custom filter classes is now more obvious, using #matches? instead of #passes? too.
(see https://github.com/simplecov-ruby/simplecov/issues/85, thanks @robinroestenburg)
* Mailers are now part of the Rails adapter as their own group (see
https://github.com/simplecov-ruby/simplecov/issues/79, thanks @geetarista)
* Removed fix for JRuby 1.6 RC1 float bug because it's been fixed
(see https://github.com/simplecov-ruby/simplecov/issues/86)
* Readme formatted in Markdown :)
v0.5.3, 2011-09-13 ([changes](https://github.com/simplecov-ruby/simplecov/compare/v0.5.2...v0.5.3))
==================
* Fix for encoding issues that came from the nocov processing mechanism
(see https://github.com/simplecov-ruby/simplecov/issues/71)
* :nocov: lines are now actually being reflected in the HTML report and are marked in yellow.
* The Favicon in the HTML report is now determined by the overall coverage and will have the color
that the coverage percentage gets as a css class to immediately indicate coverage status on first sight.
* Introduced SimpleCov::SourceFile::Line#status method that returns the coverage status
as a string for this line - made SimpleCov::HTML use that.
* Refactored nocov processing and made it configurable using SimpleCov.ncov_token (or it's
alias SimpleCov.skip_token)
v0.5.2, 2011-09-12 ([changes](https://github.com/simplecov-ruby/simplecov/compare/v0.5.1...v0.5.2))
==================
* Another fix for a bug in JSON processing introduced with MultiJSON in 0.5.1
(see https://github.com/simplecov-ruby/simplecov/pull/75, thanks @sferik)
v0.5.1, 2011-09-12 ([changes](https://github.com/simplecov-ruby/simplecov/compare/v0.5.0...v0.5.1))
==================
**Note: Yanked 2011-09-12 because the MultiJSON-patch had a crucial bug**
* Fix for invalid gemspec dependency string (see https://github.com/simplecov-ruby/simplecov/pull/70,
http://blog.rubygems.org/2011/08/31/shaving-the-yaml-yacc.html, thanks @jspradlin)
* Added JSON in the form of the multi_json gem as dependency for those cases when built-in JSON
is unavailable (see https://github.com/simplecov-ruby/simplecov/issues/72
and https://github.com/simplecov-ruby/simplecov/pull/74, thanks @sferik)
v0.5.0, 2011-09-09 ([changes](https://github.com/simplecov-ruby/simplecov/compare/v0.4.2...v0.5.4))
==================
**Note: Yanked 2011-09-09 because of trouble with the gemspec.**
* JSON is now used instead of YAML for resultset caching (used for merging). Should resolve
a lot of problems people used to have because of YAML parser errors.
* There's a new adapter 'test_frameworks'. Use it outside of Rails to remove `test/`,
`spec/`, `features/` and `autotest/` dirs from your coverage reports, either directly
with `SimpleCov.start 'test_frameworks'` or with `SimpleCov.load_adapter 'test_frameworks'`
* SimpleCov configuration can now be placed centrally in a text file `.simplecov`, which will
be automatically read on `require 'simplecov'`. This makes using custom configuration like
groups and filters across your test suites much easier as you only have to specify your config
once. Just put the whole `SimpleCov.start (...)` code into `APP_ROOT/.simplecov`
* Lines can now be skipped by using the :nocov: flag in comments that wrap the code that should be
skipped, like in this example (thanks @phillipkoebbe)
#:nocov:
def skipped
@foo * 2
end
#:nocov:
* Moved file set coverage analytics from simplecov-html to SimpleCov::FileList, a new subclass
of Array that is always returned for SourceFile lists (i.e. in groups) and can now be used
in all formatters without the need to roll your own.
* The exceptions you used to get after removing some code and re-running your tests because SimpleCov
couldn't find the cached source lines should be resolved (thanks @goneflyin)
* Coverage strength metric: Average hits/line per source file and result group (thanks @trans)
* Finally, SimpleCov has an extensive Cucumber test suite
* Full compatibility with Ruby 1.9.3.preview1
### HTML Formatter:
* The display of source files has been improved a lot. Weird scrolling trouble, out-of-scope line hit counts
and such should be a thing of the past. Also, it is prettier now.
* Source files are now syntax highlighted
* File paths no longer have that annoying './' in front of them
simplecov-0.22.0/CODE_OF_CONDUCT.md 0000664 0000000 0000000 00000006421 14351411403 0016372 0 ustar 00root root 0000000 0000000 # SimpleCov Code of Conduct
## Our Pledge
In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, sex characteristics, gender identity and expression,
level of experience, education, socio-economic status, nationality, personal
appearance, race, religion, or sexual identity and orientation.
## Our Standards
Examples of behavior that contributes to creating a positive environment
include:
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
## Our Responsibilities
Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.
Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.
## Scope
This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at simplecov.team@gmail.com. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.
Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
[homepage]: https://www.contributor-covenant.org
For answers to common questions about this code of conduct, see
https://www.contributor-covenant.org/faq
simplecov-0.22.0/CONTRIBUTING.md 0000664 0000000 0000000 00000004427 14351411403 0016030 0 ustar 00root root 0000000 0000000 ## Reporting Issues
You can report issues at https://github.com/simplecov-ruby/simplecov/issues
Before you go ahead please search existing issues for your problem, chances are someone else already reported it.
To make sure that we can help you quickly please include and check the following information:
* Include how you run your tests and which testing framework or frameworks you are running.
- please ensure you are requiring and starting SimpleCov before requiring any application code.
- If running via rake, please ensure you are requiring SimpleCov at the top of your Rakefile
For example, if running via RSpec, this would be at the top of your spec_helper.
- Have you tried using a [`.simplecov` file](https://github.com/simplecov-ruby/simplecov#using-simplecov-for-centralized-config)?
* Include the SimpleCov version you are running in your report.
* If you are not running the latest version (please check), and you cannot update it,
please specify in your report why you can't update to the latest version.
* Include your `ruby -e "puts RUBY_DESCRIPTION"`.
* Please also specify the gem versions of Rails (if applicable).
* Include any other coverage gems you may be using and their versions.
Include as much sample code as you can to help us reproduce the issue. (Inline, repo link, or gist, are fine. A failing test would help the most.)
This is extremely important for narrowing down the cause of your problem.
Thanks!
## Making Contributions
To fetch & test the library for development, do:
$ git clone https://github.com/simplecov-ruby/simplecov.git
$ cd simplecov
$ bundle
$ bundle exec rake
To run the cucumber tests make sure:
* chrome/chromium is installed
* you can successfully install the sqlite gem (so you have the appropriate dev headers)
If you want to contribute, please:
* Fork the project.
* Make your feature addition or bug fix.
* Add tests for it. This is important so I don't break it in a future version unintentionally.
* **Bonus Points** go out to anyone who also updates `CHANGELOG.md` :)
* Send me a pull request on GitHub.
## Running Individual Tests
This project uses RSpec and Cucumber. Individual tests can be run like this:
```bash
bundle exec rspec path/to/test.rb
bundle exec cucumber path/to/test.feature
```
simplecov-0.22.0/Gemfile 0000664 0000000 0000000 00000001601 14351411403 0015061 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
source "https://rubygems.org"
# Uncomment this to use local copy of simplecov-html in development when checked out
# gem "simplecov-html", path: File.dirname(__FILE__) + "/../simplecov-html"
# Uncomment this to use development version of html formatter from github
# gem "simplecov-html", github: "simplecov-ruby/simplecov-html"
gem "matrix"
group :development do
gem "apparition", github: "twalpole/apparition" # LOCKED: When this is released, use a released version https://github.com/twalpole/apparition/pull/79
gem "aruba", "~> 1.0"
gem "capybara", "~> 3.31"
gem "cucumber", "~> 4.0"
gem "minitest"
gem "rake", "~> 13.0"
gem "rspec", "~> 3.2"
gem "pry"
gem "rubocop"
gem "test-unit"
# Explicitly add webrick because it has been removed from stdlib in Ruby 3.0
gem "webrick"
end
group :benchmark do
gem "benchmark-ips"
end
gemspec
simplecov-0.22.0/Gemfile.lock 0000664 0000000 0000000 00000011605 14351411403 0016015 0 ustar 00root root 0000000 0000000 GIT
remote: https://github.com/twalpole/apparition.git
revision: ca86be4d54af835d531dbcd2b86e7b2c77f85f34
specs:
apparition (0.6.0)
capybara (~> 3.13, < 4)
websocket-driver (>= 0.6.5)
PATH
remote: .
specs:
simplecov (0.22.0)
docile (~> 1.1)
simplecov-html (~> 0.11)
simplecov_json_formatter (~> 0.1)
GEM
remote: https://rubygems.org/
specs:
activesupport (6.1.4.4)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
zeitwerk (~> 2.3)
addressable (2.8.0)
public_suffix (>= 2.0.2, < 5.0)
aruba (1.1.2)
bundler (>= 1.17, < 3.0)
childprocess (>= 2.0, < 5.0)
contracts (>= 0.16.0, < 0.18.0)
cucumber (>= 2.4, < 7.0)
rspec-expectations (~> 3.4)
thor (~> 1.0)
ast (2.4.2)
benchmark-ips (2.9.2)
builder (3.2.4)
capybara (3.35.3)
addressable
mini_mime (>= 0.1.3)
nokogiri (~> 1.8)
rack (>= 1.6.0)
rack-test (>= 0.6.3)
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
childprocess (4.1.0)
coderay (1.1.3)
concurrent-ruby (1.1.9)
contracts (0.16.1)
cucumber (4.1.0)
builder (~> 3.2, >= 3.2.3)
cucumber-core (~> 7.1, >= 7.1.0)
cucumber-create-meta (~> 1.0.0, >= 1.0.0)
cucumber-cucumber-expressions (~> 10.1, >= 10.1.0)
cucumber-gherkin (~> 14.0, >= 14.0.1)
cucumber-html-formatter (~> 7.0, >= 7.0.0)
cucumber-messages (~> 12.2, >= 12.2.0)
cucumber-wire (~> 3.1, >= 3.1.0)
diff-lcs (~> 1.3, >= 1.3, < 1.4)
multi_test (~> 0.1, >= 0.1.2)
sys-uname (~> 1.0, >= 1.0.2)
cucumber-core (7.1.0)
cucumber-gherkin (~> 14.0, >= 14.0.1)
cucumber-messages (~> 12.2, >= 12.2.0)
cucumber-tag-expressions (~> 2.0, >= 2.0.4)
cucumber-create-meta (1.0.0)
cucumber-messages (~> 12.2, >= 12.2.0)
sys-uname (~> 1.2, >= 1.2.1)
cucumber-cucumber-expressions (10.3.0)
cucumber-gherkin (14.2.0)
cucumber-messages (~> 12.4, >= 12.4.0)
cucumber-html-formatter (7.2.0)
cucumber-messages (~> 12.4, >= 12.4.0)
cucumber-messages (12.4.0)
protobuf-cucumber (~> 3.10, >= 3.10.8)
cucumber-tag-expressions (2.0.4)
cucumber-wire (3.1.0)
cucumber-core (~> 7.1, >= 7.1.0)
cucumber-cucumber-expressions (~> 10.1, >= 10.1.0)
cucumber-messages (~> 12.2, >= 12.2.0)
diff-lcs (1.3)
docile (1.4.0)
ffi (1.15.5)
ffi (1.15.5-java)
i18n (1.8.11)
concurrent-ruby (~> 1.0)
matrix (0.4.2)
method_source (1.0.0)
middleware (0.1.0)
mini_mime (1.1.2)
mini_portile2 (2.6.1)
minitest (5.15.0)
multi_test (0.1.2)
nokogiri (1.12.5)
mini_portile2 (~> 2.6.1)
racc (~> 1.4)
nokogiri (1.12.5-java)
racc (~> 1.4)
parallel (1.21.0)
parser (3.1.0.0)
ast (~> 2.4.1)
power_assert (2.0.1)
protobuf-cucumber (3.10.8)
activesupport (>= 3.2)
middleware
thor
thread_safe
pry (0.14.1)
coderay (~> 1.1)
method_source (~> 1.0)
pry (0.14.1-java)
coderay (~> 1.1)
method_source (~> 1.0)
spoon (~> 0.0)
public_suffix (4.0.6)
racc (1.6.0)
racc (1.6.0-java)
rack (2.2.3.1)
rack-test (1.1.0)
rack (>= 1.0, < 3)
rainbow (3.1.1)
rake (13.0.6)
regexp_parser (2.2.0)
rexml (3.2.5)
rspec (3.10.0)
rspec-core (~> 3.10.0)
rspec-expectations (~> 3.10.0)
rspec-mocks (~> 3.10.0)
rspec-core (3.10.1)
rspec-support (~> 3.10.0)
rspec-expectations (3.10.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-mocks (3.10.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-support (3.10.3)
rubocop (1.24.1)
parallel (~> 1.10)
parser (>= 3.0.0.0)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml
rubocop-ast (>= 1.15.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 3.0)
rubocop-ast (1.15.1)
parser (>= 3.0.1.1)
ruby-progressbar (1.11.0)
simplecov-html (0.12.3)
simplecov_json_formatter (0.1.3)
spoon (0.0.6)
ffi
sys-uname (1.2.2)
ffi (~> 1.1)
test-unit (3.5.3)
power_assert
thor (1.2.1)
thread_safe (0.3.6)
thread_safe (0.3.6-java)
tzinfo (2.0.4)
concurrent-ruby (~> 1.0)
unicode-display_width (2.1.0)
webrick (1.7.0)
websocket-driver (0.7.5)
websocket-extensions (>= 0.1.0)
websocket-driver (0.7.5-java)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
xpath (3.2.0)
nokogiri (~> 1.8)
zeitwerk (2.5.3)
PLATFORMS
java
ruby
universal-java-1.8
DEPENDENCIES
apparition!
aruba (~> 1.0)
benchmark-ips
capybara (~> 3.31)
cucumber (~> 4.0)
matrix
minitest
pry
rake (~> 13.0)
rspec (~> 3.2)
rubocop
simplecov!
test-unit
webrick
BUNDLED WITH
2.3.4
simplecov-0.22.0/ISSUE_TEMPLATE.md 0000664 0000000 0000000 00000002604 14351411403 0016277 0 ustar 00root root 0000000 0000000 Howdy! Thanks for reporting an issue <3
Before you go ahead please search existing issues for your problem, chances are someone else already reported it.
To make sure that we can help you quickly please include and check the following information:
* Include how you run your tests and which testing framework or frameworks you are running.
- please ensure you are requiring and starting SimpleCov before requiring any application code.
- If running via rake, please ensure you are requiring SimpleCov at the top of your Rakefile
For example, if running via RSpec, this would be at the top of your spec_helper.
- Have you tried using a [`.simplecov` file](https://github.com/simplecov-ruby/simplecov#using-simplecov-for-centralized-config)?
* Include the SimpleCov version you are running in your report.
* If you are not running the latest version (please check), and you cannot update it,
please specify in your report why you can't update to the latest version.
* Include your `ruby -e "puts RUBY_DESCRIPTION"`.
* Please also specify the gem versions of Rails (if applicable).
* Include any other coverage gems you may be using and their versions.
Include as much sample code as you can to help us reproduce the issue. (Inline, repo link, or gist, are fine. A failing test would help the most.)
This is extremely important for narrowing down the cause of your problem.
Thanks!
simplecov-0.22.0/LICENSE 0000664 0000000 0000000 00000002053 14351411403 0014575 0 ustar 00root root 0000000 0000000 Copyright (c) 2010-2017 Christoph Olszowka
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
simplecov-0.22.0/README.md 0000664 0000000 0000000 00000104742 14351411403 0015057 0 ustar 00root root 0000000 0000000 SimpleCov [](https://badge.fury.io/rb/simplecov) [][Continuous Integration] [](https://codeclimate.com/github/simplecov-ruby/simplecov/maintainability) [](http://inch-ci.org/github/simplecov-ruby/simplecov)
=========
**Code coverage for Ruby**
* [Source Code]
* [API documentation]
* [Changelog]
* [Rubygem]
* [Continuous Integration]
[Coverage]: https://ruby-doc.org/stdlib/libdoc/coverage/rdoc/Coverage.html "API doc for Ruby's Coverage library"
[Source Code]: https://github.com/simplecov-ruby/simplecov "Source Code @ GitHub"
[API documentation]: http://rubydoc.info/gems/simplecov/frames "RDoc API Documentation at Rubydoc.info"
[Configuration]: http://rubydoc.info/gems/simplecov/SimpleCov/Configuration "Configuration options API documentation"
[Changelog]: https://github.com/simplecov-ruby/simplecov/blob/main/CHANGELOG.md "Project Changelog"
[Rubygem]: http://rubygems.org/gems/simplecov "SimpleCov @ rubygems.org"
[Continuous Integration]: https://github.com/simplecov-ruby/simplecov/actions?query=workflow%3Astable "SimpleCov is built around the clock by github.com"
[Dependencies]: https://gemnasium.com/simplecov-ruby/simplecov "SimpleCov dependencies on Gemnasium"
[simplecov-html]: https://github.com/simplecov-ruby/simplecov-html "SimpleCov HTML Formatter Source Code @ GitHub"
SimpleCov is a code coverage analysis tool for Ruby. It uses [Ruby's built-in Coverage][Coverage] library to gather code
coverage data, but makes processing its results much easier by providing a clean API to filter, group, merge, format,
and display those results, giving you a complete code coverage suite that can be set up with just a couple lines of
code.
SimpleCov/Coverage track covered ruby code, gathering coverage for common templating solutions like erb, slim and haml is not supported.
In most cases, you'll want overall coverage results for your projects, including all types of tests, Cucumber features,
etc. SimpleCov automatically takes care of this by caching and merging results when generating reports, so your
report actually includes coverage across your test suites and thereby gives you a better picture of blank spots.
The official formatter of SimpleCov is packaged as a separate gem called [simplecov-html], but will be installed and
configured automatically when you launch SimpleCov. If you're curious, you can find it [on GitHub, too][simplecov-html].
## Contact
*Code and Bug Reports*
* [Issue Tracker](https://github.com/simplecov-ruby/simplecov/issues)
* See [CONTRIBUTING](https://github.com/simplecov-ruby/simplecov/blob/main/CONTRIBUTING.md) for how to contribute along
with some common problems to check out before creating an issue.
*Questions, Problems, Suggestions, etc.*
* [Mailing List](https://groups.google.com/forum/#!forum/simplecov) "Open mailing list for discussion and announcements
on Google Groups"
Getting started
---------------
1. Add SimpleCov to your `Gemfile` and `bundle install`:
```ruby
gem 'simplecov', require: false, group: :test
```
2. Load and launch SimpleCov **at the very top** of your `test/test_helper.rb`
(*or `spec_helper.rb`, `rails_helper`, cucumber `env.rb`, or whatever your preferred test
framework uses*):
```ruby
require 'simplecov'
SimpleCov.start
# Previous content of test helper now starts here
```
**Note:** If SimpleCov starts after your application code is already loaded
(via `require`), it won't be able to track your files and their coverage!
The `SimpleCov.start` **must** be issued **before any of your application
code is required!**
This is especially true if you use anything that keeps your tests application loaded like spring, check out the **[spring section](#want-to-use-spring-with-simplecov)**.
SimpleCov must be running in the process that you want the code coverage
analysis to happen on. When testing a server process (e.g. a JSON API
endpoint) via a separate test process (e.g. when using Selenium) where you
want to see all code executed by the `rails server`, and not just code
executed in your actual test files, you need to require SimpleCov in the
server process. For rails for instance, you'll want to add something like this
to the top of `bin/rails`, but below the "shebang" line (`#! /usr/bin/env
ruby`) and after config/boot is required:
```ruby
if ENV['RAILS_ENV'] == 'test'
require 'simplecov'
SimpleCov.start 'rails'
puts "required simplecov"
end
```
3. Run your full test suite to see the percent coverage that your application has.
4. After running your tests, open `coverage/index.html` in the browser of your choice. For example, in a Mac Terminal,
run the following command from your application's root directory:
```
open coverage/index.html
```
in a debian/ubuntu Terminal,
```
xdg-open coverage/index.html
```
**Note:** [This guide](https://dwheeler.com/essays/open-files-urls.html) can help if you're unsure which command your particular
operating system requires.
5. Add the following to your `.gitignore` file to ensure that coverage results
are not tracked by Git (optional):
```
echo coverage >> .gitignore
```
If you're making a Rails application, SimpleCov comes with built-in configurations (see below for information on
profiles) that will get you started with groups for your Controllers, Models and Helpers. To use it, the
first two lines of your test_helper should be like this:
```ruby
require 'simplecov'
SimpleCov.start 'rails'
```
## Example output
**Coverage results report, fully browsable locally with sorting and much more:**

**Source file coverage details view:**

## Use it with any framework!
Similarly to the usage with Test::Unit described above, the only thing you have to do is to add the SimpleCov
config to the very top of your Cucumber/RSpec/whatever setup file.
Add the setup code to the **top** of `features/support/env.rb` (for Cucumber) or `spec/spec_helper.rb` (for RSpec).
Other test frameworks should work accordingly, whatever their setup file may be:
```ruby
require 'simplecov'
SimpleCov.start 'rails'
```
You could even track what kind of code your UI testers are touching if you want to go overboard with things. SimpleCov
does not care what kind of framework it is running in; it just looks at what code is being executed and generates a
report about it.
### Notes on specific frameworks and test utilities
For some frameworks and testing tools there are quirks and problems you might want to know about if you want
to use SimpleCov with them. Here's an overview of the known ones:
Framework | Notes | Issue |
parallel_tests
|
As of 0.8.0, SimpleCov should correctly recognize parallel_tests and
supplement your test suite names with their corresponding test env
numbers. SimpleCov locks the resultset cache while merging, ensuring no
race conditions occur when results are merged.
|
#64 &
#185
|
knapsack_pro
|
To make SimpleCov work with Knapsack Pro Queue Mode to split tests in parallel on CI jobs you need to provide CI node index number to the SimpleCov.command_name in KnapsackPro::Hooks::Queue.before_queue hook.
|
Tip
|
RubyMine
|
The RubyMine IDE has
built-in support for SimpleCov's coverage reports, though you might need
to explicitly set the output root using `SimpleCov.root('foo/bar/baz')`
|
#95
|
Spork
|
Because of how Spork works internally (using preforking), there used to
be trouble when using SimpleCov with it, but that has apparently been
resolved with a specific configuration strategy. See this
comment.
|
#42
|
Spring
|
See section below.
|
#381
|
Test/Unit
|
Test Unit 2 used to mess with ARGV, leading to a failure to detect the
test process name in SimpleCov. test-unit releases 2.4.3+
(Dec 11th, 2011) should have this problem resolved.
|
#45 &
test-unit/test-unit#12
|
## Configuring SimpleCov
[Configuration] settings can be applied in three formats, which are completely equivalent:
* The most common way is to configure it directly in your start block:
```ruby
SimpleCov.start do
some_config_option 'foo'
end
```
* You can also set all configuration options directly:
```ruby
SimpleCov.some_config_option 'foo'
```
* If you do not want to start coverage immediately after launch or want to add additional configuration later on in a
concise way, use:
```ruby
SimpleCov.configure do
some_config_option 'foo'
end
```
Please check out the [Configuration] API documentation to find out what you can customize.
## Using .simplecov for centralized config
If you use SimpleCov to merge multiple test suite results (e.g. Test/Unit and Cucumber) into a single report, you'd
normally have to set up all your config options twice, once in `test_helper.rb` and once in `env.rb`.
To avoid this, you can place a file called `.simplecov` in your project root. You can then just leave the
`require 'simplecov'` in each test setup helper (**at the top**) and move the `SimpleCov.start` code with all your
custom config options into `.simplecov`:
```ruby
# test/test_helper.rb
require 'simplecov'
# features/support/env.rb
require 'simplecov'
# .simplecov
SimpleCov.start 'rails' do
# any custom configs like groups and filters can be here at a central place
end
```
Using `.simplecov` rather than separately requiring SimpleCov multiple times is recommended if you are merging multiple
test frameworks like Cucumber and RSpec that rely on each other, as invoking SimpleCov multiple times can cause coverage
information to be lost.
## Branch coverage (ruby "~> 2.5")
Add branch coverage measurement statistics to your results. Supported in CRuby versions 2.5+.
```ruby
SimpleCov.start do
enable_coverage :branch
end
```
Branch coverage is a feature introduced in Ruby 2.5 concerning itself with whether a
particular branch of a condition had been executed. Line coverage on the other hand
is only interested in whether a line of code has been executed.
This comes in handy for instance for one line conditionals:
```ruby
number.odd? ? "odd" : "even"
```
In line coverage this line would always be marked as executed but you'd never know if both
conditions were met. Guard clauses have a similar story:
```ruby
return if number.odd?
# more code
```
If all the code in that method was covered you'd never know if the guard clause was ever
triggered! With line coverage as just evaluating the condition marks it as covered.
In the HTML report the lines of code will be annotated like `branch_type: hit_count`:
* `then: 2` - the then branch (of an `if`) was executed twice
* `else: 0` - the else branch (of an `if` or `case`) was never executed
Not that even if you don't declare an `else` branch it will still show up in the coverage
reports meaning that the condition of the `if` was not hit or that no `when` of `case`
was hit during the test runs.
**Is branch coverage strictly better?** No. Branch coverage really only concerns itself with
conditionals - meaning coverage of sequential code is of no interest to it. A file without
conditional logic will have no branch coverage data and SimpleCov will report 0 of 0
branches covered as 100% (as everything that can be covered was covered).
Hence, we recommend looking at both metrics together. Branch coverage might also be a good
overall metric to look at - while you might be missing only 10% of your lines that might
account for 50% of your branches for instance.
## Primary Coverage
By default, the primary coverage type is `line`. To set the primary coverage to something else, use the following:
```ruby
# or in configure SimpleCov.primary_coverage :branch
SimpleCov.start do
enable_coverage :branch
primary_coverage :branch
end
```
Primary coverage determines what will come in first all output, and the type of coverage to check if you don't specify the type of coverage when customizing exit behavior (`SimpleCov.minimum_coverage 90`).
Note that coverage must first be enabled for non-default coverage types.
## Coverage for eval
You can measure coverage for code that is evaluated by `Kernel#eval`. Supported in CRuby versions 3.2+.
```ruby
SimpleCov.start do
enable_coverage_for_eval
end
```
This is typically useful for ERB. Set `ERB#filename=` to make it possible for SimpleCov to trace the original .erb source file.
## Filters
Filters can be used to remove selected files from your coverage data. By default, a filter is applied that removes all
files OUTSIDE of your project's root directory - otherwise you'd end up with billions of coverage reports for source
files in the gems you are using.
You can define your own to remove things like configuration files, tests or whatever you don't need in your coverage
report.
### Defining custom filters
You can currently define a filter using either a String or Regexp (that will then be Regexp-matched against each source
file's path), a block or by passing in your own Filter class.
#### String filter
```ruby
SimpleCov.start do
add_filter "/test/"
end
```
This simple string filter will remove all files that match "/test/" in their path.
#### Regex filter
```ruby
SimpleCov.start do
add_filter %r{^/test/}
end
```
This simple regex filter will remove all files that start with /test/ in their path.
#### Block filter
```ruby
SimpleCov.start do
add_filter do |source_file|
source_file.lines.count < 5
end
end
```
Block filters receive a SimpleCov::SourceFile instance and expect your block to return either true (if the file is to be
removed from the result) or false (if the result should be kept). Please check out the RDoc for SimpleCov::SourceFile to
learn about the methods available to you. In the above example, the filter will remove all files that have less than 5
lines of code.
#### Custom filter class
```ruby
class LineFilter < SimpleCov::Filter
def matches?(source_file)
source_file.lines.count < filter_argument
end
end
SimpleCov.add_filter LineFilter.new(5)
```
Defining your own filters is pretty easy: Just inherit from SimpleCov::Filter and define a method
'matches?(source_file)'. When running the filter, a true return value from this method will result in the removal of the
given source_file. The filter_argument method is being set in the SimpleCov::Filter initialize method and thus is set to
5 in this example.
#### Array filter
```ruby
SimpleCov.start do
proc = Proc.new { |source_file| false }
add_filter ["string", /regex/, proc, LineFilter.new(5)]
end
```
You can pass in an array containing any of the other filter types.
#### Ignoring/skipping code
You can exclude code from the coverage report by wrapping it in `# :nocov:`.
```ruby
# :nocov:
def skip_this_method
never_reached
end
# :nocov:
```
The name of the token can be changed to your liking. [Learn more about the nocov feature.]( https://github.com/simplecov-ruby/simplecov/blob/main/features/config_nocov_token.feature)
**Note:** You shouldn't have to use the nocov token to skip private methods that are being included in your coverage. If
you appropriately test the public interface of your classes and objects you should automatically get full coverage of
your private methods.
## Default root filter and coverage for things outside of it
By default, SimpleCov filters everything outside of the `SimpleCov.root` directory. However, sometimes you may want
to include coverage reports for things you include as a gem, for example a Rails Engine.
Here's an example by [@lsaffie](https://github.com/lsaffie) from [#221](https://github.com/simplecov-ruby/simplecov/issues/221)
that shows how you can achieve just that:
```ruby
SimpleCov.start :rails do
filters.clear # This will remove the :root_filter and :bundler_filter that come via simplecov's defaults
add_filter do |src|
!(src.filename =~ /^#{SimpleCov.root}/) unless src.filename =~ /my_engine/
end
end
```
## Groups
You can separate your source files into groups. For example, in a Rails app, you'll want to have separate listings for
Models, Controllers, Helpers, and Libs. Group definition works similarly to Filters (and also accepts custom
filter classes), but source files end up in a group when the filter passes (returns true), as opposed to filtering
results, which exclude files from results when the filter results in a true value.
Add your groups with:
```ruby
SimpleCov.start do
add_group "Models", "app/models"
add_group "Controllers", "app/controllers"
add_group "Long files" do |src_file|
src_file.lines.count > 100
end
add_group "Multiple Files", ["app/models", "app/controllers"] # You can also pass in an array
add_group "Short files", LineFilter.new(5) # Using the LineFilter class defined in Filters section above
end
```
## Merging results
You normally want to have your coverage analyzed across ALL of your test suites, right?
Simplecov automatically caches coverage results in your
(coverage_path)/.resultset.json, and will merge or override those with
subsequent runs, depending on whether simplecov considers those subsequent runs
as different test suites or as the same test suite as the cached results. To
make this distinction, simplecov has the concept of "test suite names".
### Test suite names
SimpleCov tries to guess the name of the currently running test suite based upon the shell command the tests
are running on. This should work fine for Unit Tests, RSpec, and Cucumber. If it fails, it will use the shell
command that invoked the test suite as a command name.
If you have some non-standard setup and still want nicely labeled test suites, you have to give Simplecov a
cue as to what the name of the currently running test suite is. You can do so by specifying
`SimpleCov.command_name` in one test file that is part of your specific suite.
To customize the suite names on a Rails app (yeah, sorry for being Rails-biased, but everyone knows what
the structure of those projects is. You can apply this accordingly to the RSpecs in your
Outlook-WebDAV-Calendar-Sync gem), you could do something like this:
```ruby
# test/unit/some_test.rb
SimpleCov.command_name 'test:units'
# test/functionals/some_controller_test.rb
SimpleCov.command_name "test:functionals"
# test/integration/some_integration_test.rb
SimpleCov.command_name "test:integration"
# features/support/env.rb
SimpleCov.command_name "features"
```
Note that this only has to be invoked ONCE PER TEST SUITE, so even if you have 200 unit test files,
specifying it in `some_test.rb` is enough.
Last but not least **if multiple suites resolve to the same `command_name`** be aware that the coverage results **will
clobber each other instead of being merged**. SimpleCov is smart enough to detect unique names for the most common
setups, but if you have more than one test suite that doesn't follow a common pattern then you will want to manually
ensure that each suite gets a unique `command_name`.
If you are running tests in parallel each process has the potential to clobber results from the other test processes.
If you are relying on the default `command_name` then SimpleCov will attempt to detect and avoid parallel test suite
`command_name` collisions based on the presence of `ENV['PARALLEL_TEST_GROUPS']` and `ENV['TEST_ENV_NUMBER']`. If your
parallel test runner does not set one or both of these then *you must* set a `command_name` and ensure that it is unique
per process (eg. `command_name "Unit Tests PID #{$$}"`).
If you are using parallel_tests, you must incorporate `TEST_ENV_NUMBER` into the command name yourself, in
order for SimpleCov to merge the results correctly. For example:
```ruby
# spec/spec_helper.rb
SimpleCov.command_name "features" + (ENV['TEST_ENV_NUMBER'] || '')
```
[simplecov-html] prints the used test suites in the footer of the generated coverage report.
### Merging test runs under the same execution environment
Test results are automatically merged with previous runs in the same execution
environment when generating the result, so when coverage is set up properly for
Cucumber and your unit / functional / integration tests, all of those test
suites will be taken into account when building the coverage report.
#### Timeout for merge
Of course, your cached coverage data is likely to become invalid at some point. Thus, when automatically merging
subsequent test runs, result sets that are older than `SimpleCov.merge_timeout` will not be used any more. By default,
the timeout is 600 seconds (10 minutes), and you can raise (or lower) it by specifying `SimpleCov.merge_timeout 3600`
(1 hour), or, inside a configure/start block, with just `merge_timeout 3600`.
You can deactivate this automatic merging altogether with `SimpleCov.use_merging false`.
### Merging test runs under different execution environments
If your tests are done in parallel across multiple build machines, you can fetch them all and merge them into a single
result set using the `SimpleCov.collate` method. This can be added to a Rakefile or script file, having downloaded a set of
`.resultset.json` files from each parallel test run.
```ruby
# lib/tasks/coverage_report.rake
namespace :coverage do
desc "Collates all result sets generated by the different test runners"
task :report do
require 'simplecov'
SimpleCov.collate Dir["simplecov-resultset-*/.resultset.json"]
end
end
```
`SimpleCov.collate` also takes an optional simplecov profile and an optional
block for configuration, just the same as `SimpleCov.start` or
`SimpleCov.configure`. This means you can configure a separate formatter for
the collated output. For instance, you can make the formatter in
`SimpleCov.start` the `SimpleCov::Formatter::SimpleFormatter`, and only use more
complex formatters in the final `SimpleCov.collate` run.
```ruby
# spec/spec_helper.rb
require 'simplecov'
SimpleCov.start 'rails' do
# Disambiguates individual test runs
command_name "Job #{ENV["TEST_ENV_NUMBER"]}" if ENV["TEST_ENV_NUMBER"]
if ENV['CI']
formatter SimpleCov::Formatter::SimpleFormatter
else
formatter SimpleCov::Formatter::MultiFormatter.new([
SimpleCov::Formatter::SimpleFormatter,
SimpleCov::Formatter::HTMLFormatter
])
end
track_files "**/*.rb"
end
```
```ruby
# lib/tasks/coverage_report.rake
namespace :coverage do
task :report do
require 'simplecov'
SimpleCov.collate Dir["simplecov-resultset-*/.resultset.json"], 'rails' do
formatter SimpleCov::Formatter::MultiFormatter.new([
SimpleCov::Formatter::SimpleFormatter,
SimpleCov::Formatter::HTMLFormatter
])
end
end
end
```
## Running simplecov against subprocesses
`SimpleCov.enable_for_subprocesses` will allow SimpleCov to observe subprocesses starting using `Process.fork`.
This modifies ruby's core Process.fork method so that SimpleCov can see into it, appending `" (subprocess #{pid})"`
to the `SimpleCov.command_name`, with results that can be merged together using SimpleCov's merging feature.
To configure this, use `.at_fork`.
```ruby
SimpleCov.enable_for_subprocesses true
SimpleCov.at_fork do |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 output and checking coverage totals
SimpleCov.print_error_status = false
SimpleCov.formatter SimpleCov::Formatter::SimpleFormatter
SimpleCov.minimum_coverage 0
# start
SimpleCov.start
end
```
NOTE: SimpleCov must have already been started before `Process.fork` was called.
### Running simplecov against spawned subprocesses
Perhaps you're testing a ruby script with `PTY.spawn` or `Open3.popen`, or `Process.spawn` or etc.
SimpleCov can cover this too.
Add a .simplecov_spawn.rb file to your project root
```ruby
# .simplecov_spawn.rb
require 'simplecov' # this will also pick up whatever config is in .simplecov
# so ensure it just contains configuration, and doesn't call SimpleCov.start.
SimpleCov.command_name 'spawn' # As this is not for a test runner directly, script doesn't have a pre-defined base command_name
SimpleCov.at_fork.call(Process.pid) # Use the per-process setup described previously
SimpleCov.start # only now can we start.
```
Then, instead of calling your script directly, like:
```ruby
PTY.spawn('my_script.rb') do # ...
```
Use bin/ruby to require the new .simplecov_spawn file, then your script
```ruby
PTY.spawn('ruby -r./.simplecov_spawn my_script.rb') do # ...
```
## Running coverage only on demand
The Ruby STDLIB Coverage library that SimpleCov builds upon is *very* fast (on a ~10 min Rails test suite, the speed
drop was only a couple seconds for me), and therefore it's SimpleCov's policy to just generate coverage every time you
run your tests because it doesn't do your test speed any harm and you're always equipped with the latest and greatest
coverage results.
Because of this, SimpleCov has no explicit built-in mechanism to run coverage only on demand.
However, you can still accomplish this very easily by introducing an ENV variable conditional into your SimpleCov setup
block, like this:
```ruby
SimpleCov.start if ENV["COVERAGE"]
```
Then, SimpleCov will only run if you execute your tests like this:
```shell
COVERAGE=true rake test
```
## Errors and exit statuses
To aid in debugging issues, if an error is raised, SimpleCov will print a message to `STDERR`
with the exit status of the error, like:
```
SimpleCov failed with exit 1
```
This `STDERR` message can be disabled with:
```
SimpleCov.print_error_status = false
```
## Profiles
By default, SimpleCov's only config assumption is that you only want coverage reports for files inside your project
root. To save yourself from repetitive configuration, you can use predefined blocks of configuration, called 'profiles',
or define your own.
You can then pass the name of the profile to be used as the first argument to SimpleCov.start. For example, simplecov
comes bundled with a 'rails' profile. It looks somewhat like this:
```ruby
SimpleCov.profiles.define 'rails' do
add_filter '/test/'
add_filter '/config/'
add_group 'Controllers', 'app/controllers'
add_group 'Models', 'app/models'
add_group 'Helpers', 'app/helpers'
add_group 'Libraries', 'lib'
end
```
As you can see, it's just a SimpleCov.configure block. In your test_helper.rb, launch SimpleCov with:
```ruby
SimpleCov.start 'rails'
```
or
```ruby
SimpleCov.start 'rails' do
# additional config here
end
```
### Custom profiles
You can load additional profiles with the SimpleCov.load_profile('xyz') method. This allows you to build upon an
existing profile and customize it so you can reuse it in unit tests and Cucumber features. For example:
```ruby
# lib/simplecov_custom_profile.rb
require 'simplecov'
SimpleCov.profiles.define 'myprofile' do
load_profile 'rails'
add_filter 'vendor' # Don't include vendored stuff
end
# features/support/env.rb
require 'simplecov_custom_profile'
SimpleCov.start 'myprofile'
# test/test_helper.rb
require 'simplecov_custom_profile'
SimpleCov.start 'myprofile'
```
## Customizing exit behaviour
You can define what SimpleCov should do when your test suite finishes by customizing the at_exit hook:
```ruby
SimpleCov.at_exit do
SimpleCov.result.format!
end
```
Above is the default behaviour. Do whatever you like instead!
### Minimum coverage
You can define the minimum coverage percentage expected. SimpleCov will return non-zero if unmet.
```ruby
SimpleCov.minimum_coverage 90
# same as above (the default is to check line coverage)
SimpleCov.minimum_coverage line: 90
# check for a minimum line coverage of 90% and minimum 80% branch coverage
SimpleCov.minimum_coverage line: 90, branch: 80
```
### Minimum coverage by file
You can define the minimum coverage by file percentage expected. SimpleCov will return non-zero if unmet. This is useful
to help ensure coverage is relatively consistent, rather than being skewed by particularly good or bad areas of the code.
```ruby
SimpleCov.minimum_coverage_by_file 80
# same as above (the default is to check line coverage by file)
SimpleCov.minimum_coverage_by_file line: 80
# check for a minimum line coverage by file of 90% and minimum 80% branch coverage
SimpleCov.minimum_coverage_by_file line: 90, branch: 80
```
### Maximum coverage drop
You can define the maximum coverage drop percentage at once. SimpleCov will return non-zero if exceeded.
```ruby
SimpleCov.maximum_coverage_drop 5
# same as above (the default is to check line drop)
SimpleCov.maximum_coverage_drop line: 5
# check for a maximum line drop of 5% and maximum 10% branch drop
SimpleCov.maximum_coverage_drop line: 5, branch: 10
```
### Refuse dropping coverage
You can also entirely refuse dropping coverage between test runs:
```ruby
SimpleCov.refuse_coverage_drop
# same as above (the default is to only refuse line drop)
SimpleCov.refuse_coverage_drop :line
# refuse drop for line and branch
SimpleCov.refuse_coverage_drop :line, :branch
```
## Using your own formatter
You can use your own formatter with:
```ruby
SimpleCov.formatter = SimpleCov::Formatter::HTMLFormatter
```
Calling `SimpleCov.result.format!` will be invoked with `SimpleCov::Formatter::YourFormatter.new.format(result)`,
and `result` is an instance of `SimpleCov::Result`. Do whatever your wish with that!
## Using multiple formatters
As of SimpleCov 0.9, you can specify multiple result formats. Formatters besides the default HTML formatter require separate gems, however.
```ruby
require "simplecov-html"
SimpleCov.formatters = SimpleCov::Formatter::MultiFormatter.new([
SimpleCov::Formatter::HTMLFormatter,
SimpleCov::Formatter::CSVFormatter,
])
```
## JSON formatter
SimpleCov is packaged with a separate gem called [simplecov_json_formatter](https://github.com/codeclimate-community/simplecov_json_formatter) that provides you with a JSON formatter, this formatter could be useful for different use cases, such as for CI consumption or for reporting to external services.
In order to use it you will need to manually load the installed gem like so:
```ruby
require "simplecov_json_formatter"
SimpleCov.formatter = SimpleCov::Formatter::JSONFormatter
```
> _Note:_ In case you plan to report your coverage results to CodeClimate services, know that SimpleCov will automatically use the
> JSON formatter along with the HTML formatter when the `CC_TEST_REPORTER_ID` variable is present in the environment.
## Available formatters, editor integrations and hosted services
* [Open Source formatter and integration plugins for SimpleCov](doc/alternate-formatters.md)
* [Editor Integration](doc/editor-integration.md)
* [Hosted (commercial) services](doc/commercial-services.md)
## Ruby version compatibility
SimpleCov is built in [Continuous Integration] on Ruby 2.7+ as well as JRuby 9.3+.
Note for JRuby => You need to pass JRUBY_OPTS="--debug" or create .jrubyrc and add debug.fullTrace=true
## Want to find dead code in production?
Try [Coverband](https://github.com/danmayer/coverband).
## Want to use Spring with SimpleCov?
If you're using [Spring](https://github.com/rails/spring) to speed up test suite runs and want to run SimpleCov along
with them, you'll find that it often misreports coverage with the default config due to some sort of eager loading
issue. Don't despair!
One solution is to [explicitly call eager
load](https://github.com/simplecov-ruby/simplecov/issues/381#issuecomment-347651728)
in your `test_helper.rb` / `spec_helper.rb` after calling `SimpleCov.start`.
```ruby
require 'simplecov'
SimpleCov.start 'rails'
Rails.application.eager_load!
```
Alternatively, you could disable Spring while running SimpleCov:
```
DISABLE_SPRING=1 rake test
```
Or you could remove `gem 'spring'` from your `Gemfile`.
## Troubleshooting
The **most common problem is that simplecov isn't required and started before everything else**. In order to track
coverage for your whole application **simplecov needs to be the first one** so that it (and the underlying coverage
library) can subsequently track loaded files and their usage.
If you are missing coverage for some code a simple trick is to put a puts statement in there and right after
`SimpleCov.start` so you can see if the file really was loaded after simplecov was started.
```ruby
# my_code.rb
class MyCode
puts "MyCode is being loaded!"
def my_method
# ...
end
end
# spec_helper.rb/rails_helper.rb/test_helper.rb/.simplecov whatever
SimpleCov.start
puts "SimpleCov started successfully!"
```
Now when you run your test suite and you see:
```
SimpleCov started successfully!
MyCode is being loaded!
```
then it's good otherwise you likely have a problem :)
## Code of Conduct
Everyone participating in this project's development, issue trackers and other channels is expected to follow our
[Code of Conduct](./CODE_OF_CONDUCT.md)
## Contributing
See the [contributing guide](https://github.com/simplecov-ruby/simplecov/blob/main/CONTRIBUTING.md).
## Kudos
Thanks to Aaron Patterson for the original idea for this!
## Copyright
Copyright (c) 2010-2017 Christoph Olszowka. See MIT-LICENSE for details.
simplecov-0.22.0/Rakefile 0000664 0000000 0000000 00000001543 14351411403 0015240 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
require "rubygems"
require "bundler/setup"
Bundler::GemHelper.install_tasks
# See https://github.com/simplecov-ruby/simplecov/issues/171
desc "Set permissions on all files so they are compatible with both user-local and system-wide installs"
task :fix_permissions do
system 'bash -c "find lib/ -type f -exec chmod 644 {} \; && find . -type d -exec chmod 755 {} \;"'
end
# Enforce proper permissions on each build
Rake::Task[:build].prerequisites.unshift :fix_permissions
require "rspec/core/rake_task"
RSpec::Core::RakeTask.new(:spec)
begin
require "rubocop/rake_task"
RuboCop::RakeTask.new
rescue LoadError
task :rubocop do
warn "Rubocop is disabled"
end
end
require "cucumber/rake/task"
Cucumber::Rake::Task.new do |t|
t.cucumber_opts = %w[--retry 3 --no-strict-flaky]
end
task default: %i[rubocop spec cucumber]
simplecov-0.22.0/benchmarks/ 0000775 0000000 0000000 00000000000 14351411403 0015705 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/benchmarks/result.rb 0000664 0000000 0000000 00000001165 14351411403 0017553 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
require "benchmark/ips"
require "coverage"
Coverage.start
# such meta, many wow
require_relative "../lib/simplecov"
require_relative "../test_projects/faked_project/lib/faked_project"
result = Coverage.result
class MyFormatter
def format(result)
result.files.map do |file|
"#{file.filename}: #{file.covered_percent} #{file.lines_of_code}"
end
result.covered_percent.to_s
end
end
SimpleCov.command_name "Benchmarking"
SimpleCov.formatter = MyFormatter
Benchmark.ips do |bm|
bm.report "generating a simplecov result" do
SimpleCov::Result.new(result).format!
end
end
simplecov-0.22.0/cucumber.yml 0000664 0000000 0000000 00000001150 14351411403 0016115 0 ustar 00root root 0000000 0000000 <%
rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : ""
rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}"
std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} --strict --tags 'not @wip'"
interp_opts = if defined?(RUBY_ENGINE)
" --tags 'not @exclude-#{RUBY_ENGINE}'"
else
''
end
%>
default: <%= std_opts %><%= interp_opts %> features
wip: --tags @wip:30 --wip features<%= interp_opts %>
rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags 'not @wip' <%= interp_opts %>
simplecov-0.22.0/doc/ 0000775 0000000 0000000 00000000000 14351411403 0014335 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/doc/alternate-formatters.md 0000664 0000000 0000000 00000005222 14351411403 0021023 0 ustar 00root root 0000000 0000000 ## Alternate coverage report formatters
The community around simplecov provides a whole bunch of alternate formatters beyond the official
[simplecov-html](https://github.com/simplecov-ruby/simplecov-html) gem.
If you have built or found one that is missing here, please send a Pull Request for this document!
#### [simplecov-badge](https://github.com/matthew342/simplecov-badge)
*by Matt Hale*
A formatter that generates a coverage badge for use in your project's readme using ImageMagick.
#### [simplecov-small-badge](https://github.com/marcgrimme/simplecov-small-badge)
*by Marc Grimme*
A formatter that generates a small coverage badge for use in your project's readme using the SVG.
#### [simplecov_badger](https://github.com/traels-it/simplecov_badger)
*by traels.it*
A formatter that uploads your coverage to a server, that will then host a SVG badge of the score. No need to have the badge stored in repository.
#### [simplecov-cobertura](https://github.com/dashingrocket/simplecov-cobertura)
*by Jesse Bowes*
A formatter that generates Cobertura XML.
#### [simplecov-csv](https://github.com/fguillen/simplecov-csv)
*by Fernando Guillen*
CSV formatter for SimpleCov
#### [simplecov-erb](https://github.com/kpaulisse/simplecov-erb)
*by [Kevin Paulisse](https://github.com/kpaulisse)*
Flexible formatter that generates the output from an ERB template.
#### [simplecov-json](https://github.com/vicentllongo/simplecov-json)
*by Vicent Llongo*
JSON formatter for SimpleCov
#### [simplecov-lcov](https://github.com/fortissimo1997/simplecov-lcov)
*by fortissimo1997*
lcov formatter for SimpleCov
#### [simplecov-rcov](https://github.com/fguillen/simplecov-rcov)
*by Fernando Guillen*
"The target of this formatter is to cheat on Hudson so I can use the Ruby metrics plugin with SimpleCov."
#### [simplecov-single_file_reporter](https://github.com/grosser/simplecov-single_file_reporter)
*by [Michael Grosser](http://grosser.it)*
A formatter that prints the coverage of the file under test when you run a single test file.
#### [simplecov-t_wada](https://github.com/ysksn/simplecov-t_wada)
*by [Yosuke Kabuto](https://github.com/ysksn)*
t_wada AA formatter for SimpleCov
#### [simplecov-tailwindcss](https://github.com/chiefpansancolt/simplecov-tailwindcss)
*by [Chiefpansancolt](https://github.com/chiefpansancolt)*
A TailwindCSS & TailwindUI Designed HTML formatter with clean and easy search of files with a tabular left Navigation.
#### [simplecov-material](https://github.com/chiefpansancolt/simplecov-material)
*by [Chiefpansancolt](https://github.com/chiefpansancolt)*
A Material Designed HTML formatter with clean and easy search of files with a tabular left Navigation.
simplecov-0.22.0/doc/commercial-services.md 0000664 0000000 0000000 00000002356 14351411403 0020621 0 ustar 00root root 0000000 0000000 ## Commercial Services with SimpleCov integration
There is a bunch of services that offer integration with your existing CI pipeline and SimpleCov coverage
reports. Please note these are not associated with the SimpleCov project itself, so please report problems with
these integrations with their respective owners.
#### [Codacy](https://github.com/codacy/codacy-coverage-reporter)
*by [Codacy](https://www.codacy.com/)*
Upload coverage reports to [codacy.com](https://www.codacy.com/), a hosted (or self-hosted) software quality analysis platform that also includes coverage reporting.
#### [codeclimate](https://github.com/codeclimate/ruby-test-reporter)
*by [Code Climate](https://codeclimate.com/)*
Upload coverage reports to [codeclimate.com](https://codeclimate.com/), a hosted software quality analysis and that also includes coverage reporting.
#### [codecov](https://github.com/codecov/codecov-ruby)
*by [Codecov](https://codecov.io/)*
Upload coverage reports to [codecov.io](https://codecov.io/), a hosted coverage reporting solution.
#### [coveralls](https://github.com/lemurheavy/coveralls-ruby)
*by [Coveralls](https://coveralls.io/)*
Upload coverage reports to [coveralls.io](https://coveralls.io/), a hosted coverage reporting solution.
simplecov-0.22.0/doc/editor-integration.md 0000664 0000000 0000000 00000001147 14351411403 0020471 0 ustar 00root root 0000000 0000000 ## Editor integration
Some editors have a graphical integration for the simplecov gem.
#### [Atom Editor: coverage](https://atom.io/packages/coverage)
*by Philip Giuliani*
Adds an overview of your current test coverage to Atom.
#### [Sublime Editor: Simple​Cov](https://packagecontrol.io/packages/SimpleCov)
*by sentience*
Adds in editor live coverage highlighting, status bar coverage information, and summary coverage information.
#### [cadre](https://github.com/nyarly/cadre)
*by Judson Lester*
Includes a formatter for Simplecov that emits a Vim script to mark up code files with coverage information.
simplecov-0.22.0/features/ 0000775 0000000 0000000 00000000000 14351411403 0015406 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/features/branch_coverage.feature 0000664 0000000 0000000 00000003142 14351411403 0022073 0 ustar 00root root 0000000 0000000 @rspec @branch_coverage
Feature:
Simply executing branch coverage gives ok results.
Background:
Given I'm working on the project "faked_project"
Scenario:
Given SimpleCov for RSpec is configured with:
"""
require 'simplecov'
SimpleCov.start do
enable_coverage :branch
end
"""
When I open the coverage report generated with `bundle exec rspec spec`
Then I should see the groups:
| name | coverage | files |
| All Files | 91.8% | 7 |
And I should see a line coverage summary of 56/61
And I should see a branch coverage summary of 2/4
And I should see the source files:
| name | coverage | branch coverage |
| lib/faked_project.rb | 100.00 % | 100.00 % |
| lib/faked_project/some_class.rb | 80.00 % | 50.00 % |
| lib/faked_project/framework_specific.rb | 75.00 % | 100.00 % |
| lib/faked_project/meta_magic.rb | 100.00 % | 100.00 % |
| spec/forking_spec.rb | 100.00 % | 50.00 % |
| spec/meta_magic_spec.rb | 100.00 % | 100.00 % |
| spec/some_class_spec.rb | 100.00 % | 100.00 % |
When I open the detailed view for "lib/faked_project/some_class.rb"
Then I should see a line coverage summary of 12/15 for the file
And I should see a branch coverage summary of 1/2 for the file
And I should see coverage branch data like "then: 1"
And I should see coverage branch data like "else: 0"
simplecov-0.22.0/features/config_autoload.feature 0000664 0000000 0000000 00000003031 14351411403 0022115 0 ustar 00root root 0000000 0000000 @test_unit @rspec @config
Feature:
If you have multiple test suites, it can be a bit cumbersome
to keep the configuration across them in sync. SimpleCov
is able to find a config file called '.simplecov' that resides
in your project's root and will automatically use it when
loaded.
This gives you the ability to configure SimpleCov just once
and then use the same configuration on all test suites simply
by doing a 'require "simplecov"'
Background:
Given I'm working on the project "faked_project"
Scenario:
Given a file named ".simplecov" with:
"""
SimpleCov.start do
add_filter 'test.rb'
add_filter 'spec.rb'
end
"""
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
"""
Given SimpleCov for RSpec is configured with:
"""
require 'simplecov'
"""
When I successfully run `bundle exec rake test`
And I open the coverage report generated with `bundle exec rspec spec`
Then the report should be based upon:
| RSpec |
| Unit Tests |
And I should see the groups:
| name | coverage | files |
| All Files | 90.48% | 4 |
And I should see the source files:
| name | coverage |
| lib/faked_project.rb | 100.00 % |
| lib/faked_project/some_class.rb | 80.00 % |
| lib/faked_project/framework_specific.rb | 87.50 % |
| lib/faked_project/meta_magic.rb | 100.00 % |
simplecov-0.22.0/features/config_command_name.feature 0000664 0000000 0000000 00000002755 14351411403 0022737 0 ustar 00root root 0000000 0000000 @test_unit @rspec @merging @config
Feature: Custom names for individual test suites
Each test suite needs a name it can be identified by. SimpleCov tries
best to detect Rails' Unit, Functional, Integration tests as well as regular
Test/Unit, RSpec and Cucumber, but if that is insufficient, each test suite
config can be given a custom command name using SimpleCov.command_name.
Background:
Given I'm working on the project "faked_project"
Scenario:
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
SimpleCov.start do
command_name "I'm in UR Unitz"
end
"""
Given SimpleCov for RSpec is configured with:
"""
require 'simplecov'
SimpleCov.start do
command_name "Dreck macht Speck"
end
"""
When I open the coverage report generated with `bundle exec rake test`
Then the report should be based upon:
| I'm in UR Unitz |
When I open the coverage report generated with `bundle exec rspec spec`
Then the report should be based upon:
| Dreck macht Speck |
| I'm in UR Unitz |
Scenario: RSpec auto detection with spec/features
Given SimpleCov for RSpec is configured with:
"""
require 'simplecov'
SimpleCov.start
"""
And a file named "spec/features/foobar_spec.rb" with:
"""
"""
When I open the coverage report generated with `bundle exec rspec spec`
Then the report should be based upon:
| RSpec |
simplecov-0.22.0/features/config_coverage_dir.feature 0000664 0000000 0000000 00000002036 14351411403 0022742 0 ustar 00root root 0000000 0000000 @test_unit @config
Feature:
The output directory for test coverage can be customized
with the SimpleCov.coverage_dir setting. All coverage reports
will be put there instead of the default 'coverage' directory
in your project's root.
Background:
Given I'm working on the project "faked_project"
Scenario:
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
SimpleCov.start do
coverage_dir 'test/simplecov'
end
"""
When I successfully run `bundle exec rake test`
Then a coverage report should have been generated in "test/simplecov"
And a directory named "coverage" should not exist
Scenario:
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
SimpleCov.start do
coverage_dir '/tmp/test/simplecov'
end
"""
When I successfully run `bundle exec rake test`
Then a coverage report should have been generated in "/tmp/test/simplecov"
And a directory named "coverage" should not exist
simplecov-0.22.0/features/config_deactivate_merging.feature 0000664 0000000 0000000 00000002526 14351411403 0024136 0 ustar 00root root 0000000 0000000 @test_unit @rspec @merging @config
Feature:
If merging of test suite results is not desired, it can be deactivated,
thus leading to the coverage report being overwritten with the latest results
of a single test suite on each run of any suite.
It's probably preferrable to generate the individual suite results into separate
output directories instead (see SimpleCov.coverage_dir), but it is possible :)
Background:
Given I'm working on the project "faked_project"
Scenario:
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
SimpleCov.start do
use_merging false
end
"""
Given SimpleCov for RSpec is configured with:
"""
require 'simplecov'
SimpleCov.start do
use_merging false
end
"""
When I successfully run `bundle exec rake test`
Then a file named "coverage/index.html" should exist
But a file named "coverage/.resultset.json" should not exist
Given I open the coverage report
Then the report should be based upon:
| Unit Tests |
When I successfully run `bundle exec rspec spec`
Then a file named "coverage/index.html" should exist
But a file named "coverage/.resultset.json" should not exist
Given I open the coverage report
Then the report should be based upon:
| RSpec |
simplecov-0.22.0/features/config_enable_for_subprocesses.feature 0000664 0000000 0000000 00000002310 14351411403 0025200 0 ustar 00root root 0000000 0000000 @rspec @process_fork
Feature:
Coverage should include code run by subprocesses
Background:
Given I'm working on the project "subprocesses"
Scenario: Coverage has seen the subprocess line
When I open the coverage report generated with `bundle exec rspec spec/simple_spec.rb`
Then I should see the groups:
| name | coverage | files |
| All Files | 100.0% | 1 |
Scenario: The at_fork proc
Given a file named ".simplecov" with:
"""
SimpleCov.enable_for_subprocesses true
SimpleCov.command_name "parent process name"
SimpleCov.at_fork do |_pid|
SimpleCov.command_name "child process name"
SimpleCov.start
end
"""
When I open the coverage report generated with `bundle exec rspec spec/simple_spec.rb`
Then I should see the groups:
| name | coverage | files |
| All Files | 100.0% | 1 |
And the report should be based upon:
| child process name |
| parent process name |
Scenario: The documentation on .simplecov_spawn
When I open the coverage report generated with `bundle exec rspec spec/spawn_spec.rb`
Then I should see the groups:
| name | coverage | files |
| All Files | 100.0% | 1 |
simplecov-0.22.0/features/config_formatters.feature 0000664 0000000 0000000 00000004562 14351411403 0022505 0 ustar 00root root 0000000 0000000 @test_unit @config
Feature:
The formatter for test coverage can be customized
with the SimpleCov.formatter setting. There are two
built-in formatters:
SimpleCov::Formatter::SimpleFormatter is a simple
formatter returning a string of all files with
theirs coverages.
SimpleCov::Formatter::MultiFormatter is a formatter
used to call multiple formatters at once.
Background:
Given I'm working on the project "faked_project"
Scenario: With SimpleFormatter
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
SimpleCov.formatter = SimpleCov::Formatter::SimpleFormatter
SimpleCov.at_exit do
puts SimpleCov.result.format!
end
SimpleCov.start do
add_group 'Libs', 'lib/faked_project/'
end
"""
When I successfully run `bundle exec rake test`
Then the output should contain "lib/faked_project/meta_magic.rb (coverage: 100.0%)"
Scenario: With MultiFormatter
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
SimpleCov.formatters = [
SimpleCov::Formatter::SimpleFormatter,
Class.new do
def format(result)
raise "Unable to format"
end
end
]
SimpleCov.at_exit do
puts SimpleCov.result.format!.join
end
SimpleCov.start do
add_group 'Libs', 'lib/faked_project/'
end
"""
When I successfully run `bundle exec rake test`
Then the output should contain "lib/faked_project/meta_magic.rb (coverage: 100.0%)"
And the output should match /Formatter [^\s]* failed with RuntimeError: Unable to format/
Scenario: With multiple formatters
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
SimpleCov.formatters = [
SimpleCov::Formatter::SimpleFormatter,
Class.new do
def format(result)
raise "Unable to format"
end
end
]
SimpleCov.at_exit do
puts SimpleCov.result.format!.join
end
SimpleCov.start do
add_group 'Libs', 'lib/faked_project/'
end
"""
When I successfully run `bundle exec rake test`
Then the output should contain "lib/faked_project/meta_magic.rb (coverage: 100.0%)"
And the output should match /Formatter [^\s]* failed with RuntimeError: Unable to format/
simplecov-0.22.0/features/config_json_formatter.feature 0000664 0000000 0000000 00000002671 14351411403 0023352 0 ustar 00root root 0000000 0000000 @test_unit @config
Feature:
SimpleCov::Formatter::JSONFormatter is one of the
formatters included by default, useful for exporting
coverage results in JSON format.
Background:
Given I'm working on the project "faked_project"
Scenario: With JSONFormatter
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
require 'simplecov_json_formatter'
SimpleCov.formatter = SimpleCov::Formatter::JSONFormatter
SimpleCov.at_exit do
puts SimpleCov.result.format!
end
SimpleCov.start do
add_group 'Libs', 'lib/faked_project/'
end
"""
When I successfully run `bundle exec rake test`
Then a JSON coverage report should have been generated in "coverage"
And the output should contain "JSON Coverage report generated"
Scenario: When CC_TEST_REPORTER_ID is set in the environment
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
SimpleCov.at_exit do
puts SimpleCov.result.format!
end
SimpleCov.start do
add_group 'Libs', 'lib/faked_project/'
end
"""
And I set the environment variables to:
| variable | value |
| CC_TEST_REPORTER_ID | some-id |
When I successfully run `bundle exec rake test`
Then a JSON coverage report should have been generated in "coverage"
And the output should contain "JSON Coverage report generated"
simplecov-0.22.0/features/config_merge_timeout.feature 0000664 0000000 0000000 00000002347 14351411403 0023163 0 ustar 00root root 0000000 0000000 @test_unit @rspec @merging @config
Feature:
The maximum time between resultset merges can be customized
using SimpleCov.merge_timeout SECONDS. This can be helpful for
long-running test-suites that fail to merge because of the time
between individual suite finishes is more then the default timeout
of 10 minutes.
Here, for the sake of testing the opposite case is shown, choosing
a merge timeout so short that the first test suite's results actually
are out of date when the second suite finishes and thus does not end up
in the report.
Background:
Given I'm working on the project "faked_project"
Scenario:
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
SimpleCov.start do
merge_timeout 5
end
"""
Given SimpleCov for RSpec is configured with:
"""
require 'simplecov'
SimpleCov.start do
merge_timeout 5
end
"""
When I open the coverage report generated with `bundle exec rake test`
Then the report should be based upon:
| Unit Tests |
When I wait for 5 seconds
And I open the coverage report generated with `bundle exec rspec spec`
Then the report should be based upon:
| RSpec |
simplecov-0.22.0/features/config_nocov_token.feature 0000664 0000000 0000000 00000004752 14351411403 0022644 0 ustar 00root root 0000000 0000000 @test_unit @nocov
Feature:
Code wrapped in # :nocov: will be ignored by coverage reports.
The name of the token can be configured with SimpleCov.nocov_token or SimpleCov.skip_token
Background:
Given I'm working on the project "faked_project"
Scenario: Custom nocov token using nocov_token
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
SimpleCov.start 'test_frameworks' do
nocov_token 'skippit'
end
"""
Given a file named "lib/faked_project/nocov.rb" with:
"""
class SourceCodeWithNocov
# :skippit:
def some_weird_code
never_reached
rescue => err
but no one cares about invalid ruby here
end
# :skippit:
end
"""
When I open the coverage report generated with `bundle exec rake test`
Then I should see the source files:
| name | coverage |
| lib/faked_project.rb | 100.00 % |
| lib/faked_project/some_class.rb | 80.00 % |
| lib/faked_project/framework_specific.rb | 75.00 % |
| lib/faked_project/meta_magic.rb | 100.00 % |
| lib/faked_project/nocov.rb | 100.00 % |
And there should be 7 skipped lines in the source files
And the report should be based upon:
| Unit Tests |
Scenario: Custom nocov token using skip_token
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
SimpleCov.start 'test_frameworks' do
skip_token 'skippit'
end
"""
Given a file named "lib/faked_project/nocov.rb" with:
"""
class SourceCodeWithNocov
# :skippit:
def some_weird_code
never_reached
rescue => err
but no one cares about invalid ruby here
end
# :skippit:
end
"""
When I open the coverage report generated with `bundle exec rake test`
Then I should see the source files:
| name | coverage |
| lib/faked_project.rb | 100.00 % |
| lib/faked_project/some_class.rb | 80.00 % |
| lib/faked_project/framework_specific.rb | 75.00 % |
| lib/faked_project/meta_magic.rb | 100.00 % |
| lib/faked_project/nocov.rb | 100.00 % |
And there should be 7 skipped lines in the source files
And the report should be based upon:
| Unit Tests |
simplecov-0.22.0/features/config_profiles.feature 0000664 0000000 0000000 00000002511 14351411403 0022132 0 ustar 00root root 0000000 0000000 @test_unit @config @profiles
Feature:
In order to re-use SimpleCov settings across projects,
profiles can be defined that hold configuration settings
that can be loaded at once.
Background:
Given I'm working on the project "faked_project"
And SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
"""
Scenario: Defining and using a custom profile
Given a file named ".simplecov" with:
"""
SimpleCov.profiles.define 'custom_command' do
command_name "Profile Command"
end
SimpleCov.start do
load_profile 'test_frameworks'
load_profile 'custom_command'
end
"""
When I open the coverage report generated with `bundle exec rake test`
Then I should see "4 files in total."
And I should see "using Profile Command" within "#footer"
Scenario: Using existing profile in custom profile and supplying profile to start command
Given a file named ".simplecov" with:
"""
SimpleCov.profiles.define 'my_profile' do
load_profile 'test_frameworks'
command_name "My Profile"
end
SimpleCov.start 'my_profile'
"""
When I open the coverage report generated with `bundle exec rake test`
Then I should see "4 files in total."
And I should see "using My Profile" within "#footer"
simplecov-0.22.0/features/config_project_name.feature 0000664 0000000 0000000 00000001573 14351411403 0022764 0 ustar 00root root 0000000 0000000 @test_unit @config
Feature:
SimpleCov guesses the project name from the project root dir's name.
If this is not sufficient for you, you can specify a custom name using
SimpleCov.project_name('xyz')
Background:
Given I'm working on the project "faked_project"
Scenario: Guessed name
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
SimpleCov.start
"""
When I open the coverage report generated with `bundle exec rake test`
Then I should see "Code coverage for Project" within "title"
Scenario: Custom name
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
SimpleCov.start { project_name "Superfancy 2.0" }
"""
When I open the coverage report generated with `bundle exec rake test`
Then I should see "Code coverage for Superfancy 2.0" within "title"
simplecov-0.22.0/features/config_root.feature 0000664 0000000 0000000 00000001423 14351411403 0021273 0 ustar 00root root 0000000 0000000 @rspec @disable-bundler
Feature:
The root of the project can be customized.
Background:
Given I'm working on the project "monorepo"
Scenario: A coverage result is considered if it falls inside the root of the project
Given I install dependencies
And a file named ".simplecov" with:
"""
SimpleCov.start do
root __dir__
end
"""
When I open the coverage report generated with `bin/rspec_binstub_that_chdirs extra/spec/extra_spec.rb`
Then I should see the groups:
| name | coverage | files |
| All Files | 100.0% | 2 |
And I should see the source files:
| name | coverage |
| base/lib/monorepo/base.rb | 100.00 % |
| extra/lib/monorepo/extra.rb | 100.00 % |
simplecov-0.22.0/features/config_styles.feature 0000664 0000000 0000000 00000007142 14351411403 0021637 0 ustar 00root root 0000000 0000000 @test_unit @config
Feature:
There's several ways to configure SimpleCov. All of those
config schemes below are equivalent and can be chosen by personal
preference or project requirements.
Background:
Given I'm working on the project "faked_project"
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
"""
Scenario: Inside start block
Given a file named ".simplecov" with:
"""
SimpleCov.start do
add_filter 'test'
command_name 'Config Test Runner'
end
"""
When I open the coverage report generated with `bundle exec rake test`
Then I should see "4 files in total."
And I should see "using Config Test Runner" within "#footer"
Scenario: Inside start block, using instance var from outside
Given a file named ".simplecov" with:
"""
@filter = 'test'
SimpleCov.start do
add_filter @filter
command_name 'Config Test Runner'
end
"""
When I open the coverage report generated with `bundle exec rake test`
Then I should see "4 files in total."
And I should see "using Config Test Runner" within "#footer"
Scenario: Inside start block, using local var from outside
Given a file named ".simplecov" with:
"""
filter = 'test'
SimpleCov.start do
add_filter filter
command_name 'Config Test Runner'
end
"""
When I open the coverage report generated with `bundle exec rake test`
Then I should see "4 files in total."
And I should see "using Config Test Runner" within "#footer"
Scenario: Explicitly before start block
Given a file named ".simplecov" with:
"""
SimpleCov.add_filter 'test'
SimpleCov.command_name 'Config Test Runner'
SimpleCov.start
"""
When I open the coverage report generated with `bundle exec rake test`
Then I should see "4 files in total."
And I should see "using Config Test Runner" within "#footer"
Scenario: Explicitly after start block
Given a file named ".simplecov" with:
"""
SimpleCov.start
SimpleCov.add_filter 'test'
SimpleCov.command_name 'Config Test Runner'
"""
When I open the coverage report generated with `bundle exec rake test`
Then I should see "4 files in total."
And I should see "using Config Test Runner" within "#footer"
Scenario: Using configure block after start
Given a file named ".simplecov" with:
"""
SimpleCov.start
SimpleCov.configure do
add_filter 'test'
command_name 'Config Test Runner'
end
"""
When I open the coverage report generated with `bundle exec rake test`
Then I should see "4 files in total."
And I should see "using Config Test Runner" within "#footer"
Scenario: Using configure block before start
Given a file named ".simplecov" with:
"""
SimpleCov.configure do
add_filter 'test'
command_name 'Config Test Runner'
end
SimpleCov.start
"""
When I open the coverage report generated with `bundle exec rake test`
Then I should see "4 files in total."
And I should see "using Config Test Runner" within "#footer"
Scenario: Mixing configure and start block config
Given a file named ".simplecov" with:
"""
SimpleCov.configure do
command_name 'Config Test Runner'
end
SimpleCov.start do
add_filter 'test'
end
"""
When I open the coverage report generated with `bundle exec rake test`
Then I should see "4 files in total."
And I should see "using Config Test Runner" within "#footer"
simplecov-0.22.0/features/config_tracked_files.feature 0000664 0000000 0000000 00000002077 14351411403 0023115 0 ustar 00root root 0000000 0000000 @test_unit
Feature:
Using the setting `tracked_files` should add files that were not
required to the report.
Background:
Given I'm working on the project "faked_project"
Scenario:
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
SimpleCov.start do
track_files "lib/**/*.rb"
end
"""
When I open the coverage report generated with `bundle exec rake test`
Then I should see the groups:
| name | coverage | files |
| All Files | 77.94% | 7 |
And I should see the source files:
| name | coverage |
| lib/faked_project.rb | 100.00 % |
| lib/faked_project/untested_class.rb | 0.00 % |
| lib/faked_project/some_class.rb | 80.00 % |
| lib/faked_project/framework_specific.rb | 75.00 % |
| lib/faked_project/meta_magic.rb | 100.00 % |
| test/meta_magic_test.rb | 100.00 % |
| test/some_class_test.rb | 100.00 % |
simplecov-0.22.0/features/config_tracked_files_relevant_lines.feature 0000664 0000000 0000000 00000001501 14351411403 0026176 0 ustar 00root root 0000000 0000000 @rspec
Feature:
Using the setting `tracked_files` should classify whether lines
are relevant or not (such as whitespace or comments).
Background:
Given I'm working on the project "faked_project"
Scenario:
Given SimpleCov for RSpec is configured with:
"""
require 'simplecov'
SimpleCov.start do
track_files "lib/**/*.rb"
end
"""
Given a file named "lib/not_loaded.rb" with:
"""
# A comment line. Plus a whitespace line below:
# :nocov:
def ignore_me
end
# :nocov:
def this_is_relevant
puts "still relevant"
end
"""
When I open the coverage report generated with `bundle exec rspec spec`
And I follow "lib/not_loaded.rb"
Then the overlay should be open
And I should see "3 relevant lines" within "#cboxContent"
simplecov-0.22.0/features/cucumber_basic.feature 0000664 0000000 0000000 00000002004 14351411403 0021725 0 ustar 00root root 0000000 0000000 @cucumber
Feature:
Simply adding the basic simplecov lines to a project should get
the user a coverage report after running `cucumber features`
Background:
Given I'm working on the project "faked_project"
Scenario:
Given SimpleCov for Cucumber is configured with:
"""
require 'simplecov'
SimpleCov.start
"""
When I open the coverage report generated with `bundle exec cucumber features`
Then I should see the groups:
| name | coverage | files |
| All Files | 90.91% | 5 |
And I should see the source files:
| name | coverage |
| lib/faked_project.rb | 100.00 % |
| lib/faked_project/some_class.rb | 80.00 % |
| lib/faked_project/framework_specific.rb | 75.00 % |
| lib/faked_project/meta_magic.rb | 100.00 % |
| features/step_definitions/my_steps.rb | 100.00 % |
And the report should be based upon:
| Cucumber Features |
simplecov-0.22.0/features/encoding.feature 0000664 0000000 0000000 00000002236 14351411403 0020554 0 ustar 00root root 0000000 0000000 @rspec
Feature:
We've experienced some problems given source file encoding.
We want to make sure we try the appropriate encoding and
can display it correcty in the formatter.
Background:
Given I'm working on the project "encodings"
Scenario: Running tests produces coverage and it's mostly legible
When I open the coverage report generated with `bundle exec rspec spec`
Then I should see the groups:
| name | coverage | files |
| All Files | 55.56% | 4 |
When I open the detailed view for "lib/utf8.rb"
Then "�" should not be visible
And "🇯🇵" should be visible
And "ãŠã¯ã‚ˆã†" should be visible
When I close the detailed view
And I open the detailed view for "lib/euc_jp.rb"
Then "�" should not be visible
And "ãŠã¯ã‚ˆã†" should be visible
When I close the detailed view
And I open the detailed view for "lib/euc_jp_not_declared.rb"
Then "�" should not be visible
And "Fun3" should be visible
When I close the detailed view
And I open the detailed view for "lib/euc_jp_not_declared_tracked.rb"
# no way around it I guess
Then "�" should be visible
And "NoDeclare" should be visible
simplecov-0.22.0/features/maximum_coverage_drop.feature 0000664 0000000 0000000 00000022623 14351411403 0023344 0 ustar 00root root 0000000 0000000 @test_unit @config
Feature:
Exit code should be non-zero if the overall coverage decreases by more than
the maximum_coverage_drop threshold.
Background:
Given I'm working on the project "faked_project"
Scenario: maximum_coverage_drop configured can cause spec failure
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
SimpleCov.start do
add_filter 'test.rb'
maximum_coverage_drop 3.14
end
"""
When I run `bundle exec rake test`
Then the exit status should be 0
And a file named "coverage/.last_run.json" should exist
Given a file named "lib/faked_project/missed.rb" with:
"""
class UncoveredSourceCode
def foo
never_reached
rescue => err
but no one cares about invalid ruby here
end
end
"""
When I run `bundle exec rake test`
Then the exit status should not be 0
And the output should contain "Line coverage has dropped by 3.31% since the last time (maximum allowed: 3.14%)."
And a file named "coverage/.last_run.json" should exist
And the file "coverage/.last_run.json" should contain:
"""
{
"result": {
"line": 88.09
}
}
"""
Scenario: maximum_coverage_drop not configured updates resultset
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
SimpleCov.start do
add_filter 'test.rb'
end
"""
When I run `bundle exec rake test`
Then the exit status should be 0
And a file named "coverage/.last_run.json" should exist
And the file "coverage/.last_run.json" should contain:
"""
{
"result": {
"line": 88.09
}
}
"""
Given a file named "lib/faked_project/missed.rb" with:
"""
class UncoveredSourceCode
def foo
never_reached
rescue => err
but no one cares about invalid ruby here
end
end
"""
When I run `bundle exec rake test`
Then the exit status should be 0
And a file named "coverage/.last_run.json" should exist
And the file "coverage/.last_run.json" should contain:
"""
{
"result": {
"line": 84.78
}
}
"""
Scenario: test failures do not update the resultset
Given SimpleCov for RSpec is configured with:
"""
require 'simplecov'
SimpleCov.start do
add_group 'Libs', 'lib/faked_project/'
add_filter '/spec/'
maximum_coverage_drop 0
end
"""
And a file named "lib/faked_project/missed.rb" with:
"""
class UncoveredSourceCode
def foo
never_reached
rescue => err
but no one cares about invalid ruby here
end
end
"""
And a file named "spec/failing_spec.rb" with:
"""
require "spec_helper"
describe FakedProject do
it "fails" do
expect(false).to eq(true)
end
end
"""
And the file named "coverage/.last_run.json" with:
"""
{
"result": {
"line": 100.0
}
}
"""
When I run `bundle exec rspec spec`
Then the exit status should be 1
And a file named "coverage/.last_run.json" should exist
And the file "coverage/.last_run.json" should contain:
"""
{
"result": {
"line": 100.0
}
}
"""
Scenario: When the previous last_run file has legacy covered_percent it still works
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
SimpleCov.start do
add_filter 'test.rb'
maximum_coverage_drop 0
end
"""
And the file "coverage/.last_run.json" with:
"""
{
"result": {
"covered_percent": 88.09
}
}
"""
When I run `bundle exec rake test`
Then the exit status should be 0
And a file named "coverage/.last_run.json" should exist
And the file "coverage/.last_run.json" should contain:
"""
{
"result": {
"line": 88.09
}
}
"""
Scenario: When the previous last_run file has covered_percent and we fail does not update it
Given SimpleCov for RSpec is configured with:
"""
require 'simplecov'
SimpleCov.start do
add_group 'Libs', 'lib/faked_project/'
add_filter '/spec/'
maximum_coverage_drop 0
end
"""
And a file named "lib/faked_project/missed.rb" with:
"""
class UncoveredSourceCode
def foo
never_reached
rescue => err
but no one cares about invalid ruby here
end
end
"""
And a file named "spec/failing_spec.rb" with:
"""
require "spec_helper"
describe FakedProject do
it "fails" do
expect(false).to eq(true)
end
end
"""
And the file named "coverage/.last_run.json" with:
"""
{
"result": {
"covered_percent": 100.0
}
}
"""
When I run `bundle exec rspec spec`
Then the exit status should be 1
And a file named "coverage/.last_run.json" should exist
And the file "coverage/.last_run.json" should contain:
"""
{
"result": {
"covered_percent": 100.0
}
}
"""
@branch_coverage
Scenario: Works together with branch coverage and line coverage, announcing both failures
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
SimpleCov.start do
add_filter 'test.rb'
enable_coverage :branch
maximum_coverage_drop line: 0, branch: 0
end
"""
And a file named "lib/faked_project/missed.rb" with:
"""
class UncoveredSourceCode
def foo
never_reached
rescue => err
but no one cares about invalid ruby here
end
end
"""
And a file named "spec/failing_spec.rb" with:
"""
require "spec_helper"
describe FakedProject do
it "fails" do
false ? true : expect(false).to eq(true)
end
end
"""
And the file named "coverage/.last_run.json" with:
"""
{
"result": {
"line": 100.0,
"branch": 100.0
}
}
"""
When I run `bundle exec rake test`
Then the exit status should not be 0
And the output should contain "Line coverage has dropped by 15.22% since the last time (maximum allowed: 0.00%)."
And the output should contain "Branch coverage has dropped by 50.00% since the last time (maximum allowed: 0.00%)."
And the output should contain "SimpleCov failed with exit 3"
@branch_coverage
Scenario: Can set branch as primary coverage and it will fail if branch is below maximum coverage drop
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
SimpleCov.start do
add_filter 'test.rb'
enable_coverage :branch
primary_coverage :branch
maximum_coverage_drop 0
end
"""
And a file named "lib/faked_project/missed.rb" with:
"""
class UncoveredSourceCode
def foo
never_reached
rescue => err
but no one cares about invalid ruby here
end
end
"""
And a file named "spec/failing_spec.rb" with:
"""
require "spec_helper"
describe FakedProject do
it "fails" do
false ? true : expect(false).to eq(true)
end
end
"""
And the file named "coverage/.last_run.json" with:
"""
{
"result": {
"line": 100.0,
"branch": 100.0
}
}
"""
When I run `bundle exec rake test`
Then the exit status should not be 0
And the output should not contain "Line coverage"
And the output should contain "Branch coverage has dropped by 50.00% since the last time (maximum allowed: 0.00%)."
And the output should contain "SimpleCov failed with exit 3"
@branch_coverage
Scenario: Can set branch as primary coverage and it will fail if branch is below maximum coverage drop
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
SimpleCov.start do
add_filter 'test.rb'
enable_coverage :branch
primary_coverage :branch
maximum_coverage_drop line: 0, branch: 0
end
"""
And a file named "lib/faked_project/missed.rb" with:
"""
class UncoveredSourceCode
def foo
never_reached
rescue => err
but no one cares about invalid ruby here
end
end
"""
And a file named "spec/failing_spec.rb" with:
"""
require "spec_helper"
describe FakedProject do
it "fails" do
false ? true : expect(false).to eq(true)
end
end
"""
And the file named "coverage/.last_run.json" with:
"""
{
"result": {
"line": 100.0,
"branch": 100.0
}
}
"""
When I run `bundle exec rake test`
Then the exit status should not be 0
And the output should contain "Branch coverage has dropped by 50.00% since the last time (maximum allowed: 0.00%)."
And the output should contain "Line coverage has dropped by 15.22% since the last time (maximum allowed: 0.00%)."
And the output should contain "SimpleCov failed with exit 3"
simplecov-0.22.0/features/merging_test_unit_and_rspec.feature 0000664 0000000 0000000 00000002670 14351411403 0024534 0 ustar 00root root 0000000 0000000 @test_unit @rspec @merging
Feature:
Test suites like RSpec and Test/Unit should be merged automatically
when both have been run recently. The coverage report will feature
the joined results of all test suites that are using SimpleCov.
Background:
Given I'm working on the project "faked_project"
Scenario:
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
SimpleCov.start do
add_filter 'test.rb'
add_filter 'spec.rb'
end
"""
And SimpleCov for RSpec is configured with:
"""
require 'simplecov'
SimpleCov.start do
add_filter 'test.rb'
add_filter 'spec.rb'
end
"""
When I open the coverage report generated with `bundle exec rake test`
Then the report should be based upon:
| Unit Tests |
When I open the coverage report generated with `bundle exec rspec spec`
Then the report should be based upon:
| RSpec |
| Unit Tests |
And I should see the groups:
| name | coverage | files |
| All Files | 90.48% | 4 |
And I should see the source files:
| name | coverage |
| lib/faked_project.rb | 100.00 % |
| lib/faked_project/some_class.rb | 80.00 % |
| lib/faked_project/framework_specific.rb | 87.50 % |
| lib/faked_project/meta_magic.rb | 100.00 % |
simplecov-0.22.0/features/minimum_coverage.feature 0000664 0000000 0000000 00000005552 14351411403 0022320 0 ustar 00root root 0000000 0000000 @test_unit @config
Feature:
Exit code should be non-zero if the overall coverage is below the
minimum_coverage threshold.
Background:
Given I'm working on the project "faked_project"
Scenario: It fails against too high coverage
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
SimpleCov.start do
add_filter 'test.rb'
minimum_coverage 90
end
"""
When I run `bundle exec rake test`
Then the exit status should not be 0
And the output should contain "Line coverage (88.09%) is below the expected minimum coverage (90.00%)."
And the output should contain "SimpleCov failed with exit 2"
Scenario: It fails if it's just 0.01% too low
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
SimpleCov.start do
add_filter 'test.rb'
minimum_coverage 88.10
end
"""
When I run `bundle exec rake test`
Then the exit status should not be 0
And the output should contain "Line coverage (88.09%) is below the expected minimum coverage (88.10%)."
And the output should contain "SimpleCov failed with exit 2"
Scenario: It passes when it is exactly the coverage
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
SimpleCov.start do
add_filter 'test.rb'
minimum_coverage 88.09
end
"""
When I run `bundle exec rake test`
Then the exit status should be 0
@branch_coverage
Scenario: Works together with branch coverage and the new criterion announcing both failures
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
SimpleCov.start do
add_filter 'test.rb'
enable_coverage :branch
minimum_coverage line: 90, branch: 80
end
"""
When I run `bundle exec rake test`
Then the exit status should not be 0
And the output should contain "Line coverage (88.09%) is below the expected minimum coverage (90.00%)."
And the output should contain "Branch coverage (50.00%) is below the expected minimum coverage (80.00%)."
And the output should contain "SimpleCov failed with exit 2"
@branch_coverage
Scenario: Can set branch as primary coverage and it will fail if branch is below minimum coverage
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
SimpleCov.start do
add_filter 'test.rb'
enable_coverage :branch
primary_coverage :branch
minimum_coverage 80
end
"""
When I run `bundle exec rake test`
Then the exit status should not be 0
And the output should contain "Branch coverage (50.00%) is below the expected minimum coverage (80.00%)."
And the output should not contain "Line coverage"
And the output should contain "SimpleCov failed with exit 2"
simplecov-0.22.0/features/minimum_coverage_by_file.feature 0000664 0000000 0000000 00000004637 14351411403 0024014 0 ustar 00root root 0000000 0000000 @test_unit @config
Feature:
Exit code should be non-zero if the coverage of any one file is below the configured value.
Background:
Given I'm working on the project "faked_project"
Scenario: slightly under minimum coverage by file
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
SimpleCov.start do
add_filter 'test.rb'
minimum_coverage_by_file 75.01
end
"""
When I run `bundle exec rake test`
Then the exit status should not be 0
And the output should contain "Line coverage by file (75.00%) is below the expected minimum coverage (75.01%)."
And the output should contain "SimpleCov failed with exit 2"
Scenario: Just passing it
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
SimpleCov.start do
add_filter 'test.rb'
minimum_coverage_by_file 75
end
"""
When I run `bundle exec rake test`
Then the exit status should be 0
@branch_coverage
Scenario: Works together with branch coverage and the new criterion announcing both failures
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
SimpleCov.start do
add_filter 'test.rb'
enable_coverage :branch
minimum_coverage_by_file line: 90, branch: 70
end
"""
When I run `bundle exec rake test`
Then the exit status should not be 0
And the output should contain "Line coverage by file (80.00%) is below the expected minimum coverage (90.00%)."
And the output should contain "Branch coverage by file (50.00%) is below the expected minimum coverage (70.00%)."
And the output should contain "SimpleCov failed with exit 2"
@branch_coverage
Scenario: Can set branch as primary coverage and it will fail if branch is below minimum coverage
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
SimpleCov.start do
add_filter 'test.rb'
enable_coverage :branch
primary_coverage :branch
minimum_coverage_by_file 70
end
"""
When I run `bundle exec rake test`
Then the exit status should not be 0
And the output should contain "Branch coverage by file (50.00%) is below the expected minimum coverage (70.00%)."
And the output should not contain "Line coverage"
And the output should contain "SimpleCov failed with exit 2"
simplecov-0.22.0/features/minitest_basic.feature 0000664 0000000 0000000 00000003650 14351411403 0021764 0 ustar 00root root 0000000 0000000 @minitest
Feature:
"Working with minitest"
Background:
Given I'm working on the project "faked_project"
Scenario:
Given SimpleCov for Minitest is configured with:
"""
require 'simplecov'
SimpleCov.start do
add_filter "test_helper.rb"
end
"""
When I open the coverage report generated with `bundle exec rake minitest`
Then I should see the groups:
| name | coverage | files |
| All Files | 87.5% | 2 |
And I should see the source files:
| name | coverage |
| lib/faked_project/some_class.rb | 80.00 % |
| minitest/some_test.rb | 100.00 % |
Scenario:
Given SimpleCov for Minitest is configured with:
"""
require 'simplecov'
SimpleCov.start
"""
When I open the coverage report generated with `bundle exec ruby -Ilib:minitest minitest/other_test.rb`
Then I should see the groups:
| name | coverage | files |
| All Files | 80.0% | 1 |
And I should see the source files:
| name | coverage |
| lib/faked_project/some_class.rb | 80.00 % |
Scenario: Not having simplecov loaded/enabled it does not crash #877
Given SimpleCov for Minitest is configured with:
"""
# nothing
"""
# What's this? Path requirements in the Gemfile evaluate the gemspec,
# which normally loads the version, which defined SimpleCov which leads
# to a different failure. This works around that issue.
# Somehow putting an arbitrary version broks the Gemfile. Using a current
# version seems to work.
And I set the environment variables to:
| variable | value |
| SIMPLECOV_NO_REQUIRE_VERSION | 0.22.0 |
When I successfully run `bundle exec rake minitest`
Then no coverage report should have been generated
simplecov-0.22.0/features/old_version_json.feature 0000664 0000000 0000000 00000002206 14351411403 0022337 0 ustar 00root root 0000000 0000000 @rspec
Feature:
This test project has a resultset.json generated by simplecov 0.17.1 lying around
(we changed the file format in 0.18) - as long as we want a hassle free upgrade
path from 0.17 and below to our current version this cuke should pass :) #820
Background:
Given I'm working on the project "old_coverage_json"
Scenario: Running the tests succeeds
Given the paths in the old .resultset.json are adjusted to the current environment
When I open the coverage report generated with `bundle exec rspec spec`
Then I should see the groups:
| name | coverage | files |
| All Files | 88.89% | 2 |
And I should see a line coverage summary of 8/9
Scenario: Running the tests succeeds even with a current time stamp
Given the paths in the old .resultset.json are adjusted to the current environment
And the timestamp in the .resultset.json is current
When I open the coverage report generated with `bundle exec rspec spec`
Then I should see the groups:
| name | coverage | files |
| All Files | 88.89% | 2 |
And I should see a line coverage summary of 8/9
simplecov-0.22.0/features/pagination.feature 0000664 0000000 0000000 00000001257 14351411403 0021121 0 ustar 00root root 0000000 0000000 @rspec
Feature:
We don't want to have pagination.
But it's good to have a test project that would at least trigger
pagination for 10+ source files or so, so we can avoid nasty surprises.
Background:
Given I'm working on the project "pagination"
Scenario:
When I open the coverage report generated with `bundle exec rspec`
Then I should see the groups:
| name | coverage | files |
| All Files | 100.0% | 12 |
When I open the detailed view for "lib/a.rb"
Then "nothing to see here" should be visible
When I close the detailed view
And I open the detailed view for "lib/l.rb"
Then "nothing to see here" should be visible
simplecov-0.22.0/features/parallel_tests.feature 0000664 0000000 0000000 00000004547 14351411403 0022013 0 ustar 00root root 0000000 0000000 @rspec @disable-bundler
Feature:
Parallel tests and its corresponding test project work together with Simplecov
just fine and they produce the same output like a normal rspec run.
Background:
Given I'm working on the project "parallel_tests"
Scenario: Running it through parallel_tests produces the same results as a normal rspec run
Given I install dependencies
And SimpleCov for RSpec is configured with:
"""
require 'simplecov'
SimpleCov.start
"""
When I open the coverage report generated with `bundle exec parallel_rspec spec`
Then I should see the line coverage results for the parallel tests project
# Note it's better not to test this in the same scenario as before.
# Merging of results might kick in and ruin this.
Scenario: Running the project with normal rspec
Given I install dependencies
And SimpleCov for RSpec is configured with:
"""
require 'simplecov'
SimpleCov.start
"""
When I open the coverage report generated with `bundle exec rspec spec`
Then I should see the line coverage results for the parallel tests project
@branch_coverage
Scenario: Running the project with normal rspec and branch coverage
Given I install dependencies
And SimpleCov for RSpec is configured with:
"""
require 'simplecov'
SimpleCov.start do
enable_coverage :branch
end
"""
When I open the coverage report generated with `bundle exec rspec spec`
Then I should see the branch coverage results for the parallel tests project
@branch_coverage
Scenario: Running the project with normal rspec and branch coverage
Given I install dependencies
And SimpleCov for RSpec is configured with:
"""
require 'simplecov'
SimpleCov.start do
enable_coverage :branch
end
"""
When I open the coverage report generated with `bundle exec parallel_rspec spec`
Then I should see the branch coverage results for the parallel tests project
Scenario: Coverage violations aren't printed until the end
Given I install dependencies
And SimpleCov for RSpec is configured with:
"""
require 'simplecov'
SimpleCov.start do
minimum_coverage 89
end
"""
When I successfully run `bundle exec parallel_rspec spec`
Then the output should not match /+cover.+below.+minimum/
simplecov-0.22.0/features/refuse_coverage_drop.feature 0000664 0000000 0000000 00000004636 14351411403 0023164 0 ustar 00root root 0000000 0000000 @test_unit @config
Feature:
Exit code should be non-zero if the overall coverage decreases.
And last_run file should not be overwritten with new coverage value.
Background:
Given I'm working on the project "faked_project"
Scenario: refuse_coverage_drop configured
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
SimpleCov.start do
add_filter 'test.rb'
refuse_coverage_drop
end
"""
When I run `bundle exec rake test`
Then the exit status should be 0
And a file named "coverage/.last_run.json" should exist
And the file "coverage/.last_run.json" should contain:
"""
{
"result": {
"line": 88.09
}
}
"""
Given a file named "lib/faked_project/missed.rb" with:
"""
class UncoveredSourceCode
def foo
never_reached
rescue => err
but no one cares about invalid ruby here
end
end
"""
When I run `bundle exec rake test`
Then the exit status should not be 0
And the output should contain "Line coverage has dropped by 3.31% since the last time (maximum allowed: 0.00%)."
And a file named "coverage/.last_run.json" should exist
And the file "coverage/.last_run.json" should contain:
"""
{
"result": {
"line": 88.09
}
}
"""
Scenario: refuse_coverage_drop not configured updates resultset
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
SimpleCov.start do
add_filter 'test.rb'
end
"""
When I run `bundle exec rake test`
Then the exit status should be 0
And a file named "coverage/.last_run.json" should exist
And the file "coverage/.last_run.json" should contain:
"""
{
"result": {
"line": 88.09
}
}
"""
Given a file named "lib/faked_project/missed.rb" with:
"""
class UncoveredSourceCode
def foo
never_reached
rescue => err
but no one cares about invalid ruby here
end
end
"""
When I run `bundle exec rake test`
Then the exit status should be 0
And a file named "coverage/.last_run.json" should exist
And the file "coverage/.last_run.json" should contain:
"""
{
"result": {
"line": 84.78
}
}
"""
simplecov-0.22.0/features/rspec_basic.feature 0000664 0000000 0000000 00000002562 14351411403 0021245 0 ustar 00root root 0000000 0000000 @rspec
Feature:
Simply adding the basic simplecov lines to a project should get
the user a coverage report after running `rspec`
Background:
Given I'm working on the project "faked_project"
Scenario:
Given SimpleCov for RSpec is configured with:
"""
require 'simplecov'
SimpleCov.start
"""
When I open the coverage report generated with `bundle exec rspec spec`
Then I should see the groups:
| name | coverage | files |
| All Files | 91.8% | 7 |
And I should see the source files:
| name | coverage |
| lib/faked_project.rb | 100.00 % |
| lib/faked_project/some_class.rb | 80.00 % |
| lib/faked_project/framework_specific.rb | 75.00 % |
| lib/faked_project/meta_magic.rb | 100.00 % |
| spec/forking_spec.rb | 100.00 % |
| spec/meta_magic_spec.rb | 100.00 % |
| spec/some_class_spec.rb | 100.00 % |
# Note: faked_spec.rb is not appearing here since that's the first unit test file
# loaded by Rake, and only there test_helper is required, which then loads simplecov
# and triggers tracking of all other loaded files! Solution for this would be to
# configure simplecov in this first test instead of test_helper.
simplecov-0.22.0/features/rspec_failing.feature 0000664 0000000 0000000 00000001313 14351411403 0021566 0 ustar 00root root 0000000 0000000 @rspec
Feature:
RSpec failing in different ways results SimpleCov saying something beforehand. However it doesn't identify itself as the originator of said error.
Background:
Given I'm working on the project "faked_project"
Scenario:
When I run `bundle exec rspec bad_spec/failing_spec.rb`
Then the exit status should not be 0
And the output should match /SimpleCov.+previous.+error/
And the output should not match /SimpleCov.+exit.+with.+status/
Scenario:
When I run `bundle exec rspec bad_spec/fail_with_5.rb`
Then the exit status should be 5
And the output should match /SimpleCov.+previous.+error/
And the output should not match /SimpleCov.+exit.+with.+status/
simplecov-0.22.0/features/rspec_fails_on_initialization.feature 0000664 0000000 0000000 00000000714 14351411403 0025062 0 ustar 00root root 0000000 0000000 @rspec
Feature:
Running specs with a failing rspec setup
Background:
Given I'm working on the project "faked_project"
Scenario: Fail if rspec fails before starting its tests
Given a file named "spec/spec_helper.rb" with:
"""
require 'simplecov'
SimpleCov.start
raise "some exception in the class loading before the tests start"
"""
When I run `bundle exec rspec spec`
Then the exit status should not be 0
simplecov-0.22.0/features/rspec_groups_and_filters_basic.feature 0000664 0000000 0000000 00000002031 14351411403 0025205 0 ustar 00root root 0000000 0000000 @rspec
Feature:
Defining some groups and filters should give a corresponding
coverage report that respects those settings after running rspec
Background:
Given I'm working on the project "faked_project"
Scenario:
Given SimpleCov for RSpec is configured with:
"""
require 'simplecov'
SimpleCov.start do
add_group 'Libs', 'lib/faked_project/'
add_filter '/spec/'
end
"""
When I open the coverage report generated with `bundle exec rspec spec`
And I should see the groups:
| name | coverage | files |
| All Files | 88.1% | 4 |
| Libs | 86.11% | 3 |
| Ungrouped | 100.0% | 1 |
And I should see the source files:
| name | coverage |
| lib/faked_project.rb | 100.00 % |
| lib/faked_project/some_class.rb | 80.00 % |
| lib/faked_project/framework_specific.rb | 75.00 % |
| lib/faked_project/meta_magic.rb | 100.00 % |
simplecov-0.22.0/features/rspec_groups_and_filters_complex.feature 0000664 0000000 0000000 00000002632 14351411403 0025602 0 ustar 00root root 0000000 0000000 @rspec
Feature: Sophisticated grouping and filtering on RSpec
Defining groups and filters can be done by passing blocks or strings.
Blocks get each SimpleCov::SourceFile instance passed an can use arbitrary
and potentially weird conditions to remove files from the report or add them
to specific groups.
Background:
Given I'm working on the project "faked_project"
Scenario:
Given SimpleCov for RSpec is configured with:
"""
require 'simplecov'
SimpleCov.start do
add_group 'By block' do |src_file|
src_file.filename =~ /MaGiC/i
end
add_group 'By string', 'project/meta_magic'
add_group 'By array', ['project/meta_magic']
add_filter 'faked_project.rb'
# Remove all files that include "describe" in their source
add_filter {|src_file| src_file.lines.any? {|line| line.src =~ /describe/ } }
add_filter {|src_file| src_file.covered_percent < 100 }
end
"""
When I open the coverage report generated with `bundle exec rspec spec`
Then I should see the groups:
| name | coverage | files |
| All Files | 100.0% | 1 |
| By block | 100.0% | 1 |
| By string | 100.0% | 1 |
| By array | 100.0% | 1 |
And I should see the source files:
| name | coverage |
| lib/faked_project/meta_magic.rb | 100.00 % |
simplecov-0.22.0/features/rspec_groups_using_filter_class.feature 0000664 0000000 0000000 00000003227 14351411403 0025441 0 ustar 00root root 0000000 0000000 @rspec
Feature: Grouping on RSpec using a custom filter class
Next to passing a block or a string to define a group, you can also pass
a filter class. The filter class inherits from SimpleCov::Filter and
must implement the matches? method, which is used to determine whether
or not a file should be added to the group.
Background:
Given I'm working on the project "faked_project"
Scenario:
Given SimpleCov for RSpec is configured with:
"""
require 'simplecov'
class CoverageFilter < SimpleCov::Filter
def matches?(source_file)
source_file.covered_percent < filter_argument
end
end
SimpleCov.start do
add_group 'By filter class', CoverageFilter.new(90)
add_group 'By string', 'project/meta_magic'
end
"""
When I open the coverage report generated with `bundle exec rspec spec`
Then I should see the groups:
| name | coverage | files |
| All Files | 91.8% | 7 |
| By filter class | 78.26% | 2 |
| By string | 100.0% | 1 |
| Ungrouped | 100.0% | 4 |
And I should see the source files:
| name | coverage |
| lib/faked_project/framework_specific.rb | 75.00 % |
| lib/faked_project/some_class.rb | 80.00 % |
| lib/faked_project.rb | 100.00 % |
| lib/faked_project/meta_magic.rb | 100.00 % |
| spec/forking_spec.rb | 100.00 % |
| spec/meta_magic_spec.rb | 100.00 % |
| spec/some_class_spec.rb | 100.00 % |
simplecov-0.22.0/features/rspec_rails.feature 0000664 0000000 0000000 00000001474 14351411403 0021277 0 ustar 00root root 0000000 0000000 @rspec @disable-bundler @rails6
Feature:
Make sure that a fairly standard rspec-rails setup within a rails
application works.
See #873 for an example of how this might break.
Background:
Given I'm working on the project "rails/rspec_rails"
Scenario: Running bundle exec rspec produces a coverage report
Given I install dependencies
When I open the coverage report generated with `bundle exec rspec`
Then I should see the groups:
| name | coverage | files |
| All Files | 36.36% | 5 |
| Controllers | 0.0% | 1 |
| Channels | 100.0% | 0 |
| Models | 50.0% | 2 |
| Mailers | 100.0% | 0 |
| Helpers | 100.0% | 1 |
| Jobs | 0.0% | 1 |
| Libraries | 100.0% | 0 |
simplecov-0.22.0/features/rspec_without_simplecov.feature 0000664 0000000 0000000 00000001114 14351411403 0023740 0 ustar 00root root 0000000 0000000 @rspec
Feature:
Running specs without simplecov configuration
Background:
Given I'm working on the project "faked_project"
Scenario: No config at all
When I successfully run `bundle exec rspec spec`
Then no coverage report should have been generated
Scenario: Configured, but not started
Given SimpleCov for RSpec is configured with:
"""
require 'simplecov'
SimpleCov.configure do
add_filter 'somefilter'
end
"""
When I successfully run `bundle exec rspec spec`
Then no coverage report should have been generated
simplecov-0.22.0/features/skipping_code_blocks_manually.feature 0000664 0000000 0000000 00000004325 14351411403 0025044 0 ustar 00root root 0000000 0000000 @test_unit @nocov
Feature:
When code is wrapped in :nocov: comment blocks, it does not count
against the coverage numbers.
Background:
Given I'm working on the project "faked_project"
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
SimpleCov.start 'test_frameworks'
"""
Scenario: Plain run with a nocov'd method
Given a file named "lib/faked_project/nocov.rb" with:
"""
class SourceCodeWithNocov
#:nocov:
def some_weird_code
never_reached
rescue => err
but no one cares about invalid ruby here
end
#:nocov:
end
"""
When I open the coverage report generated with `bundle exec rake test`
Then I should see the source files:
| name | coverage |
| lib/faked_project.rb | 100.00 % |
| lib/faked_project/some_class.rb | 80.00 % |
| lib/faked_project/framework_specific.rb | 75.00 % |
| lib/faked_project/meta_magic.rb | 100.00 % |
| lib/faked_project/nocov.rb | 100.00 % |
And there should be 7 skipped lines in the source files
And the report should be based upon:
| Unit Tests |
Scenario: Number of spaces should not mix up nocov results
Given a file named "lib/faked_project/nocov.rb" with:
"""
class SourceCodeWithNocov
# :nocov:
def some_weird_code
never_reached
rescue => err
but no one cares about invalid ruby here
end
# :nocov:
end
"""
When I open the coverage report generated with `bundle exec rake test`
Then the report should be based upon:
| Unit Tests |
And there should be 7 skipped lines in the source files
And I should see the source files:
| name | coverage |
| lib/faked_project.rb | 100.00 % |
| lib/faked_project/some_class.rb | 80.00 % |
| lib/faked_project/framework_specific.rb | 75.00 % |
| lib/faked_project/meta_magic.rb | 100.00 % |
| lib/faked_project/nocov.rb | 100.00 % |
simplecov-0.22.0/features/step_definitions/ 0000775 0000000 0000000 00000000000 14351411403 0020754 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/features/step_definitions/html_steps.rb 0000664 0000000 0000000 00000005005 14351411403 0023463 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
Then /^I should see the groups:$/ do |table|
expected_groups = table.hashes
# Given group names should be the same number than those rendered in report
expect(page).to have_css("#content .file_list_container", count: expected_groups.count)
# Verify each of the expected groups has a file list container and corresponding title and coverage number
# as well as the correct number of links to files.
expected_groups.each do |group|
with_scope "#content ##{group['name'].gsub(/[^a-z]/i, '')}.file_list_container" do
file_count_in_group = page.all("a.src_link").count
expect(file_count_in_group).to eq(group["files"].to_i)
with_scope "h2" do
expect(page).to have_content(group["name"])
expect(page).to have_content(group["coverage"])
end
end
end
end
Then /^I should see the source files:$/ do |table|
expected_files = table.hashes
available_source_files = all(".t-file", visible: true, count: expected_files.count)
include_branch_coverage = table.column_names.include?("branch coverage")
# Find all filenames and their coverage present in coverage report
files = available_source_files.map do |file_row|
coverage_data =
{
"name" => file_row.find(".t-file__name").text,
"coverage" => file_row.find(".t-file__coverage").text
}
coverage_data["branch coverage"] = file_row.find(".t-file__branch-coverage").text if include_branch_coverage
coverage_data
end
expect(files.sort_by { |coverage_data| coverage_data["name"] }).to eq(expected_files.sort_by { |coverage_data| coverage_data["name"] })
end
Then /^there should be (\d+) skipped lines in the source files$/ do |expected_count|
expect(all(".source_table ol li.skipped").count).to eq(expected_count.to_i)
end
Then /^I should see a (.+) coverage summary of (\d+)\/(\d+)( for the file)?$/ do |coverage_type, hit, total, for_file|
missed = total - hit
extra_class = for_file ? ".source_table" : ""
summary_text = find("#{extra_class} .t-#{coverage_type}-summary", visible: true).text
expect(summary_text).to match /#{total} .+ #{hit} .+ #{missed} /
end
When /^I open the detailed view for "(.+)"$/ do |file_path|
click_link(file_path, class: "src_link", title: file_path)
expect(page).to have_css(".header h3", visible: true, text: file_path)
end
When "I close the detailed view" do
click_button "cboxClose"
end
Then /^I should see coverage branch data like "(.+)"$/ do |text|
expect(find(".hits", visible: true, text: text)).to be_truthy
end
simplecov-0.22.0/features/step_definitions/json_steps.rb 0000664 0000000 0000000 00000001170 14351411403 0023467 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
Then /^the JSON coverage report should match the output for the basic case$/ do
cd(".") do
json_report = JSON.parse(File.read("coverage/coverage.json"))
coverage_hash = json_report.fetch "coverage"
directory = Dir.pwd
expect(coverage_hash.fetch("#{directory}/lib/faked_project.rb")).to eq "lines" => [nil, nil, 1, 1, 1, nil, nil, nil, 5, 3, nil, nil, 1]
expect(coverage_hash.fetch("#{directory}/lib/faked_project/some_class.rb")).to eq "lines" => [nil, nil, 1, 1, 1, nil, 1, 2, nil, nil, 1, 1, nil, nil, 1, 1, 1, nil, 0, nil, nil, 0, nil, nil, 1, nil, 1, 0, nil, nil]
end
end
simplecov-0.22.0/features/step_definitions/old_coverage_json_steps.rb 0000664 0000000 0000000 00000001411 14351411403 0026176 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
RESULTSET_JSON_PATH = "coverage/.resultset.json"
PATH_PLACE_HOLDER = "$$path"
COMMAND_NAME = "RSpec Different Name to avoid overriding"
Given "the paths in the old .resultset.json are adjusted to the current environment" do
in_current_directory do
resultset_json_content = File.read(RESULTSET_JSON_PATH)
File.write(RESULTSET_JSON_PATH, resultset_json_content.gsub(PATH_PLACE_HOLDER, Dir.pwd))
end
end
Given "the timestamp in the .resultset.json is current" do
in_current_directory do
resultset_json = File.read(RESULTSET_JSON_PATH)
resultset_hash = JSON.parse(resultset_json)
resultset_hash[COMMAND_NAME]["timestamp"] = Time.now.to_i
File.write(RESULTSET_JSON_PATH, JSON.pretty_generate(resultset_hash))
end
end
simplecov-0.22.0/features/step_definitions/parallel_tests_steps.rb 0000664 0000000 0000000 00000003052 14351411403 0025535 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
Then "I should see the line coverage results for the parallel tests project" do
steps %(
Then I should see the groups:
| name | coverage | files |
| All Files | 89.36% | 9 |
And I should see the source files:
| name | coverage |
| lib/all.rb | 100.00 % |
| spec/a_spec.rb | 100.00 % |
| spec/b_spec.rb | 100.00 % |
| spec/c_spec.rb | 100.00 % |
| spec/d_spec.rb | 100.00 % |
| lib/a.rb | 85.71 % |
| lib/b.rb | 80.00 % |
| lib/c.rb | 75.00 % |
| lib/d.rb | 71.43 % |
)
end
Then "I should see the branch coverage results for the parallel tests project" do
steps %(
Then I should see the groups:
| name | coverage | files |
| All Files | 89.36% | 9 |
And I should see a line coverage summary of 42/47
And I should see a branch coverage summary of 4/8
And I should see the source files:
| name | coverage | branch coverage |
| lib/all.rb | 100.00 % | 100.00 % |
| spec/a_spec.rb | 100.00 % | 100.00 % |
| spec/b_spec.rb | 100.00 % | 100.00 % |
| spec/c_spec.rb | 100.00 % | 100.00 % |
| spec/d_spec.rb | 100.00 % | 100.00 % |
| lib/a.rb | 85.71 % | 50.00 % |
| lib/b.rb | 80.00 % | 100.00 % |
| lib/c.rb | 75.00 % | 50.00 % |
| lib/d.rb | 71.43 % | 50.00 % |
)
end
simplecov-0.22.0/features/step_definitions/parameter_types.rb 0000664 0000000 0000000 00000001171 14351411403 0024505 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
#
# Enforce the alphabetical execution of specs because rspec 2+ executes them
# randomly with `rspec spec` while we need them in an accurate order for coverage
# reports that include the spec files.
#
# This is due to the fact that coverage will not include the first loaded spec/test file.
# To get predictable coverage results, we need to know which one that is...
ParameterType(
name: "rspec",
regexp: /bundle exec rspec spec/,
transformer: lambda { |_|
files = nil # Avoid shadowing
cd(".") { files = Dir["spec/**/*_spec.rb"] }
"bundle exec rspec #{files.sort.join(' ')}"
}
)
simplecov-0.22.0/features/step_definitions/simplecov_steps.rb 0000664 0000000 0000000 00000006166 14351411403 0024531 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
# Just a shortcut to make framework setup more readable
# The test project is using separate config files to avoid specifying all of
# test/spec_helper in the features every time.
Given /^SimpleCov for (.*) is configured with:$/ do |framework, config_body|
framework_dir =
case framework
when /RSpec/i
"spec"
when /Test\/Unit/i
"test"
when /Cucumber/i
"features/support"
when /Minitest/i
"minitest"
else
raise ArgumentError, "Could not identify test framework #{framework}!"
end
steps %(
Given a file named "#{framework_dir}/simplecov_config.rb" with:
"""
#{config_body}
"""
)
end
When /^I open the coverage report generated with `([^`]+)`$/ do |command|
steps %(
When I successfully run `#{command}`
Then a coverage report should have been generated
When I open the coverage report
)
end
Then /^a coverage report should have been generated(?: in "([^"]*)")?$/ do |coverage_dir|
coverage_dir ||= "coverage"
steps %(
Then the output should contain "Coverage report generated"
And a directory named "#{coverage_dir}" should exist
And the following files should exist:
| #{coverage_dir}/index.html |
| #{coverage_dir}/.resultset.json |
)
end
Then /^a JSON coverage report should have been generated(?: in "([^"]*)")?$/ do |coverage_dir|
coverage_dir ||= "coverage"
steps %(
Then the output should contain "Coverage report generated"
And a directory named "#{coverage_dir}" should exist
And the following files should exist:
| #{coverage_dir}/coverage.json |
)
end
Then /^no coverage report should have been generated(?: in "([^"]*)")?$/ do |coverage_dir|
coverage_dir ||= "coverage"
steps %(
Then the output should not contain "Coverage report generated"
And a directory named "#{coverage_dir}" should not exist
And the following files should not exist:
| #{coverage_dir}/index.html |
| #{coverage_dir}/.resultset.json |
)
end
Then /^the report should be based upon:$/ do |table|
frameworks = table.raw.flatten
steps %(
Then the output should contain "Coverage report generated for #{frameworks.join(', ')}"
And I should see "using #{frameworks.join(', ')}" within "#footer"
)
end
# This is necessary to ensure timing-dependant tests like the merge timeout
# do not fail on powerful machines.
When /^I wait for (\d+) seconds$/ do |seconds|
sleep seconds.to_i
end
Then "the overlay should be open" do
expect(page).to have_css("#cboxContent")
end
When "I install dependencies" do
# bundle may take its time
steps %(
When I successfully run `bundle` for up to 120 seconds
)
end
When "I pry" do
require "pry"
# rubocop:disable Lint/Debugger
binding.pry
# rubocop:enable Lint/Debugger
end
Given "I'm working on the project {string}" do |project_name|
this_dir = File.dirname(__FILE__)
# Clean up and create blank state for project
cd(".") do
FileUtils.rm_rf "project"
FileUtils.cp_r File.join(this_dir, "../../test_projects/#{project_name}/"), "project"
end
step 'I cd to "project"'
end
simplecov-0.22.0/features/step_definitions/web_steps.rb 0000664 0000000 0000000 00000003433 14351411403 0023277 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
module WithinHelpers
def with_scope(locator)
locator ? within(locator) { yield } : yield
end
end
World(WithinHelpers)
When /^I open the coverage report$/ do
visit "/"
end
Given /^(?:|I )am on (.+)$/ do |path|
visit path
end
When /^(?:|I )go to (.+)$/ do |path|
visit path
end
When /^(?:|I )press "([^"]*)"(?: within "([^"]*)")?$/ do |button, selector|
with_scope(selector) do
click_button(button)
end
end
When /^(?:|I )follow "([^"]*)"(?: within "([^"]*)")?$/ do |link, selector|
with_scope(selector) do
click_link(link)
end
end
Then /^(?:|I )should see "([^"]*)"(?: within "([^"]*)")?$/ do |text, selector|
with_scope(selector) do
expect(page).to have_content(text)
end
end
Then /^(?:|I )should see \/([^\/]*)\/(?: within "([^"]*)")?$/ do |regexp, selector|
regexp = Regexp.new(regexp)
with_scope(selector) do
expect(page).to have_xpath("//*", text: regexp)
end
end
Then /^(?:|I )should not see "([^"]*)"(?: within "([^"]*)")?$/ do |text, selector|
with_scope(selector) do
expect(page).to have_no_content(text)
end
end
Then /^(?:|I )should not see \/([^\/]*)\/(?: within "([^"]*)")?$/ do |regexp, selector|
regexp = Regexp.new(regexp)
with_scope(selector) do
expect(page).to have_no_xpath("//*", text: regexp)
end
end
# the default in our settings is still to check unvisible content
# as well and until we change that these steps similar to "should (not)
# see" are necessary
Then "{string} should be visible" do |text|
expect(page).to have_content(:visible, text)
end
Then "{string} should not be visible" do |text|
expect(page).to have_no_content(:visible, text)
end
Then /^show me the page$/ do
save_and_open_page # rubocop:disable Lint/Debugger
end
Then /^print the page$/ do
puts page.body
end
simplecov-0.22.0/features/support/ 0000775 0000000 0000000 00000000000 14351411403 0017122 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/features/support/env.rb 0000664 0000000 0000000 00000002572 14351411403 0020245 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
# While you're here, handy tip for debugging: try to attach @announce-output
# @announce-command to the scenarios/features to see what's going on
require "bundler"
Bundler.setup
require "aruba/cucumber"
require "aruba/config/jruby" if RUBY_ENGINE == "jruby"
require "capybara/cucumber"
require "capybara/apparition"
require "simplecov"
# Rack app for Capybara which returns the latest coverage report from Aruba temp project dir
coverage_dir = File.expand_path("../../tmp/aruba/project/coverage/", __dir__)
Capybara.app = Rack::Builder.new do
use Rack::Static, urls: {"/" => "index.html"}, root: coverage_dir
run Rack::Directory.new(coverage_dir)
end.to_app
Capybara.configure do |config|
config.ignore_hidden_elements = false
config.server = :webrick
config.default_driver = :apparition
end
Before("@branch_coverage") do
skip_this_scenario unless SimpleCov.branch_coverage_supported?
end
Before("@rails6") do
# Rails 6 only supports Ruby 2.5+
skip_this_scenario if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("2.5")
end
Before("@process_fork") do
# Process.fork is NotImplementedError in jruby
skip_this_scenario if defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby"
end
Aruba.configure do |config|
config.allow_absolute_paths = true
# JRuby needs a bit longer to get going
config.exit_timeout = RUBY_ENGINE == "jruby" ? 60 : 20
end
simplecov-0.22.0/features/test_unit_basic.feature 0000664 0000000 0000000 00000005431 14351411403 0022145 0 ustar 00root root 0000000 0000000 @test_unit
Feature:
Simply adding the basic simplecov lines to a project should get
the user a coverage report after running `rake test`
Background:
Given I'm working on the project "faked_project"
Scenario:
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
SimpleCov.start
"""
When I open the coverage report generated with `bundle exec rake test`
Then I should see the groups:
| name | coverage | files |
| All Files | 91.38% | 6 |
And I should see the source files:
| name | coverage |
| lib/faked_project.rb | 100.00 % |
| lib/faked_project/some_class.rb | 80.00 % |
| lib/faked_project/framework_specific.rb | 75.00 % |
| lib/faked_project/meta_magic.rb | 100.00 % |
| test/meta_magic_test.rb | 100.00 % |
| test/some_class_test.rb | 100.00 % |
# Note: faked_test.rb is not appearing here since that's the first unit test file
# loaded by Rake, and only there test_helper is required, which then loads simplecov
# and triggers tracking of all other loaded files! Solution for this would be to
# configure simplecov in this first test instead of test_helper.
And the report should be based upon:
| Unit Tests |
Scenario:
Given SimpleCov for Test/Unit is configured with:
"""
ENV['CC_TEST_REPORTER_ID'] = "9719ac886877886b7e325d1e828373114f633683e429107d1221d25270baeabf"
require 'simplecov'
SimpleCov.start
"""
When I open the coverage report generated with `bundle exec rake test`
Then I should see the groups:
| name | coverage | files |
| All Files | 91.38% | 6 |
And I should see the source files:
| name | coverage |
| lib/faked_project.rb | 100.00 % |
| lib/faked_project/some_class.rb | 80.00 % |
| lib/faked_project/framework_specific.rb | 75.00 % |
| lib/faked_project/meta_magic.rb | 100.00 % |
| test/meta_magic_test.rb | 100.00 % |
| test/some_class_test.rb | 100.00 % |
# Note: faked_test.rb is not appearing here since that's the first unit test file
# loaded by Rake, and only there test_helper is required, which then loads simplecov
# and triggers tracking of all other loaded files! Solution for this would be to
# configure simplecov in this first test instead of test_helper.
And the report should be based upon:
| Unit Tests |
And a JSON coverage report should have been generated
And the JSON coverage report should match the output for the basic case
simplecov-0.22.0/features/test_unit_collate.feature 0000664 0000000 0000000 00000003457 14351411403 0022515 0 ustar 00root root 0000000 0000000 @test_unit
Feature:
Using SimpleCov.collate should get the user a coverage report
Background:
Given I'm working on the project "faked_project"
Scenario:
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
SimpleCov.start
"""
When I successfully run `bundle exec rake part1`
Then a coverage report should have been generated
When I successfully run `mv coverage/.resultset.json coverage/resultset1.json`
And I successfully run `rm coverage/index.html`
When I successfully run `bundle exec rake part2`
Then a coverage report should have been generated
When I successfully run `mv coverage/.resultset.json coverage/resultset2.json`
And I successfully run `rm coverage/index.html`
When I open the coverage report generated with `bundle exec rake collate`
Then I should see the groups:
| name | coverage | files |
| All Files | 91.38% | 6 |
And I should see the source files:
| name | coverage |
| lib/faked_project.rb | 100.00 % |
| lib/faked_project/some_class.rb | 80.00 % |
| lib/faked_project/framework_specific.rb | 75.00 % |
| lib/faked_project/meta_magic.rb | 100.00 % |
| test/meta_magic_test.rb | 100.00 % |
| test/some_class_test.rb | 100.00 % |
# Note: faked_test.rb is not appearing here since that's the first unit test file
# loaded by Rake, and only there test_helper is required, which then loads simplecov
# and triggers tracking of all other loaded files! Solution for this would be to
# configure simplecov in this first test instead of test_helper.
And the report should be based upon:
| Unit Tests |
simplecov-0.22.0/features/test_unit_groups_and_filters_basic.feature 0000664 0000000 0000000 00000002041 14351411403 0026110 0 ustar 00root root 0000000 0000000 @test_unit
Feature:
Defining some groups and filters should give a corresponding
coverage report that respects those settings after running tests
Background:
Given I'm working on the project "faked_project"
Scenario:
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
SimpleCov.start do
add_group 'Libs', 'lib/faked_project/'
add_filter '/test/'
end
"""
When I open the coverage report generated with `bundle exec rake test`
Then I should see the groups:
| name | coverage | files |
| All Files | 88.1% | 4 |
| Libs | 86.11% | 3 |
| Ungrouped | 100.0% | 1 |
And I should see the source files:
| name | coverage |
| lib/faked_project.rb | 100.00 % |
| lib/faked_project/some_class.rb | 80.00 % |
| lib/faked_project/framework_specific.rb | 75.00 % |
| lib/faked_project/meta_magic.rb | 100.00 % |
simplecov-0.22.0/features/test_unit_groups_and_filters_complex.feature 0000664 0000000 0000000 00000002511 14351411403 0026500 0 ustar 00root root 0000000 0000000 @test_unit
Feature: Sophisticated grouping and filtering on Test/Unit
Defining groups and filters can be done by passing blocks or strings.
Blocks get each SimpleCov::SourceFile instance passed an can use arbitrary
and potentially weird conditions to remove files from the report or add them
to specific groups.
Background:
Given I'm working on the project "faked_project"
Scenario:
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
SimpleCov.start do
add_group 'By block' do |src_file|
src_file.filename =~ /MaGiC/i
end
add_group 'By string', 'project/meta_magic'
add_filter 'faked_project.rb'
# Remove all files that include "describe" in their source
add_filter {|src_file| src_file.lines.any? {|line| line.src =~ /TestCase/ } }
add_filter {|src_file| src_file.covered_percent < 100 }
end
"""
When I open the coverage report generated with `bundle exec rake test`
Then I should see the groups:
| name | coverage | files |
| All Files | 100.0% | 1 |
| By block | 100.0% | 1 |
| By string | 100.0% | 1 |
And I should see the source files:
| name | coverage |
| lib/faked_project/meta_magic.rb | 100.00 % |
simplecov-0.22.0/features/test_unit_groups_using_filter_class.feature 0000664 0000000 0000000 00000003144 14351411403 0026341 0 ustar 00root root 0000000 0000000 @test_unit
Feature: Grouping on Test/Unit using a custom filter class
Next to passing a block or a string to define a group, you can also pass
a filter class. The filter class inherits from SimpleCov::Filter and
must implement the matches? method, which is used to determine whether
or not a file should be added to the group.
Background:
Given I'm working on the project "faked_project"
Scenario:
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
class CoverageFilter < SimpleCov::Filter
def matches?(source_file)
source_file.covered_percent < filter_argument
end
end
SimpleCov.start do
add_group 'By filter class', CoverageFilter.new(90)
add_group 'By string', 'project/meta_magic'
end
"""
When I open the coverage report generated with `bundle exec rake test`
Then I should see the groups:
| name | coverage | files |
| All Files | 91.38% | 6 |
| By filter class | 78.26% | 2 |
| By string | 100.0% | 1 |
| Ungrouped | 100.0% | 3 |
And I should see the source files:
| name | coverage |
| lib/faked_project/framework_specific.rb | 75.00 % |
| lib/faked_project/some_class.rb | 80.00 % |
| lib/faked_project.rb | 100.00 % |
| lib/faked_project/meta_magic.rb | 100.00 % |
| test/meta_magic_test.rb | 100.00 % |
| test/some_class_test.rb | 100.00 % |
simplecov-0.22.0/features/test_unit_without_simplecov.feature 0000664 0000000 0000000 00000001127 14351411403 0024646 0 ustar 00root root 0000000 0000000 @test_unit
Feature:
Running unit tests without simplecov configuration
Background:
Given I'm working on the project "faked_project"
Scenario: No config at all
When I successfully run `bundle exec rake test`
Then no coverage report should have been generated
Scenario: Configured, but not started
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
SimpleCov.configure do
add_filter 'somefilter'
end
"""
When I successfully run `bundle exec rake test`
Then no coverage report should have been generated
simplecov-0.22.0/features/unicode_compatiblity.feature 0000664 0000000 0000000 00000004216 14351411403 0023174 0 ustar 00root root 0000000 0000000 @test_unit @unicode
Feature:
Files with unicode in their source should be no problem at all for
generating a proper coverage report.
Background:
Given I'm working on the project "faked_project"
Given SimpleCov for Test/Unit is configured with:
"""
require 'simplecov'
SimpleCov.start 'test_frameworks'
"""
Scenario: Snowman inside method string
Given a file named "lib/faked_project/unicode.rb" with:
"""
# encoding: UTF-8
class SourceCodeWithUnicode
def self.yell!
puts "☃"
end
end
"""
When I open the coverage report generated with `bundle exec rake test`
Then I should see the groups:
| name | coverage | files |
| All Files | 86.67% | 5 |
And I should see the source files:
| name | coverage |
| lib/faked_project.rb | 100.00 % |
| lib/faked_project/some_class.rb | 80.00 % |
| lib/faked_project/framework_specific.rb | 75.00 % |
| lib/faked_project/meta_magic.rb | 100.00 % |
| lib/faked_project/unicode.rb | 66.67 % |
And the report should be based upon:
| Unit Tests |
Scenario: Author name in comment
Given a file named "lib/faked_project/unicode.rb" with:
"""
# encoding: UTF-8
# author: Javiér Hernández
class SomeClassWrittenByAForeigner
def self.yell!
foo
end
end
"""
When I open the coverage report generated with `bundle exec rake test`
Then I should see the groups:
| name | coverage | files |
| All Files | 86.67% | 5 |
And I should see the source files:
| name | coverage |
| lib/faked_project.rb | 100.00 % |
| lib/faked_project/some_class.rb | 80.00 % |
| lib/faked_project/framework_specific.rb | 75.00 % |
| lib/faked_project/meta_magic.rb | 100.00 % |
| lib/faked_project/unicode.rb | 66.67 % |
And the report should be based upon:
| Unit Tests |
simplecov-0.22.0/features/warnings.feature 0000664 0000000 0000000 00000000703 14351411403 0020613 0 ustar 00root root 0000000 0000000 @rspec
Feature:
Running SimpleCov with verbosity enabled does not yield warnings.
Background:
Given I'm working on the project "faked_project"
Scenario:
Given SimpleCov for RSpec is configured with:
"""
require 'simplecov'
SimpleCov.start
"""
When I successfully run `bundle exec rspec --warnings spec`
Then a coverage report should have been generated
And the output should not contain "warning"
simplecov-0.22.0/lib/ 0000775 0000000 0000000 00000000000 14351411403 0014336 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/lib/minitest/ 0000775 0000000 0000000 00000000000 14351411403 0016172 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/lib/minitest/simplecov_plugin.rb 0000664 0000000 0000000 00000000633 14351411403 0022100 0 ustar 00root root 0000000 0000000 # 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
simplecov-0.22.0/lib/simplecov.rb 0000664 0000000 0000000 00000035163 14351411403 0016674 0 ustar 00root root 0000000 0000000 # 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_given?
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
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["TEST_ENV_NUMBER"] && ENV["PARALLEL_TEST_GROUPS"]
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"]
simplecov-0.22.0/lib/simplecov/ 0000775 0000000 0000000 00000000000 14351411403 0016337 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/lib/simplecov/combine.rb 0000664 0000000 0000000 00000001422 14351411403 0020277 0 ustar 00root root 0000000 0000000 # 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
simplecov-0.22.0/lib/simplecov/combine/ 0000775 0000000 0000000 00000000000 14351411403 0017753 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/lib/simplecov/combine/branches_combiner.rb 0000664 0000000 0000000 00000002252 14351411403 0023744 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
module SimpleCov
module Combine
#
# Combine different branch coverage results on single file.
#
# Should be called through `SimpleCov.combine`.
module BranchesCombiner
module_function
#
# Return merged branches or the existed brach if other is missing.
#
# Branches inside files are always same if they exist, the difference only in coverage count.
# Branch coverage report for any conditional case is built from hash, it's key is a condition and
# it's body is a hash << keys from condition and value is coverage rate >>.
# ex: branches =>{ [:if, 3, 8, 6, 8, 36] => {[:then, 4, 8, 6, 8, 12] => 1, [:else, 5, 8, 6, 8, 36]=>2}, other conditions...}
# We create copy of result and update it values depending on the combined branches coverage values.
#
# @return [Hash]
#
def combine(coverage_a, coverage_b)
coverage_a.merge(coverage_b) do |_condition, branches_inside_a, branches_inside_b|
branches_inside_a.merge(branches_inside_b) do |_branch, a_count, b_count|
a_count + b_count
end
end
end
end
end
end
simplecov-0.22.0/lib/simplecov/combine/files_combiner.rb 0000664 0000000 0000000 00000001250 14351411403 0023256 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
module SimpleCov
module Combine
#
# Handle combining two coverage results for same file
#
# Should be called through `SimpleCov.combine`.
module FilesCombiner
module_function
#
# Combines the results for 2 coverages of a file.
#
# @return [Hash]
#
def combine(coverage_a, coverage_b)
combination = {"lines" => Combine.combine(LinesCombiner, coverage_a["lines"], coverage_b["lines"])}
combination["branches"] = Combine.combine(BranchesCombiner, coverage_a["branches"], coverage_b["branches"]) if SimpleCov.branch_coverage?
combination
end
end
end
end
simplecov-0.22.0/lib/simplecov/combine/lines_combiner.rb 0000664 0000000 0000000 00000001757 14351411403 0023302 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
module SimpleCov
module Combine
#
# Combine two different lines coverage results on same file
#
# Should be called through `SimpleCov.combine`.
module LinesCombiner
module_function
def combine(coverage_a, coverage_b)
coverage_a
.zip(coverage_b)
.map do |coverage_a_val, coverage_b_val|
merge_line_coverage(coverage_a_val, coverage_b_val)
end
end
# Return depends on coverage in a specific line
#
# @param [Integer || nil] first_val
# @param [Integer || nil] second_val
#
# Logic:
#
# => nil + 0 = nil
# => nil + nil = nil
# => int + int = int
#
# @return [Integer || nil]
def merge_line_coverage(first_val, second_val)
sum = first_val.to_i + second_val.to_i
if sum.zero? && (first_val.nil? || second_val.nil?)
nil
else
sum
end
end
end
end
end
simplecov-0.22.0/lib/simplecov/combine/results_combiner.rb 0000664 0000000 0000000 00000003434 14351411403 0023663 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
module SimpleCov
module Combine
# There might be reports from different kinds of tests,
# e.g. RSpec and Cucumber. We need to combine their results
# into unified one. This class does that.
# To unite the results on file basis, it leverages
# the combine of lines and branches inside each file within given results.
module ResultsCombiner
module_function
#
# Combine process explanation
# => ResultCombiner: define all present files between results and start combine on file level.
# ==> FileCombiner: collect result of next combine levels lines and branches.
# ===> LinesCombiner: combine lines results.
# ===> BranchesCombiner: combine branches results.
#
# @return [Hash]
#
def combine(*results)
results.reduce({}) do |combined_results, next_result|
combine_result_sets(combined_results, next_result)
end
end
#
# Manage combining results on files level
#
# @param [Hash] combined_results
# @param [Hash] result
#
# @return [Hash]
#
def combine_result_sets(combined_results, result)
results_files = combined_results.keys | result.keys
results_files.each_with_object({}) do |file_name, file_combination|
file_combination[file_name] = combine_file_coverage(
combined_results[file_name],
result[file_name]
)
end
end
#
# Combine two files coverage results
#
# @param [Hash] coverage_a
# @param [Hash] coverage_b
#
# @return [Hash]
#
def combine_file_coverage(coverage_a, coverage_b)
Combine.combine(Combine::FilesCombiner, coverage_a, coverage_b)
end
end
end
end
simplecov-0.22.0/lib/simplecov/command_guesser.rb 0000664 0000000 0000000 00000004007 14351411403 0022040 0 ustar 00root root 0000000 0000000 # 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["TEST_ENV_NUMBER"]
number = "1" if number.empty?
"(#{number}/#{ENV['PARALLEL_TEST_GROUPS']})"
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
simplecov-0.22.0/lib/simplecov/configuration.rb 0000664 0000000 0000000 00000040003 14351411403 0021530 0 ustar 00root root 0000000 0000000 # 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_given?
@at_exit = block if block_given?
@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_given?
@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 sorce 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
simplecov-0.22.0/lib/simplecov/coverage_statistics.rb 0000664 0000000 0000000 00000003603 14351411403 0022733 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
module SimpleCov
# Holds the individual data of a coverage result.
#
# This is uniform across coverage criteria as they all have:
#
# * total - how many things to cover there are (total relevant loc/branches)
# * covered - how many of the coverables are hit
# * missed - how many of the coverables are missed
# * percent - percentage as covered/missed
# * strength - average hits per/coverable (will not exist for one shot lines format)
class CoverageStatistics
attr_reader :total, :covered, :missed, :strength, :percent
def self.from(coverage_statistics)
sum_covered, sum_missed, sum_total_strength =
coverage_statistics.reduce([0, 0, 0.0]) do |(covered, missed, total_strength), file_coverage_statistics|
[
covered + file_coverage_statistics.covered,
missed + file_coverage_statistics.missed,
# gotta remultiply with loc because files have different strength and loc
# giving them a different "weight" in total
total_strength + (file_coverage_statistics.strength * file_coverage_statistics.total)
]
end
new(covered: sum_covered, missed: sum_missed, total_strength: sum_total_strength)
end
# Requires only covered, missed and strength to be initialized.
#
# Other values are computed by this class.
def initialize(covered:, missed:, total_strength: 0.0)
@covered = covered
@missed = missed
@total = covered + missed
@percent = compute_percent(covered, missed, total)
@strength = compute_strength(total_strength, total)
end
private
def compute_percent(covered, missed, total)
return 100.0 if missed.zero?
covered * 100.0 / total
end
def compute_strength(total_strength, total)
return 0.0 if total.zero?
total_strength.to_f / total
end
end
end
simplecov-0.22.0/lib/simplecov/default_formatter.rb 0000664 0000000 0000000 00000000754 14351411403 0022401 0 ustar 00root root 0000000 0000000 # 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
simplecov-0.22.0/lib/simplecov/defaults.rb 0000664 0000000 0000000 00000002657 14351411403 0020505 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
# Load default formatter gem
require "pathname"
require_relative "default_formatter"
require_relative "profiles/root_filter"
require_relative "profiles/test_frameworks"
require_relative "profiles/bundler_filter"
require_relative "profiles/hidden_filter"
require_relative "profiles/rails"
# Default configuration
SimpleCov.configure do
formatter SimpleCov::Formatter::MultiFormatter.new(
SimpleCov::Formatter.from_env(ENV)
)
load_profile "bundler_filter"
load_profile "hidden_filter"
# Exclude files outside of SimpleCov.root
load_profile "root_filter"
end
# Gotta stash this a-s-a-p, see the CommandGuesser class and i.e. #110 for further info
SimpleCov::CommandGuesser.original_run_command = "#{$PROGRAM_NAME} #{ARGV.join(' ')}"
at_exit do
next if SimpleCov.external_at_exit?
SimpleCov.at_exit_behavior
end
# Autoload config from ~/.simplecov if present
require_relative "load_global_config"
# Autoload config from .simplecov if present
# Recurse upwards until we find .simplecov or reach the root directory
config_path = Pathname.new(SimpleCov.root)
loop do
filename = config_path.join(".simplecov")
if filename.exist?
begin
load filename
rescue LoadError, StandardError
warn "Warning: Error occurred while trying to load #{filename}. " \
"Error message: #{$!.message}"
end
break
end
config_path, = config_path.split
break if config_path.root?
end
simplecov-0.22.0/lib/simplecov/exit_codes.rb 0000664 0000000 0000000 00000000614 14351411403 0021013 0 ustar 00root root 0000000 0000000 # 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"
simplecov-0.22.0/lib/simplecov/exit_codes/ 0000775 0000000 0000000 00000000000 14351411403 0020465 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/lib/simplecov/exit_codes/exit_code_handling.rb 0000664 0000000 0000000 00000001430 14351411403 0024617 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
module SimpleCov
module ExitCodes
module ExitCodeHandling
module_function
def call(result, coverage_limits:)
checks = coverage_checks(result, coverage_limits)
failing_check = checks.find(&:failing?)
if failing_check
failing_check.report
failing_check.exit_code
else
SimpleCov::ExitCodes::SUCCESS
end
end
def coverage_checks(result, coverage_limits)
[
MinimumOverallCoverageCheck.new(result, coverage_limits.minimum_coverage),
MinimumCoverageByFileCheck.new(result, coverage_limits.minimum_coverage_by_file),
MaximumCoverageDropCheck.new(result, coverage_limits.maximum_coverage_drop)
]
end
end
end
end
simplecov-0.22.0/lib/simplecov/exit_codes/maximum_coverage_drop_check.rb 0000664 0000000 0000000 00000004474 14351411403 0026534 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
module SimpleCov
module ExitCodes
class MaximumCoverageDropCheck
def initialize(result, maximum_coverage_drop)
@result = result
@maximum_coverage_drop = maximum_coverage_drop
end
def failing?
return false unless maximum_coverage_drop && last_run
coverage_drop_violations.any?
end
def report
coverage_drop_violations.each do |violation|
$stderr.printf(
"%s coverage has dropped by %.2f%% since the last time (maximum allowed: %.2f%%).\n",
criterion: violation[:criterion].capitalize,
drop_percent: SimpleCov.round_coverage(violation[:drop_percent]),
max_drop: violation[:max_drop]
)
end
end
def exit_code
SimpleCov::ExitCodes::MAXIMUM_COVERAGE_DROP
end
private
attr_reader :result, :maximum_coverage_drop
def last_run
return @last_run if defined?(@last_run)
@last_run = SimpleCov::LastRun.read
end
def coverage_drop_violations
@coverage_drop_violations ||=
compute_coverage_drop_data.select do |achieved|
achieved.fetch(:max_drop) < achieved.fetch(:drop_percent)
end
end
def compute_coverage_drop_data
maximum_coverage_drop.map do |criterion, percent|
{
criterion: criterion,
max_drop: percent,
drop_percent: drop_percent(criterion)
}
end
end
# if anyone says "max_coverage_drop 0.000000000000000001" I appologize. Please don't.
MAX_DROP_ACCURACY = 10
def drop_percent(criterion)
drop = last_coverage(criterion) -
SimpleCov.round_coverage(
result.coverage_statistics.fetch(criterion).percent
)
# floats, I tell ya.
# irb(main):001:0* 80.01 - 80.0
# => 0.010000000000005116
drop.floor(MAX_DROP_ACCURACY)
end
def last_coverage(criterion)
last_coverage_percent = last_run[:result][criterion]
# fallback for old file format
last_coverage_percent = last_run[:result][:covered_percent] if !last_coverage_percent && criterion == :line
last_coverage_percent || 0
end
end
end
end
simplecov-0.22.0/lib/simplecov/exit_codes/minimum_coverage_by_file_check.rb 0000664 0000000 0000000 00000003057 14351411403 0027173 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
module SimpleCov
module ExitCodes
class MinimumCoverageByFileCheck
def initialize(result, minimum_coverage_by_file)
@result = result
@minimum_coverage_by_file = minimum_coverage_by_file
end
def failing?
minimum_violations.any?
end
def report
minimum_violations.each do |violation|
$stderr.printf(
"%s coverage by file (%.2f%%) is below the expected minimum coverage (%.2f%%).\n",
covered: SimpleCov.round_coverage(violation.fetch(:actual)),
minimum_coverage: violation.fetch(:minimum_expected),
criterion: violation.fetch(:criterion).capitalize
)
end
end
def exit_code
SimpleCov::ExitCodes::MINIMUM_COVERAGE
end
private
attr_reader :result, :minimum_coverage_by_file
def minimum_violations
@minimum_violations ||=
compute_minimum_coverage_data.select do |achieved|
achieved.fetch(:actual) < achieved.fetch(:minimum_expected)
end
end
def compute_minimum_coverage_data
minimum_coverage_by_file.flat_map do |criterion, expected_percent|
result.coverage_statistics_by_file.fetch(criterion).map do |actual_coverage|
{
criterion: criterion,
minimum_expected: expected_percent,
actual: SimpleCov.round_coverage(actual_coverage.percent)
}
end
end
end
end
end
end
simplecov-0.22.0/lib/simplecov/exit_codes/minimum_overall_coverage_check.rb 0000664 0000000 0000000 00000002633 14351411403 0027225 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
module SimpleCov
module ExitCodes
class MinimumOverallCoverageCheck
def initialize(result, minimum_coverage)
@result = result
@minimum_coverage = minimum_coverage
end
def failing?
minimum_violations.any?
end
def report
minimum_violations.each do |violation|
$stderr.printf(
"%s coverage (%.2f%%) is below the expected minimum coverage (%.2f%%).\n",
covered: SimpleCov.round_coverage(violation.fetch(:actual)),
minimum_coverage: violation.fetch(:minimum_expected),
criterion: violation.fetch(:criterion).capitalize
)
end
end
def exit_code
SimpleCov::ExitCodes::MINIMUM_COVERAGE
end
private
attr_reader :result, :minimum_coverage
def minimum_violations
@minimum_violations ||= calculate_minimum_violations
end
def calculate_minimum_violations
coverage_achieved = minimum_coverage.map do |criterion, percent|
{
criterion: criterion,
minimum_expected: percent,
actual: result.coverage_statistics.fetch(criterion).percent
}
end
coverage_achieved.select do |achieved|
achieved.fetch(:actual) < achieved.fetch(:minimum_expected)
end
end
end
end
end
simplecov-0.22.0/lib/simplecov/file_list.rb 0000664 0000000 0000000 00000006716 14351411403 0020650 0 ustar 00root root 0000000 0000000 # 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
simplecov-0.22.0/lib/simplecov/filter.rb 0000664 0000000 0000000 00000005267 14351411403 0020163 0 ustar 00root root 0000000 0000000 # 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
simplecov-0.22.0/lib/simplecov/formatter.rb 0000664 0000000 0000000 00000000345 14351411403 0020671 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
module SimpleCov
# TODO: Documentation on how to build your own formatters
module Formatter
end
end
require_relative "formatter/simple_formatter"
require_relative "formatter/multi_formatter"
simplecov-0.22.0/lib/simplecov/formatter/ 0000775 0000000 0000000 00000000000 14351411403 0020342 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/lib/simplecov/formatter/multi_formatter.rb 0000664 0000000 0000000 00000001445 14351411403 0024110 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
module SimpleCov
module Formatter
class MultiFormatter
module InstanceMethods
def format(result)
formatters.map do |formatter|
formatter.new.format(result)
rescue StandardError => e
warn("Formatter #{formatter} failed with #{e.class}: #{e.message} (#{e.backtrace.first})")
nil
end
end
end
def self.new(formatters = nil)
Class.new do
define_method :formatters do
@formatters ||= Array(formatters)
end
include InstanceMethods
end
end
def self.[](*args)
warn "#{Kernel.caller.first}: [DEPRECATION] ::[] is deprecated. Use ::new instead."
new(Array(args))
end
end
end
end
simplecov-0.22.0/lib/simplecov/formatter/simple_formatter.rb 0000664 0000000 0000000 00000001166 14351411403 0024247 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
module SimpleCov
module Formatter
#
# A ridiculously simple formatter for SimpleCov results.
#
class SimpleFormatter
# Takes a SimpleCov::Result and generates a string out of it
def format(result)
output = +""
result.groups.each do |name, files|
output << "Group: #{name}\n"
output << "=" * 40
output << "\n"
files.each do |file|
output << "#{file.filename} (coverage: #{file.covered_percent.round(2)}%)\n"
end
output << "\n"
end
output
end
end
end
end
simplecov-0.22.0/lib/simplecov/last_run.rb 0000664 0000000 0000000 00000001054 14351411403 0020513 0 ustar 00root root 0000000 0000000 # 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
simplecov-0.22.0/lib/simplecov/lines_classifier.rb 0000664 0000000 0000000 00000002246 14351411403 0022206 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
module SimpleCov
# Classifies whether lines are relevant for code coverage analysis.
# Comments & whitespace lines, and :nocov: token blocks, are considered not relevant.
class LinesClassifier
RELEVANT = 0
NOT_RELEVANT = nil
WHITESPACE_LINE = /^\s*$/.freeze
COMMENT_LINE = /^\s*#/.freeze
WHITESPACE_OR_COMMENT_LINE = Regexp.union(WHITESPACE_LINE, COMMENT_LINE)
def self.no_cov_line
/^(\s*)#(\s*)(:#{SimpleCov.nocov_token}:)/o
end
def self.no_cov_line?(line)
no_cov_line.match?(line)
rescue ArgumentError
# E.g., line contains an invalid byte sequence in UTF-8
false
end
def self.whitespace_line?(line)
WHITESPACE_OR_COMMENT_LINE.match?(line)
rescue ArgumentError
# E.g., line contains an invalid byte sequence in UTF-8
false
end
def classify(lines)
skipping = false
lines.map do |line|
if self.class.no_cov_line?(line)
skipping = !skipping
NOT_RELEVANT
elsif skipping || self.class.whitespace_line?(line)
NOT_RELEVANT
else
RELEVANT
end
end
end
end
end
simplecov-0.22.0/lib/simplecov/load_global_config.rb 0000664 0000000 0000000 00000000461 14351411403 0022451 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
require "etc"
home_dir = (ENV["HOME"] && File.expand_path("~")) || Etc.getpwuid.dir || (ENV["USER"] && File.expand_path("~#{ENV['USER']}"))
if home_dir
global_config_path = File.join(home_dir, ".simplecov")
load global_config_path if File.exist?(global_config_path)
end
simplecov-0.22.0/lib/simplecov/no_defaults.rb 0000664 0000000 0000000 00000000161 14351411403 0021165 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
ENV["SIMPLECOV_NO_DEFAULTS"] = "yes, no defaults"
require_relative "../simplecov"
simplecov-0.22.0/lib/simplecov/process.rb 0000664 0000000 0000000 00000000655 14351411403 0020350 0 ustar 00root root 0000000 0000000 # 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)
block.call if block_given?
end
else
fork_without_simplecov(&block)
end
end
alias fork_without_simplecov fork
alias fork fork_with_simplecov
end
end
simplecov-0.22.0/lib/simplecov/profiles.rb 0000664 0000000 0000000 00000001614 14351411403 0020511 0 ustar 00root root 0000000 0000000 # 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
simplecov-0.22.0/lib/simplecov/profiles/ 0000775 0000000 0000000 00000000000 14351411403 0020162 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/lib/simplecov/profiles/bundler_filter.rb 0000664 0000000 0000000 00000000160 14351411403 0023504 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
SimpleCov.profiles.define "bundler_filter" do
add_filter "/vendor/bundle/"
end
simplecov-0.22.0/lib/simplecov/profiles/hidden_filter.rb 0000664 0000000 0000000 00000000150 14351411403 0023303 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
SimpleCov.profiles.define "hidden_filter" do
add_filter %r{^/\..*}
end
simplecov-0.22.0/lib/simplecov/profiles/rails.rb 0000664 0000000 0000000 00000000716 14351411403 0021625 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
SimpleCov.profiles.define "rails" do
load_profile "test_frameworks"
add_filter %r{^/config/}
add_filter %r{^/db/}
add_group "Controllers", "app/controllers"
add_group "Channels", "app/channels"
add_group "Models", "app/models"
add_group "Mailers", "app/mailers"
add_group "Helpers", "app/helpers"
add_group "Jobs", %w[app/jobs app/workers]
add_group "Libraries", "lib/"
track_files "{app,lib}/**/*.rb"
end
simplecov-0.22.0/lib/simplecov/profiles/root_filter.rb 0000664 0000000 0000000 00000000433 14351411403 0023037 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
SimpleCov.profiles.define "root_filter" do
# Exclude all files outside of simplecov root
root_filter = nil
add_filter do |src|
root_filter ||= /\A#{Regexp.escape(SimpleCov.root + File::SEPARATOR)}/io
src.filename !~ root_filter
end
end
simplecov-0.22.0/lib/simplecov/profiles/test_frameworks.rb 0000664 0000000 0000000 00000000262 14351411403 0023726 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
SimpleCov.profiles.define "test_frameworks" do
add_filter "/test/"
add_filter "/features/"
add_filter "/spec/"
add_filter "/autotest/"
end
simplecov-0.22.0/lib/simplecov/result.rb 0000664 0000000 0000000 00000006225 14351411403 0020207 0 ustar 00root root 0000000 0000000 # 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
Hash[keys.zip(original_result.values_at(*keys))]
end
# Applies all configured SimpleCov filters on this result's source files
def filter!
@files = SimpleCov.filtered(files)
end
end
end
simplecov-0.22.0/lib/simplecov/result_adapter.rb 0000664 0000000 0000000 00000001246 14351411403 0021705 0 ustar 00root root 0000000 0000000 # 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
simplecov-0.22.0/lib/simplecov/result_merger.rb 0000664 0000000 0000000 00000014463 14351411403 0021553 0 ustar 00root root 0000000 0000000 # 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
simplecov-0.22.0/lib/simplecov/simulate_coverage.rb 0000664 0000000 0000000 00000001271 14351411403 0022363 0 ustar 00root root 0000000 0000000 # 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
simplecov-0.22.0/lib/simplecov/source_file.rb 0000664 0000000 0000000 00000024655 14351411403 0021177 0 ustar 00root root 0000000 0000000 # 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.length.zero? || (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).select { |_type, count| count.zero? }.any?
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|
if line.encoding == Encoding::UTF_8
line
else
line.encode!("UTF-8", invalid: :replace, undef: :replace)
end
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
simplecov-0.22.0/lib/simplecov/source_file/ 0000775 0000000 0000000 00000000000 14351411403 0020636 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/lib/simplecov/source_file/branch.rb 0000664 0000000 0000000 00000003731 14351411403 0022424 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
module SimpleCov
class SourceFile
#
# Representing single branch that has been detected in coverage report.
# Give us support methods that handle needed calculations.
class Branch
attr_reader :start_line, :end_line, :coverage, :type
# rubocop:disable Metrics/ParameterLists
def initialize(start_line:, end_line:, coverage:, inline:, type:)
@start_line = start_line
@end_line = end_line
@coverage = coverage
@inline = inline
@type = type
@skipped = false
end
# rubocop:enable Metrics/ParameterLists
def inline?
@inline
end
#
# Return true if there is relevant count defined > 0
#
# @return [Boolean]
#
def covered?
!skipped? && coverage.positive?
end
#
# Check if branche missed or not
#
# @return [Boolean]
#
def missed?
!skipped? && coverage.zero?
end
# The line on which we want to report the coverage
#
# Usually we choose the line above the start of the branch (so that it shows up
# at if/else) because that
# * highlights the condition
# * makes it distinguishable if the first line of the branch is an inline branch
# (see the nested_branches fixture)
#
def report_line
if inline?
start_line
else
start_line - 1
end
end
# Flags the branch as skipped
def skipped!
@skipped = true
end
# Returns true if the branch was marked skipped by virtue of nocov comments.
def skipped?
@skipped
end
def overlaps_with?(line_range)
start_line <= line_range.end && end_line >= line_range.begin
end
#
# Return array with coverage count and badge
#
# @return [Array]
#
def report
[type, coverage]
end
end
end
end
simplecov-0.22.0/lib/simplecov/source_file/line.rb 0000664 0000000 0000000 00000004567 14351411403 0022126 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
module SimpleCov
class SourceFile
# Representation of a single line in a source file including
# this specific line's source code, line_number and code coverage,
# with the coverage being either nil (coverage not applicable, e.g. comment
# line), 0 (line not covered) or >1 (the amount of times the line was
# executed)
class Line
# The source code for this line. Aliased as :source
attr_reader :src
# The line number in the source file. Aliased as :line, :number
attr_reader :line_number
# The coverage data for this line: either nil (never), 0 (missed) or >=1 (times covered)
attr_reader :coverage
# Whether this line was skipped
attr_reader :skipped
# Lets grab some fancy aliases, shall we?
alias source src
alias line line_number
alias number line_number
def initialize(src, line_number, coverage)
raise ArgumentError, "Only String accepted for source" unless src.is_a?(String)
raise ArgumentError, "Only Integer accepted for line_number" unless line_number.is_a?(Integer)
raise ArgumentError, "Only Integer and nil accepted for coverage" unless coverage.is_a?(Integer) || coverage.nil?
@src = src
@line_number = line_number
@coverage = coverage
@skipped = false
end
# Returns true if this is a line that should have been covered, but was not
def missed?
!never? && !skipped? && coverage.zero?
end
# Returns true if this is a line that has been covered
def covered?
!never? && !skipped? && coverage.positive?
end
# Returns true if this line is not relevant for coverage
def never?
!skipped? && coverage.nil?
end
# Flags this line as skipped
def skipped!
@skipped = true
end
# Returns true if this line was skipped, false otherwise. Lines are skipped if they are wrapped with
# # :nocov: comment lines.
def skipped?
skipped
end
# The status of this line - either covered, missed, skipped or never. Useful i.e. for direct use
# as a css class in report generation
def status
return "skipped" if skipped?
return "never" if never?
return "missed" if missed?
return "covered" if covered?
end
end
end
end
simplecov-0.22.0/lib/simplecov/useless_results_remover.rb 0000664 0000000 0000000 00000000640 14351411403 0023667 0 ustar 00root root 0000000 0000000 # 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.freeze
end
end
end
simplecov-0.22.0/lib/simplecov/version.rb 0000664 0000000 0000000 00000000111 14351411403 0020342 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
module SimpleCov
VERSION = "0.22.0"
end
simplecov-0.22.0/simplecov.gemspec 0000664 0000000 0000000 00000003357 14351411403 0017146 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
$LOAD_PATH.push File.expand_path("lib", __dir__)
# Why oh why oh what is this?
# See the cuke that is setting this.
# Basically to really reproduce #877 we needed a gemspec that doesn't
# (indirectly) define a SimpleCov module... so this is the workaround.
version =
if ENV["SIMPLECOV_NO_REQUIRE_VERSION"]
ENV["SIMPLECOV_NO_REQUIRE_VERSION"]
else
require "simplecov/version"
SimpleCov::VERSION
end
Gem::Specification.new do |gem|
gem.name = "simplecov"
gem.version = version
gem.platform = Gem::Platform::RUBY
gem.authors = ["Christoph Olszowka", "Tobias Pfeiffer"]
gem.email = ["christoph at olszowka de", "pragtob@gmail.com"]
gem.homepage = "https://github.com/simplecov-ruby/simplecov"
gem.summary = "Code coverage for Ruby"
gem.description = %(Code coverage for Ruby with a powerful configuration library and automatic merging of coverage across test suites)
gem.license = "MIT"
gem.metadata = {
"bug_tracker_uri" => "https://github.com/simplecov-ruby/simplecov/issues",
"changelog_uri" => "https://github.com/simplecov-ruby/simplecov/blob/main/CHANGELOG.md",
"documentation_uri" => "https://www.rubydoc.info/gems/simplecov/#{gem.version}",
"mailing_list_uri" => "https://groups.google.com/forum/#!forum/simplecov",
"source_code_uri" => "https://github.com/simplecov-ruby/simplecov/tree/v#{gem.version}"
}
gem.required_ruby_version = ">= 2.5.0"
gem.add_dependency "docile", "~> 1.1"
gem.add_dependency "simplecov-html", "~> 0.11"
gem.add_dependency "simplecov_json_formatter", "~> 0.1"
gem.files = Dir["{lib}/**/*.*", "bin/*", "LICENSE", "CHANGELOG.md", "README.md", "doc/*"]
gem.require_paths = ["lib"]
end
simplecov-0.22.0/spec/ 0000775 0000000 0000000 00000000000 14351411403 0014522 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/spec/combine/ 0000775 0000000 0000000 00000000000 14351411403 0016136 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/spec/combine/results_combiner_spec.rb 0000664 0000000 0000000 00000012331 14351411403 0023054 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
require "helper"
describe SimpleCov::Combine::ResultsCombiner do
describe "with two faked coverage resultsets" do
let(:resultset1) do
{
source_fixture("sample.rb") => {
"lines" => [nil, 1, 1, 1, nil, nil, 1, 1, nil, nil],
"branches" => {[:if, 3, 8, 6, 8, 36] => {[:then, 4, 8, 6, 8, 12] => 47, [:else, 5, 8, 6, 8, 36] => 24}}
},
source_fixture("app/models/user.rb") => {
"lines" => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil],
"branches" => {[:if, 3, 8, 6, 8, 36] => {[:then, 4, 8, 6, 8, 12] => 47, [:else, 5, 8, 6, 8, 36] => 24}}
},
source_fixture("app/controllers/sample_controller.rb") => {"lines" => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil]},
source_fixture("resultset1.rb") => {"lines" => [1, 1, 1, 1]},
source_fixture("parallel_tests.rb") => {"lines" => [nil, 0, nil, 0]},
source_fixture("conditionally_loaded_1.rb") => {"lines" => [nil, 0, 1]}, # loaded only in the first resultset
source_fixture("three.rb") => {"lines" => [nil, 1, 1]}
}
end
let(:resultset2) do
{
source_fixture("sample.rb") => {"lines" => [1, nil, 1, 1, nil, nil, 1, 1, nil, nil]},
source_fixture("app/models/user.rb") => {
"lines" => [nil, 1, 5, 1, nil, nil, 1, 0, nil, nil],
"branches" => {[:if, 3, 8, 6, 8, 36] => {[:then, 4, 8, 6, 8, 12] => 1, [:else, 5, 8, 6, 8, 36] => 2}}
},
source_fixture("app/controllers/sample_controller.rb") => {"lines" => [nil, 3, 1, nil, nil, nil, 1, 0, nil, nil]},
source_fixture("resultset2.rb") => {"lines" => [nil, 1, 1, nil]},
source_fixture("parallel_tests.rb") => {"lines" => [nil, nil, 0, 0]},
source_fixture("conditionally_loaded_2.rb") => {"lines" => [nil, 0, 1]}, # loaded only in the second resultset
source_fixture("three.rb") => {"lines" => [nil, 1, 4]}
}
end
let(:resultset3) do
{source_fixture("three.rb") => {"lines" => [nil, 1, 2]}}
end
after do
SimpleCov.clear_coverage_criteria
end
before do
SimpleCov.enable_coverage :branch
end
context "a merge" do
subject do
SimpleCov::Combine::ResultsCombiner.combine(resultset1, resultset2, resultset3)
end
it "has proper results for sample.rb" do
expect(subject[source_fixture("sample.rb")]["lines"]).to eq([1, 1, 2, 2, nil, nil, 2, 2, nil, nil])
# gotta configure max line so it doesn't get ridiculous
# rubocop:disable Style/IfUnlessModifier
if SimpleCov.branch_coverage_supported?
expect(subject[source_fixture("sample.rb")]["branches"][[:if, 3, 8, 6, 8, 36]][[:then, 4, 8, 6, 8, 12]]).to eq(47)
end
# rubocop:enable Style/IfUnlessModifier
end
it "has proper results for user.rb" do
expect(subject[source_fixture("app/models/user.rb")]["lines"]).to eq([nil, 2, 6, 2, nil, nil, 2, 0, nil, nil])
if SimpleCov.branch_coverage_supported?
expect(subject[source_fixture("app/models/user.rb")]["branches"][[:if, 3, 8, 6, 8, 36]][[:then, 4, 8, 6, 8, 12]]).to eq(48)
expect(subject[source_fixture("app/models/user.rb")]["branches"][[:if, 3, 8, 6, 8, 36]][[:else, 5, 8, 6, 8, 36]]).to eq(26)
end
end
it "has proper results for sample_controller.rb" do
expect(subject[source_fixture("app/controllers/sample_controller.rb")]["lines"]).to eq([nil, 4, 2, 1, nil, nil, 2, 0, nil, nil])
end
it "has proper results for resultset1.rb" do
expect(subject[source_fixture("resultset1.rb")]["lines"]).to eq([1, 1, 1, 1])
end
it "has proper results for resultset2.rb" do
expect(subject[source_fixture("resultset2.rb")]["lines"]).to eq([nil, 1, 1, nil])
end
it "has proper results for parallel_tests.rb" do
expect(subject[source_fixture("parallel_tests.rb")]["lines"]).to eq([nil, nil, nil, 0])
end
it "has proper results for conditionally_loaded_1.rb" do
expect(subject[source_fixture("conditionally_loaded_1.rb")]["lines"]).to eq([nil, 0, 1])
end
it "has proper results for conditionally_loaded_2.rb" do
expect(subject[source_fixture("conditionally_loaded_2.rb")]["lines"]).to eq([nil, 0, 1])
end
it "has proper results for three.rb" do
expect(subject[source_fixture("three.rb")]["lines"]).to eq([nil, 3, 7])
end
end
end
it "merges frozen resultsets" do
resultset1 = {
source_fixture("sample.rb").freeze => {"lines" => [nil, 1, 1, 1, nil, nil, 1, 1, nil, nil]},
source_fixture("app/models/user.rb").freeze => {"lines" => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil]}
}
resultset2 = {
source_fixture("sample.rb").freeze => {"lines" => [1, nil, 1, 1, nil, nil, 1, 1, nil, nil]}
}
merged_result = SimpleCov::Combine::ResultsCombiner.combine(resultset1, resultset2)
expect(merged_result.keys).to eq(resultset1.keys)
expect(merged_result.values.map(&:frozen?)).to eq([false, false])
expect(merged_result[source_fixture("sample.rb")]["lines"]).to eq([1, 1, 2, 2, nil, nil, 2, 2, nil, nil])
expect(merged_result[source_fixture("app/models/user.rb")]["lines"]).to eq([nil, 1, 1, 1, nil, nil, 1, 0, nil, nil])
end
end
simplecov-0.22.0/spec/command_guesser_spec.rb 0000664 0000000 0000000 00000003633 14351411403 0021241 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
require "helper"
describe SimpleCov::CommandGuesser do
subject { SimpleCov::CommandGuesser }
it 'correctly guesses "Unit Tests" for unit tests' do
subject.original_run_command = "/some/path/test/units/foo_bar_test.rb"
expect(subject.guess).to eq("Unit Tests")
subject.original_run_command = "test/units/foo.rb"
expect(subject.guess).to eq("Unit Tests")
subject.original_run_command = "test/foo.rb"
expect(subject.guess).to eq("Unit Tests")
subject.original_run_command = "test/{models,helpers,unit}/**/*_test.rb"
expect(subject.guess).to eq("Unit Tests")
end
it 'correctly guesses "Functional Tests" for functional tests' do
subject.original_run_command = "/some/path/test/functional/foo_bar_controller_test.rb"
expect(subject.guess).to eq("Functional Tests")
subject.original_run_command = "test/{controllers,mailers,functional}/**/*_test.rb"
expect(subject.guess).to eq("Functional Tests")
end
it 'correctly guesses "Integration Tests" for integration tests' do
subject.original_run_command = "/some/path/test/integration/foo_bar_controller_test.rb"
expect(subject.guess).to eq("Integration Tests")
subject.original_run_command = "test/integration/**/*_test.rb"
expect(subject.guess).to eq("Integration Tests")
end
it 'correctly guesses "Cucumber Features" for cucumber features' do
subject.original_run_command = "features"
expect(subject.guess).to eq("Cucumber Features")
subject.original_run_command = "cucumber"
expect(subject.guess).to eq("Cucumber Features")
end
it 'correctly guesses "RSpec" for RSpec' do
subject.original_run_command = "/some/path/spec/foo.rb"
expect(subject.guess).to eq("RSpec")
end
it "defaults to RSpec because RSpec constant is defined" do
subject.original_run_command = "some_arbitrary_command with arguments"
expect(subject.guess).to eq("RSpec")
end
end
simplecov-0.22.0/spec/config_loader_spec.rb 0000664 0000000 0000000 00000000523 14351411403 0020654 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
require "helper"
describe "loading config" do
context "without ENV[HOME]" do
it "shouldn't raise any errors" do
home = ENV.delete("HOME")
begin
expect { load "simplecov/load_global_config.rb" }.not_to raise_error
ensure
ENV["HOME"] = home
end
end
end
end
simplecov-0.22.0/spec/configuration_spec.rb 0000664 0000000 0000000 00000020172 14351411403 0020732 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
require "helper"
describe SimpleCov::Configuration do
let(:config_class) do
Class.new do
include SimpleCov::Configuration
end
end
let(:config) { config_class.new }
describe "#print_error_status" do
subject { config.print_error_status }
context "when not manually set" do
it { is_expected.to be true }
end
context "when manually set" do
before { config.print_error_status = false }
it { is_expected.to be false }
end
end
describe "#tracked_files" do
context "when configured" do
let(:glob) { "{app,lib}/**/*.rb" }
before { config.track_files(glob) }
it "returns the configured glob" do
expect(config.tracked_files).to eq glob
end
context "and configured again with nil" do
before { config.track_files(nil) }
it "returns nil" do
expect(config.tracked_files).to be_nil
end
end
end
context "when unconfigured" do
it "returns nil" do
expect(config.tracked_files).to be_nil
end
end
shared_examples "setting coverage expectations" do |coverage_setting|
after :each do
config.clear_coverage_criteria
end
it "does not warn you about your usage" do
expect(config).not_to receive(:warn)
config.public_send(coverage_setting, 100.00)
end
it "warns you about your usage" do
expect(config).to receive(:warn).with("The coverage you set for #{coverage_setting} is greater than 100%")
config.public_send(coverage_setting, 100.01)
end
it "sets the right coverage value when called with a number" do
config.public_send(coverage_setting, 80)
expect(config.public_send(coverage_setting)).to eq line: 80
end
it "sets the right coverage when called with a hash of just line" do
config.public_send(coverage_setting, {line: 85.0})
expect(config.public_send(coverage_setting)).to eq line: 85.0
end
it "sets the right coverage when called with a hash of just branch" do
config.enable_coverage :branch
config.public_send(coverage_setting, {branch: 85.0})
expect(config.public_send(coverage_setting)).to eq branch: 85.0
end
it "sets the right coverage when called with both line and branch" do
config.enable_coverage :branch
config.public_send(coverage_setting, {branch: 85.0, line: 95.4})
expect(config.public_send(coverage_setting)).to eq branch: 85.0, line: 95.4
end
it "raises when trying to set branch coverage but not enabled" do
expect do
config.public_send(coverage_setting, {branch: 42})
end.to raise_error(/branch.*disabled/i)
end
it "raises when unknown coverage criteria provided" do
expect do
config.public_send(coverage_setting, {unknown: 42})
end.to raise_error(/unsupported.*unknown/i)
end
context "when primary coverage is set" do
before(:each) do
config.enable_coverage :branch
config.primary_coverage :branch
end
it "sets the right coverage value when called with a number" do
config.public_send(coverage_setting, 80)
expect(config.public_send(coverage_setting)).to eq branch: 80
end
end
end
describe "#minimum_coverage" do
it_behaves_like "setting coverage expectations", :minimum_coverage
end
describe "#minimum_coverage_by_file" do
it_behaves_like "setting coverage expectations", :minimum_coverage_by_file
end
describe "#maximum_coverage_drop" do
it_behaves_like "setting coverage expectations", :maximum_coverage_drop
end
describe "#refuse_coverage_drop" do
after :each do
config.clear_coverage_criteria
end
it "sets the right coverage value when called with `:line`" do
config.public_send(:refuse_coverage_drop, :line)
expect(config.public_send(:maximum_coverage_drop)).to eq line: 0
end
it "sets the right coverage value when called with `:branch`" do
config.enable_coverage :branch
config.public_send(:refuse_coverage_drop, :branch)
expect(config.public_send(:maximum_coverage_drop)).to eq branch: 0
end
it "sets the right coverage value when called with `:line` and `:branch`" do
config.enable_coverage :branch
config.public_send(:refuse_coverage_drop, :line, :branch)
expect(config.public_send(:maximum_coverage_drop)).to eq line: 0, branch: 0
end
it "sets the right coverage value when called with no args" do
config.public_send(:refuse_coverage_drop)
expect(config.public_send(:maximum_coverage_drop)).to eq line: 0
end
end
describe "#coverage_criterion" do
it "defaults to line" do
expect(config.coverage_criterion).to eq :line
end
it "works fine with line" do
config.coverage_criterion :line
expect(config.coverage_criterion).to eq :line
end
it "works fine with :branch" do
config.coverage_criterion :branch
expect(config.coverage_criterion).to eq :branch
end
it "works fine setting it back and forth" do
config.coverage_criterion :branch
config.coverage_criterion :line
expect(config.coverage_criterion).to eq :line
end
it "errors out on unknown coverage" do
expect do
config.coverage_criterion :unknown
end.to raise_error(/unsupported.*unknown.*line/i)
end
end
describe "#coverage_criteria" do
it "defaults to line" do
expect(config.coverage_criteria).to contain_exactly :line
end
end
describe "#enable_coverage" do
it "can enable branch coverage" do
config.enable_coverage :branch
expect(config.coverage_criteria).to contain_exactly :line, :branch
end
it "can enable line again" do
config.enable_coverage :line
expect(config.coverage_criteria).to contain_exactly :line
end
it "can't enable arbitrary things" do
expect do
config.enable_coverage :unknown
end.to raise_error(/unsupported.*unknown.*line/i)
end
end
describe "#branch_coverage?", if: SimpleCov.branch_coverage_supported? do
it "returns true of branch coverage is being measured" do
config.enable_coverage :branch
expect(config).to be_branch_coverage
end
it "returns false for line coverage" do
config.coverage_criterion :line
expect(config).not_to be_branch_coverage
end
end
describe "#enable_for_subprocesses" do
it "returns false by default" do
expect(config.enable_for_subprocesses).to eq false
end
it "can be set to true" do
config.enable_for_subprocesses true
expect(config.enable_for_subprocesses).to eq true
end
it "can be enabled and then disabled again" do
config.enable_for_subprocesses true
config.enable_for_subprocesses false
expect(config.enable_for_subprocesses).to eq false
end
end
describe "#primary_coverage" do
context "when branch coverage is enabled" do
before(:each) { config.enable_coverage :branch }
it "can set primary coverage to branch" do
config.primary_coverage :branch
expect(config.coverage_criteria).to contain_exactly :line, :branch
expect(config.primary_coverage).to eq :branch
end
end
context "when branch coverage is not enabled" do
it "cannot set primary coverage to branch " do
expect do
config.primary_coverage :branch
end.to raise_error(/branch.*disabled/i)
end
end
it "can set primary coverage to line" do
config.primary_coverage :line
expect(config.coverage_criteria).to contain_exactly :line
expect(config.primary_coverage).to eq :line
end
it "can't set primary coverage to arbitrary things" do
expect do
config.primary_coverage :unknown
end.to raise_error(/unsupported.*unknown.*line/i)
end
end
end
end
simplecov-0.22.0/spec/coverage_for_eval_spec.rb 0000664 0000000 0000000 00000001071 14351411403 0021530 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
require "helper"
RSpec.describe "coverage for eval" do
if SimpleCov.coverage_for_eval_supported?
around do |test|
Dir.chdir(File.join(File.dirname(__FILE__), "fixtures", "eval_test")) do
FileUtils.rm_rf("./coverage")
test.call
end
end
before do
@stdout, @stderr, @status = Open3.capture3(command)
end
context "foo" do
let(:command) { "ruby eval_test.rb" }
it "records coverage for erb" do
expect(@stdout).to include(" 2 / 3 LOC")
end
end
end
end
simplecov-0.22.0/spec/coverage_statistics_spec.rb 0000664 0000000 0000000 00000004321 14351411403 0022126 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
require "helper"
RSpec.describe SimpleCov::CoverageStatistics do
describe ".new" do
it "retains statistics and computes new ones" do
statistics = described_class.new(covered: 4, missed: 6, total_strength: 14)
expect(statistics.covered).to eq 4
expect(statistics.missed).to eq 6
expect(statistics.total).to eq 10
expect(statistics.percent).to eq 40.0
expect(statistics.strength).to eq 1.4
end
it "can omit the total strength defaulting to 0.0" do
statistics = described_class.new(covered: 4, missed: 6)
expect(statistics.strength).to eq 0.0
end
it "can deal with it if everything is 0" do
statistics = described_class.new(covered: 0, missed: 0, total_strength: 0.0)
expect_all_empty(statistics)
end
end
describe ".from" do
it "returns an all 0s coverage statistics if there are no statistics" do
statistics = described_class.from([])
expect_all_empty(statistics)
end
it "returns all empty statistics when initialized with a couple of empty results" do
statistics = described_class.from([empty_statistics, empty_statistics])
expect_all_empty(statistics)
end
it "produces sensible total results" do
statistics = described_class.from(
[
described_class.new(covered: 3, missed: 4, total_strength: 54),
described_class.new(covered: 0, missed: 13, total_strength: 0),
described_class.new(covered: 37, missed: 0, total_strength: 682)
]
)
expect(statistics.covered).to eq 40
expect(statistics.missed).to eq 17
expect(statistics.total).to eq 57
expect(statistics.percent).to be_within(0.01).of(70.18)
expect(statistics.strength).to be_within(0.01).of(12.91)
end
end
def empty_statistics
described_class.new(covered: 0, missed: 0, total_strength: 0.0)
end
def expect_all_empty(statistics)
expect(statistics.covered).to eq 0
expect(statistics.missed).to eq 0
expect(statistics.total).to eq 0
# might be counter-intuitive but think of it as "we covered everything we could"
expect(statistics.percent).to eq 100.0
expect(statistics.strength).to eq 0.0
end
end
simplecov-0.22.0/spec/default_formatter_spec.rb 0000664 0000000 0000000 00000002110 14351411403 0021562 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
require "helper"
require "simplecov_json_formatter"
describe SimpleCov::Formatter do
describe ".from_env" do
let(:env) { {"CC_TEST_REPORTER_ID" => "4c9f1de6193f30799e9a5d5c082692abecc1fd2c6aa62c621af7b2a910761970"} }
context "when CC_TEST_REPORTER_ID environment variable is set" do
it "returns an array containing the HTML and JSON formatters" do
expect(described_class.from_env(env)).to eq([
SimpleCov::Formatter::HTMLFormatter,
SimpleCov::Formatter::JSONFormatter
])
end
end
context "when CC_TEST_REPORTER_ID environment variable isn't set" do
let(:env) { {} }
it "returns an array containing only the HTML formatter" do
expect(described_class.from_env(env)).to eq([
SimpleCov::Formatter::HTMLFormatter
])
end
end
end
end
simplecov-0.22.0/spec/defaults_spec.rb 0000664 0000000 0000000 00000002262 14351411403 0017672 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
require "helper"
describe SimpleCov do
skip "requires the default configuration" if ENV["SIMPLECOV_NO_DEFAULTS"]
context "profiles" do
let(:config_class) do
Class.new do
include SimpleCov::Configuration
def load_profile(name)
configure(&SimpleCov.profiles[name.to_sym])
end
end
end
let(:config) { config_class.new }
def filtered?(config, filename)
path = File.join(SimpleCov.root, filename)
file = SimpleCov::SourceFile.new(path, [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil])
config.filters.any? { |filter| filter.matches?(file) }
end
it "provides a sensible test_frameworks profile" do
config.load_profile(:test_frameworks)
expect(filtered?(config, "foo.rb")).not_to be
expect(filtered?(config, "test/foo.rb")).to be
expect(filtered?(config, "spec/bar.rb")).to be
end
it "provides a sensible rails profile" do
config.load_profile(:rails)
expect(filtered?(config, "app/models/user.rb")).not_to be
expect(filtered?(config, "db/schema.rb")).to be
expect(filtered?(config, "config/environment.rb")).to be
end
end
end
simplecov-0.22.0/spec/deleted_source_spec.rb 0000664 0000000 0000000 00000000632 14351411403 0021050 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
require "helper"
# Test to verify correct handling of deleted files
# See https://github.com/simplecov-ruby/simplecov/issues/9
describe "A source file which is subsequently deleted" do
it "does not cause an error" do
Dir.chdir(File.join(File.dirname(__FILE__), "fixtures")) do
`ruby deleted_source_sample.rb`
expect($?.exitstatus).to be_zero
end
end
end
simplecov-0.22.0/spec/exit_codes/ 0000775 0000000 0000000 00000000000 14351411403 0016650 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/spec/exit_codes/maximum_coverage_drop_check_spec.rb 0000664 0000000 0000000 00000004426 14351411403 0025726 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
require "helper"
RSpec.describe SimpleCov::ExitCodes::MaximumCoverageDropCheck do
let(:result) do
instance_double(SimpleCov::Result, coverage_statistics: stats)
end
let(:stats) do
{
line: SimpleCov::CoverageStatistics.new(covered: 8, missed: 2),
branch: SimpleCov::CoverageStatistics.new(covered: 8, missed: 2)
}
end
let(:last_run) do
{
result: last_coverage
}
end
let(:last_coverage) { {line: 80.0, branch: 80.0} }
let(:maximum_coverage_drop) { {line: 0, branch: 0} }
subject { described_class.new(result, maximum_coverage_drop) }
before :each do
expect(SimpleCov::LastRun).to receive(:read).and_return(last_run)
end
context "we're at the same coverage" do
it { is_expected.not_to be_failing }
end
context "more coverage drop allowed" do
let(:maximum_coverage_drop) { {line: 10, branch: 10} }
it { is_expected.not_to be_failing }
end
context "last coverage lower then new coverage" do
let(:last_coverage) { {line: 70.0, branch: 70.0} }
it { is_expected.not_to be_failing }
end
context "last coverage higher than new coverage" do
let(:last_coverage) { {line: 80.01, branch: 80.01} }
it { is_expected.to be_failing }
context "but allowed drop is within range" do
let(:maximum_coverage_drop) { {line: 0.01, branch: 0.01} }
it { is_expected.not_to be_failing }
end
end
context "one coverage lower than maximum drop" do
let(:last_coverage) { {line: 80.01, branch: 70.0} }
it { is_expected.to be_failing }
context "but allowed drop is within range" do
let(:maximum_coverage_drop) { {line: 0.01} }
it { is_expected.not_to be_failing }
end
end
context "coverage expectation for a coverage that wasn't previously present" do
let(:last_coverage) { {line: 80.0} }
let(:maximum_coverage_drop) { {line: 0, branch: 0} }
it { is_expected.not_to be_failing }
end
context "no last run coverage information" do
let(:last_run) { nil }
it { is_expected.not_to be_failing }
end
context "old last_run.json format" do
let(:last_run) do
{
# this format only considers line coverage
result: {covered_percent: 80.0}
}
end
it { is_expected.not_to be_failing }
end
end
simplecov-0.22.0/spec/exit_codes/minimum_coverage_by_file_check_spec.rb 0000664 0000000 0000000 00000001251 14351411403 0026362 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
require "helper"
RSpec.describe SimpleCov::ExitCodes::MinimumCoverageByFileCheck do
let(:result) do
instance_double(SimpleCov::Result, coverage_statistics_by_file: stats)
end
let(:stats) do
{
line: [SimpleCov::CoverageStatistics.new(covered: 8, missed: 2)]
}
end
subject { described_class.new(result, minimum_coverage_by_file) }
context "all files passing requirements" do
let(:minimum_coverage_by_file) { {line: 80} }
it { is_expected.not_to be_failing }
end
context "one file violating requirements" do
let(:minimum_coverage_by_file) { {line: 90} }
it { is_expected.to be_failing }
end
end
simplecov-0.22.0/spec/exit_codes/minimum_overall_coverage_check_spec.rb 0000664 0000000 0000000 00000001716 14351411403 0026423 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
require "helper"
RSpec.describe SimpleCov::ExitCodes::MinimumOverallCoverageCheck do
let(:result) do
instance_double(SimpleCov::Result, coverage_statistics: stats)
end
let(:stats) do
{
line: SimpleCov::CoverageStatistics.new(covered: 8, missed: 2),
branch: SimpleCov::CoverageStatistics.new(covered: 8, missed: 2)
}
end
subject { described_class.new(result, minimum_coverage) }
context "everything exactly ok" do
let(:minimum_coverage) { {line: 80.0} }
it { is_expected.not_to be_failing }
end
context "coverage violated" do
let(:minimum_coverage) { {line: 90.0} }
it { is_expected.to be_failing }
end
context "coverage slightly violated" do
let(:minimum_coverage) { {line: 80.01} }
it { is_expected.to be_failing }
end
context "one criterion violated" do
let(:minimum_coverage) { {line: 80.0, branch: 90.0} }
it { is_expected.to be_failing }
end
end
simplecov-0.22.0/spec/file_list_spec.rb 0000664 0000000 0000000 00000002717 14351411403 0020042 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
require "helper"
describe SimpleCov::Result do
subject do
original_result = {
source_fixture("sample.rb") => {
"lines" => [nil, 1, 1, 1, nil, nil, 1, 1, nil, nil],
"branches" => {}
},
source_fixture("app/models/user.rb") => {
"lines" => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil],
"branches" => {}
},
source_fixture("app/controllers/sample_controller.rb") => {
"lines" => [nil, 2, 2, 0, nil, nil, 0, nil, nil, nil],
"branches" => {}
}
}
SimpleCov::Result.new(original_result).files
end
it "has 11 covered lines" do
expect(subject.covered_lines).to eq(11)
end
it "has 3 missed lines" do
expect(subject.missed_lines).to eq(3)
end
it "has 17 never lines" do
expect(subject.never_lines).to eq(17)
end
it "has 14 lines of code" do
expect(subject.lines_of_code).to eq(14)
end
it "has 5 skipped lines" do
expect(subject.skipped_lines).to eq(5)
end
it "has the correct covered percent" do
expect(subject.covered_percent).to eq(78.57142857142857)
end
it "has the correct covered percentages" do
expect(subject.covered_percentages).to eq([50.0, 80.0, 100.0])
end
it "has the correct least covered file" do
expect(subject.least_covered_file).to match(/sample_controller.rb/)
end
it "has the correct covered strength" do
expect(subject.covered_strength).to eq(0.9285714285714286)
end
end
simplecov-0.22.0/spec/filters_spec.rb 0000664 0000000 0000000 00000017415 14351411403 0017541 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
require "helper"
describe SimpleCov::SourceFile do
subject do
SimpleCov::SourceFile.new(source_fixture("sample.rb"), [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil])
end
it "doesn't match a new SimpleCov::StringFilter 'foobar'" do
expect(SimpleCov::StringFilter.new("foobar")).not_to be_matches subject
end
it "doesn't match a new SimpleCov::StringFilter 'some/path'" do
expect(SimpleCov::StringFilter.new("some/path")).not_to be_matches subject
end
it "matches a new SimpleCov::StringFilter 'spec/fixtures'" do
expect(SimpleCov::StringFilter.new("spec/fixtures")).to be_matches subject
end
it "matches a new SimpleCov::StringFilter 'spec/fixtures/sample.rb'" do
expect(SimpleCov::StringFilter.new("spec/fixtures/sample.rb")).to be_matches subject
end
it "matches a new SimpleCov::StringFilter 'sample.rb'" do
expect(SimpleCov::StringFilter.new("sample.rb")).to be_matches subject
end
it "doesn't match a new SimpleCov::StringFilter '.pl'" do
expect(SimpleCov::StringFilter.new(".pl")).not_to be_matches subject
end
it "doesn't match a parent directory with a new SimpleCov::StringFilter" do
parent_dir_name = File.basename(File.expand_path("..", File.dirname(__FILE__)))
expect(SimpleCov::StringFilter.new(parent_dir_name)).not_to be_matches subject
end
it "matches a new SimpleCov::RegexFilter /\/fixtures\//" do
expect(SimpleCov::RegexFilter.new(/\/fixtures\//)).to be_matches subject
end
it "doesn't match a new SimpleCov::RegexFilter /^\/fixtures\//" do
expect(SimpleCov::RegexFilter.new(/^\/fixtures\//)).not_to be_matches subject
end
it "matches a new SimpleCov::RegexFilter /^\/spec\//" do
expect(SimpleCov::RegexFilter.new(/^\/spec\//)).to be_matches subject
end
it "doesn't match a new SimpleCov::BlockFilter that is not applicable" do
expect(SimpleCov::BlockFilter.new(proc { |s| File.basename(s.filename) == "foo.rb" })).not_to be_matches subject
end
it "matches a new SimpleCov::BlockFilter that is applicable" do
expect(SimpleCov::BlockFilter.new(proc { |s| File.basename(s.filename) == "sample.rb" })).to be_matches subject
end
it "matches a new SimpleCov::ArrayFilter when 'sample.rb' is passed as array" do
expect(SimpleCov::ArrayFilter.new(["sample.rb"])).to be_matches subject
end
it "doesn't match a new SimpleCov::ArrayFilter when a file path different than 'sample.rb' is passed as array" do
expect(SimpleCov::ArrayFilter.new(["other_file.rb"])).not_to be_matches subject
end
it "matches a new SimpleCov::ArrayFilter when two file paths including 'sample.rb' are passed as array" do
expect(SimpleCov::ArrayFilter.new(["sample.rb", "other_file.rb"])).to be_matches subject
end
it "doesn't match a parent directory with a new SimpleCov::ArrayFilter" do
parent_dir_name = File.basename(File.expand_path("..", File.dirname(__FILE__)))
expect(SimpleCov::ArrayFilter.new([parent_dir_name])).not_to be_matches subject
end
it "matches a new SimpleCov::ArrayFilter when /sample.rb/ is passed as array" do
expect(SimpleCov::ArrayFilter.new([/sample.rb/])).to be_matches subject
end
it "doesn't match a new SimpleCov::ArrayFilter when a file path different than /sample.rb/ is passed as array" do
expect(SimpleCov::ArrayFilter.new([/other_file.rb/])).not_to be_matches subject
end
it "matches a new SimpleCov::ArrayFilter when a block is passed as array and returns true" do
expect(SimpleCov::ArrayFilter.new([proc { true }])).to be_matches subject
end
it "doesn't match a new SimpleCov::ArrayFilter when a block that returns false is passed as array" do
expect(SimpleCov::ArrayFilter.new([proc { false }])).not_to be_matches subject
end
it "matches a new SimpleCov::ArrayFilter when a custom class that returns true is passed as array" do
filter = Class.new(SimpleCov::Filter) do
def matches?(_source_file)
true
end
end.new(nil)
expect(SimpleCov::ArrayFilter.new([filter])).to be_matches subject
end
it "doesn't match a new SimpleCov::ArrayFilter when a custom class that returns false is passed as array" do
filter = Class.new(SimpleCov::Filter) do
def matches?(_source_file)
false
end
end.new(nil)
expect(SimpleCov::ArrayFilter.new([filter])).not_to be_matches subject
end
context "with no filters set up and a basic source file in an array" do
before do
@prev_filters = SimpleCov.filters
SimpleCov.filters = []
end
subject do
[SimpleCov::SourceFile.new(source_fixture("sample.rb"), [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil])]
end
after do
SimpleCov.filters = @prev_filters
end
it 'returns 0 items after executing SimpleCov.filtered on files when using a "sample" string filter' do
SimpleCov.add_filter "sample"
expect(SimpleCov.filtered(subject).count).to be_zero
end
it 'returns 0 items after executing SimpleCov.filtered on files when using a "spec/fixtures" string filter' do
SimpleCov.add_filter "spec/fixtures"
expect(SimpleCov.filtered(subject).count).to be_zero
end
it 'returns 1 item after executing SimpleCov.filtered on files when using a "fooo" string filter' do
SimpleCov.add_filter "fooo"
expect(SimpleCov.filtered(subject).count).to eq(1)
end
it "returns 0 items after executing SimpleCov.filtered on files when using a block filter that returns true" do
SimpleCov.add_filter do
true
end
expect(SimpleCov.filtered(subject).count).to be_zero
end
it "returns 1 item after executing SimpleCov.filtered on files when using an always-false block filter" do
SimpleCov.add_filter do
false
end
expect(SimpleCov.filtered(subject).count).to eq(1)
end
it "returns a FileList after filtering" do
SimpleCov.add_filter "fooo"
expect(SimpleCov.filtered(subject)).to be_a SimpleCov::FileList
end
end
context "with the default configuration" do
skip "requires the default configuration" if ENV["SIMPLECOV_NO_DEFAULTS"]
def a_file(path)
path = File.join(SimpleCov.root, path) unless path.start_with?("/")
SimpleCov::SourceFile.new(path, [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil])
end
context "inside the project" do
it "doesn't filter" do
expect(SimpleCov.filtered([a_file("foo.rb")]).count).to eq(1)
end
it "filters vendor/bundle" do
expect(SimpleCov.filtered([a_file("vendor/bundle/foo.rb")]).count).to eq(0)
end
it "filters hidden folders" do
expect(SimpleCov.filtered([a_file(".semaphore-cache/lib.rb")]).count).to eq(0)
end
it "filters hidden files" do
expect(SimpleCov.filtered([a_file(".hidden_config.rb")]).count).to eq(0)
end
it "doesn't filter hidden files further down the path" do
expect(SimpleCov.filtered([a_file("some_dir/.sneaky.rb")]).count).to eq(1)
end
end
context "outside the project" do
it "filters" do
expect(SimpleCov.filtered([a_file("/other/path/foo.rb")]).count).to eq(0)
end
it "filters even if the sibling directory has SimpleCov.root as a prefix" do
sibling_dir = "#{SimpleCov.root}_cache"
expect(SimpleCov.filtered([a_file("#{sibling_dir}/foo.rb")]).count).to eq(0)
end
end
end
describe ".class_for_argument" do
it "returns SimpleCov::StringFilter for a string" do
expect(SimpleCov::Filter.class_for_argument("filestring")).to eq(SimpleCov::StringFilter)
end
it "returns SimpleCov::RegexFilter for a string" do
expect(SimpleCov::Filter.class_for_argument(/regex/)).to eq(SimpleCov::RegexFilter)
end
it "returns SimpleCov::RegexFilter for a string" do
expect(SimpleCov::Filter.class_for_argument(%w[file1 file2])).to eq(SimpleCov::ArrayFilter)
end
end
end
simplecov-0.22.0/spec/fixtures/ 0000775 0000000 0000000 00000000000 14351411403 0016373 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/spec/fixtures/app/ 0000775 0000000 0000000 00000000000 14351411403 0017153 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/spec/fixtures/app/controllers/ 0000775 0000000 0000000 00000000000 14351411403 0021521 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/spec/fixtures/app/controllers/sample_controller.rb 0000664 0000000 0000000 00000000134 14351411403 0025570 0 ustar 00root root 0000000 0000000 # Foo class
class Foo
def initialize
@foo = "baz"
end
def bar
@foo
end
end
simplecov-0.22.0/spec/fixtures/app/models/ 0000775 0000000 0000000 00000000000 14351411403 0020436 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/spec/fixtures/app/models/user.rb 0000664 0000000 0000000 00000000134 14351411403 0021737 0 ustar 00root root 0000000 0000000 # Foo class
class Foo
def initialize
@foo = "baz"
end
def bar
@foo
end
end
simplecov-0.22.0/spec/fixtures/branch_tester_script.rb 0000664 0000000 0000000 00000001116 14351411403 0023126 0 ustar 00root root 0000000 0000000 # Adapted from https://github.com/simplecov-ruby/simplecov/pull/694#issuecomment-562097006
# rubocop:disable all
x = 1
x.eql?(4) ? "4" : x
puts x unless x.eql?(5)
unless x == 5
puts "Ola.."
end
unless x != 5
puts "Ola.."
end
unless x != 5
puts "Ola.."
else
puts "text"
end
puts x if x.eql?(5)
if x != 5
puts "Ola.."
end
if x == 5
puts "Ola.."
end
if x != 5
puts "Ola.."
else
puts "text"
end
x = 4
if x == 1
puts "wow 1"
puts "such excite!"
elsif x == 4
4.times { puts "4!!!!"}
elsif x == 14
puts "magic"
puts "very"
else
puts x
end
# rubocop:enable all
simplecov-0.22.0/spec/fixtures/branches.rb 0000664 0000000 0000000 00000000222 14351411403 0020501 0 ustar 00root root 0000000 0000000 class Branches
def call(arg)
return if arg < 0
arg == 42 ? :yes : :no
if arg.odd?
:yes
else
:no
end
end
end
simplecov-0.22.0/spec/fixtures/case.rb 0000664 0000000 0000000 00000000247 14351411403 0017636 0 ustar 00root root 0000000 0000000 module Case
def self.call(arg)
case arg
when 0...23
:foo
when 40..50
:bar
when Integer
:baz
else
:nope
end
end
end
simplecov-0.22.0/spec/fixtures/case_without_else.rb 0000664 0000000 0000000 00000000222 14351411403 0022422 0 ustar 00root root 0000000 0000000 module Case
def self.call(arg)
case arg
when 0...23
:foo
when 40..50
:bar
when Integer
:baz
end
end
end
simplecov-0.22.0/spec/fixtures/conditionally_loaded_1.rb 0000664 0000000 0000000 00000000053 14351411403 0023316 0 ustar 00root root 0000000 0000000 # some comment
puts "wargh"
puts "wargh 1"
simplecov-0.22.0/spec/fixtures/conditionally_loaded_2.rb 0000664 0000000 0000000 00000000053 14351411403 0023317 0 ustar 00root root 0000000 0000000 # some comment
puts "wargh"
puts "wargh 2"
simplecov-0.22.0/spec/fixtures/coverer.rb 0000664 0000000 0000000 00000000276 14351411403 0020372 0 ustar 00root root 0000000 0000000 # Script to gather coverage data to use in tests to go along with fixtures
require "coverage"
Coverage.start(:all)
require_relative "uneven_nocovs"
UnevenNocov.call(42)
p Coverage.result
simplecov-0.22.0/spec/fixtures/deleted_source_sample.rb 0000664 0000000 0000000 00000000535 14351411403 0023252 0 ustar 00root root 0000000 0000000 $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", ".."))
require "lib/simplecov"
SimpleCov.start { command_name "Test" }
dir = __dir__
file = File.join(dir, "generated_buddha.rb")
code = %{
def kill_the_buddha(z)
z**z
end
}
File.open(file, "w") { |f| f.print code }
load file
File.unlink file
raise unless kill_the_buddha(3) == 27
simplecov-0.22.0/spec/fixtures/elsif.rb 0000664 0000000 0000000 00000000241 14351411403 0020017 0 ustar 00root root 0000000 0000000 module Elsif
def self.call(arg)
if arg.odd?
:odd
elsif arg == 30
:mop
elsif arg == 42
:yay
else
:nay
end
end
end
simplecov-0.22.0/spec/fixtures/empty_euc-jp.rb 0000664 0000000 0000000 00000000000 14351411403 0021307 0 ustar 00root root 0000000 0000000 simplecov-0.22.0/spec/fixtures/euc-jp-shebang.rb 0000664 0000000 0000000 00000000065 14351411403 0021511 0 ustar 00root root 0000000 0000000 #!/usr/bin/env ruby
# encoding: EUC-JP
puts "135¡ëC"
simplecov-0.22.0/spec/fixtures/euc-jp.rb 0000664 0000000 0000000 00000000041 14351411403 0020076 0 ustar 00root root 0000000 0000000 # encoding: EUC-JP
puts "135¡ëC"
simplecov-0.22.0/spec/fixtures/eval_test/ 0000775 0000000 0000000 00000000000 14351411403 0020361 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/spec/fixtures/eval_test/eval_test.erb 0000664 0000000 0000000 00000000101 14351411403 0023031 0 ustar 00root root 0000000 0000000 <% if 1 + 1 == 2 %>
covered
<% else %>
not covered
<% end %>
simplecov-0.22.0/spec/fixtures/eval_test/eval_test.rb 0000664 0000000 0000000 00000000266 14351411403 0022700 0 ustar 00root root 0000000 0000000 require "simplecov"
SimpleCov.enable_coverage_for_eval
SimpleCov.start "rails"
file = File.join(__dir__, "eval_test.erb")
erb = ERB.new(File.read(file))
erb.filename = file
erb.run
simplecov-0.22.0/spec/fixtures/frameworks/ 0000775 0000000 0000000 00000000000 14351411403 0020553 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/spec/fixtures/frameworks/rspec_bad.rb 0000664 0000000 0000000 00000000546 14351411403 0023027 0 ustar 00root root 0000000 0000000 $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "..", ".."))
require "lib/simplecov"
require "rspec"
SimpleCov.print_error_status = ENV["PRINT_ERROR_STATUS"] == "true" if ENV.key? "PRINT_ERROR_STATUS"
SimpleCov.start
describe "exit status" do
it "should exit with a non-zero exit status when assertion fails" do
expect(1).to eq(2)
end
end
simplecov-0.22.0/spec/fixtures/frameworks/rspec_good.rb 0000664 0000000 0000000 00000000376 14351411403 0023232 0 ustar 00root root 0000000 0000000 $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "..", ".."))
require "lib/simplecov"
require "rspec"
SimpleCov.start
describe "exit status" do
it "should exit with a zero exit status when assertion fails" do
expect(1).to eq(1)
end
end
simplecov-0.22.0/spec/fixtures/frameworks/testunit_bad.rb 0000664 0000000 0000000 00000000467 14351411403 0023574 0 ustar 00root root 0000000 0000000 $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "..", ".."))
require "lib/simplecov"
SimpleCov.print_error_status = ENV["PRINT_ERROR_STATUS"] == "true" if ENV.key? "PRINT_ERROR_STATUS"
SimpleCov.start
require "test/unit"
class FooTest < Test::Unit::TestCase
def test_foo
assert false
end
end
simplecov-0.22.0/spec/fixtures/frameworks/testunit_good.rb 0000664 0000000 0000000 00000000322 14351411403 0023764 0 ustar 00root root 0000000 0000000 $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "..", ".."))
require "lib/simplecov"
SimpleCov.start
require "test/unit"
class FooTest < Test::Unit::TestCase
def test_foo
assert true
end
end
simplecov-0.22.0/spec/fixtures/inline.rb 0000664 0000000 0000000 00000000235 14351411403 0020176 0 ustar 00root root 0000000 0000000 class Inline
def call(arg)
String(arg == 42 ? :yes : :no)
String(
if arg.odd?
:yes
else
:no
end
)
end
end
simplecov-0.22.0/spec/fixtures/iso-8859.rb 0000664 0000000 0000000 00000000037 14351411403 0020125 0 ustar 00root root 0000000 0000000
# localized to Español thus:
simplecov-0.22.0/spec/fixtures/nested_branches.rb 0000664 0000000 0000000 00000000461 14351411403 0022050 0 ustar 00root root 0000000 0000000 # yes rubocop you are right but I want to test nesting!
# rubocop:disable Metrics/BlockNesting
module NestedBranches
def self.call(arg)
if arg.even?
if arg == 42
arg -= 1 while arg > 40
:ok
end
else
:nope
end
end
end
# rubocop:enable Metrics/BlockNesting
simplecov-0.22.0/spec/fixtures/never.rb 0000664 0000000 0000000 00000000047 14351411403 0020040 0 ustar 00root root 0000000 0000000 # This class is purely some
# comments
simplecov-0.22.0/spec/fixtures/nocov_complex.rb 0000664 0000000 0000000 00000000613 14351411403 0021573 0 ustar 00root root 0000000 0000000 # So much skippping
# rubocop:disable Metrics/MethodLength
module NoCovComplex
def self.call(arg)
# :nocov:
if arg == 42
0
# :nocov:
else
puts "yolo"
end
arg += 1 if arg.odd?
# :nocov:
arg -= 1 while arg > 40
case arg
when 1..20
:nope
# :nocov:
when 30..40
:yas
end
end
end
# rubocop:enable Metrics/MethodLength
simplecov-0.22.0/spec/fixtures/parallel_tests.rb 0000664 0000000 0000000 00000000042 14351411403 0021732 0 ustar 00root root 0000000 0000000 # foo
puts "foo"
# bar
puts "bar"
simplecov-0.22.0/spec/fixtures/resultset1.rb 0000664 0000000 0000000 00000000054 14351411403 0021032 0 ustar 00root root 0000000 0000000 puts "foo"
puts "foo"
puts "foo"
puts "foo"
simplecov-0.22.0/spec/fixtures/resultset2.rb 0000664 0000000 0000000 00000000042 14351411403 0021030 0 ustar 00root root 0000000 0000000 class Resultset
VERSION = 2
end
simplecov-0.22.0/spec/fixtures/sample.rb 0000664 0000000 0000000 00000000226 14351411403 0020201 0 ustar 00root root 0000000 0000000 # Foo class
class Foo
def initialize
@foo = "baz"
end
def bar
@foo
end
# :nocov:
def skipped
@foo * 2
end
# :nocov:
end
simplecov-0.22.0/spec/fixtures/single_nocov.rb 0000664 0000000 0000000 00000000261 14351411403 0021404 0 ustar 00root root 0000000 0000000 # :nocov:
module SingleNocov
def self.call(arg)
if arg.odd?
:odd
elsif arg == 30
:mop
elsif arg == 42
:yay
else
:nay
end
end
end
simplecov-0.22.0/spec/fixtures/skipped.rb 0000664 0000000 0000000 00000000056 14351411403 0020360 0 ustar 00root root 0000000 0000000 # Not relevant
# :nocov:
# Hash.new
# :nocov:
simplecov-0.22.0/spec/fixtures/skipped_and_executed.rb 0000664 0000000 0000000 00000000174 14351411403 0023071 0 ustar 00root root 0000000 0000000 # So much skipping
# :nocov:
class Foo
def bar(arg)
if arg == 42
0
else
1
end
end
end
# :nocov:
simplecov-0.22.0/spec/fixtures/uneven_nocovs.rb 0000664 0000000 0000000 00000000321 14351411403 0021603 0 ustar 00root root 0000000 0000000 module UnevenNocov
def self.call(arg)
# :nocov:
if arg.odd?
:odd
elsif arg == 30
:mop
# :nocov:
elsif arg == 42
:yay
# :nocov:
else
:nay
end
end
end
simplecov-0.22.0/spec/fixtures/utf-8-magic.rb 0000664 0000000 0000000 00000000040 14351411403 0020733 0 ustar 00root root 0000000 0000000 # encoding: UTF-8
puts "135°C"
simplecov-0.22.0/spec/fixtures/utf-8.rb 0000664 0000000 0000000 00000000016 14351411403 0017660 0 ustar 00root root 0000000 0000000 puts "135°C"
simplecov-0.22.0/spec/gemspec_spec.rb 0000664 0000000 0000000 00000000635 14351411403 0017510 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
require "open3"
RSpec.describe "gemspec sanity" do
after do
File.delete(Dir.glob("simplecov-*.gem").first)
end
let(:build) do
Bundler.with_original_env do
Open3.capture3("gem build simplecov.gemspec")
end
end
it "has no warnings" do
expect(build[1]).not_to include("WARNING")
end
it "succeeds" do
expect(build[2]).to be_success
end
end
simplecov-0.22.0/spec/helper.rb 0000664 0000000 0000000 00000001647 14351411403 0016336 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
require "rspec"
require "stringio"
require "open3"
# loaded before simplecov to also capture parse time warnings
require "support/fail_rspec_on_ruby_warning"
require "simplecov"
SimpleCov.coverage_dir("tmp/coverage")
def source_fixture(filename)
File.join(source_fixture_base_directory, "fixtures", filename)
end
def source_fixture_base_directory
@source_fixture_base_directory ||= File.dirname(__FILE__)
end
# Taken from http://stackoverflow.com/questions/4459330/how-do-i-temporarily-redirect-stderr-in-ruby
def capture_stderr
# The output stream must be an IO-like object. In this case we capture it in
# an in-memory IO object so we can return the string value. You can assign any
# IO object here.
previous_stderr = $stderr
$stderr = StringIO.new
yield
$stderr.string
ensure
# Restore the previous value of stderr (typically equal to STDERR).
$stderr = previous_stderr
end
simplecov-0.22.0/spec/last_run_spec.rb 0000664 0000000 0000000 00000002173 14351411403 0017713 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
require "helper"
describe SimpleCov::LastRun do
subject { SimpleCov::LastRun }
it "defines a last_run_path" do
expect(subject.last_run_path).to include "tmp/coverage/.last_run.json"
end
it "writes json to its last_run_path that can be parsed again" do
structure = [{"key" => "value"}]
subject.write(structure)
file_contents = File.read(subject.last_run_path)
expect(JSON.parse(file_contents)).to eq structure
end
context "reading" do
context "but the last_run file does not exist" do
before { File.delete(subject.last_run_path) if File.exist?(subject.last_run_path) }
it "returns nil" do
expect(subject.read).to be_nil
end
end
context "a non empty result" do
before { subject.write([]) }
it "reads json from its last_run_path" do
expect(subject.read).to eq([])
end
end
context "an empty result" do
before do
File.open(subject.last_run_path, "w+") do |f|
f.puts ""
end
end
it "returns nil" do
expect(subject.read).to be_nil
end
end
end
end
simplecov-0.22.0/spec/lines_classifier_spec.rb 0000664 0000000 0000000 00000006123 14351411403 0021401 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
require "helper"
require "simplecov/lines_classifier"
describe SimpleCov::LinesClassifier do
describe "#classify" do
describe "relevant lines" do
it "determines code as relevant" do
classified_lines = subject.classify [
"module Foo",
" class Baz",
" def Bar",
" puts 'hi'",
" end",
" end",
"end"
]
expect(classified_lines.length).to eq 7
expect(classified_lines).to all be_relevant
end
it "determines invalid UTF-8 byte sequences as relevant" do
classified_lines = subject.classify [
"bytes = \"\xF1t\xEBrn\xE2ti\xF4n\xE0liz\xE6ti\xF8n\""
]
expect(classified_lines.length).to eq 1
expect(classified_lines).to all be_relevant
end
end
describe "not-relevant lines" do
it "determines whitespace is not-relevant" do
classified_lines = subject.classify [
"",
" ",
"\t\t"
]
expect(classified_lines.length).to eq 3
expect(classified_lines).to all be_irrelevant
end
describe "comments" do
it "determines comments are not-relevant" do
classified_lines = subject.classify [
"#Comment",
" # Leading space comment",
"\t# Leading tab comment"
]
expect(classified_lines.length).to eq 3
expect(classified_lines).to all be_irrelevant
end
it "doesn't mistake interpolation as a comment" do
classified_lines = subject.classify [
'puts "#{var}"' # rubocop:disable Lint/InterpolationCheck
]
expect(classified_lines.length).to eq 1
expect(classified_lines).to all be_relevant
end
end
describe ":nocov: blocks" do
it "determines :nocov: blocks are not-relevant" do
classified_lines = subject.classify [
"# :nocov:",
"def hi",
"end",
"# :nocov:"
]
expect(classified_lines.length).to eq 4
expect(classified_lines).to all be_irrelevant
end
it "determines all lines after a non-closing :nocov: as not-relevant" do
classified_lines = subject.classify [
"# :nocov:",
"puts 'Not relevant'",
"# :nocov:",
"puts 'Relevant again'",
"puts 'Still relevant'",
"# :nocov:",
"puts 'Not relevant till the end'",
"puts 'Ditto'"
]
expect(classified_lines.length).to eq 8
expect(classified_lines[0..2]).to all be_irrelevant
expect(classified_lines[3..4]).to all be_relevant
expect(classified_lines[5..7]).to all be_irrelevant
end
end
end
end
RSpec::Matchers.define :be_relevant do
match do |actual|
actual == SimpleCov::LinesClassifier::RELEVANT
end
end
RSpec::Matchers.define :be_irrelevant do
match do |actual|
actual == SimpleCov::LinesClassifier::NOT_RELEVANT
end
end
end
simplecov-0.22.0/spec/multi_formatter_spec.rb 0000664 0000000 0000000 00000001131 14351411403 0021272 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
require "helper"
require "simplecov/formatter/multi_formatter"
describe SimpleCov::Formatter::MultiFormatter do
describe ".[]" do
# Regression test for https://github.com/simplecov-ruby/simplecov/issues/428
it "constructs a formatter with multiple children" do
# Silence deprecation warnings.
allow(described_class).to receive(:warn)
children = [
SimpleCov::Formatter::SimpleFormatter,
SimpleCov::Formatter::SimpleFormatter
]
expect(described_class[*children].new.formatters).to eq(children)
end
end
end
simplecov-0.22.0/spec/result_merger_spec.rb 0000664 0000000 0000000 00000024254 14351411403 0020747 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
require "helper"
require "tempfile"
require "timeout"
describe SimpleCov::ResultMerger do
after do
File.delete(SimpleCov::ResultMerger.resultset_path) if File.exist?(SimpleCov::ResultMerger.resultset_path)
end
let(:resultset1) do
{
source_fixture("sample.rb") => {"lines" => [nil, 1, 1, 1, nil, nil, 1, 1, nil, nil]},
source_fixture("app/models/user.rb") => {"lines" => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil]},
source_fixture("app/controllers/sample_controller.rb") => {"lines" => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil]},
source_fixture("resultset1.rb") => {"lines" => [1, 1, 1, 1]},
source_fixture("parallel_tests.rb") => {"lines" => [nil, 0, nil, 0]},
source_fixture("conditionally_loaded_1.rb") => {"lines" => [nil, 0, 1]} # loaded only in the first resultset
}
end
let(:resultset2) do
{
source_fixture("sample.rb") => {"lines" => [1, nil, 1, 1, nil, nil, 1, 1, nil, nil]},
source_fixture("app/models/user.rb") => {"lines" => [nil, 1, 5, 1, nil, nil, 1, 0, nil, nil]},
source_fixture("app/controllers/sample_controller.rb") => {"lines" => [nil, 3, 1, nil, nil, nil, 1, 0, nil, nil]},
source_fixture("resultset2.rb") => {"lines" => [nil, 1, 1, nil]},
source_fixture("parallel_tests.rb") => {"lines" => [nil, nil, 0, 0]},
source_fixture("conditionally_loaded_2.rb") => {"lines" => [nil, 0, 1]} # loaded only in the second resultset
}
end
let(:merged_resultset1_and2) do
{
source_fixture("sample.rb") => {"lines" => [1, 1, 2, 2, nil, nil, 2, 2, nil, nil]},
source_fixture("app/models/user.rb") => {"lines" => [nil, 2, 6, 2, nil, nil, 2, 0, nil, nil]},
source_fixture("app/controllers/sample_controller.rb") => {"lines" => [nil, 4, 2, 1, nil, nil, 2, 0, nil, nil]},
source_fixture("resultset1.rb") => {"lines" => [1, 1, 1, 1]},
source_fixture("parallel_tests.rb") => {"lines" => [nil, nil, nil, 0]},
source_fixture("conditionally_loaded_1.rb") => {"lines" => [nil, 0, 1]},
source_fixture("resultset2.rb") => {"lines" => [nil, 1, 1, nil]},
source_fixture("conditionally_loaded_2.rb") => {"lines" => [nil, 0, 1]}
}
end
let(:result1) { SimpleCov::Result.new(resultset1, command_name: "result1") }
let(:result2) { SimpleCov::Result.new(resultset2, command_name: "result2") }
describe "resultset handling" do
# See GitHub issue #6
it "returns an empty hash when the resultset cache file is empty" do
File.open(SimpleCov::ResultMerger.resultset_path, "w+") { |f| f.puts "" }
expect(SimpleCov::ResultMerger.read_resultset).to be_empty
end
# See GitHub issue #6
it "returns an empty hash when the resultset cache file is not present" do
system "rm #{SimpleCov::ResultMerger.resultset_path}" if File.exist?(SimpleCov::ResultMerger.resultset_path)
expect(SimpleCov::ResultMerger.read_resultset).to be_empty
end
end
describe "basic workings with 2 resultsets" do
before do
system "rm #{SimpleCov::ResultMerger.resultset_path}" if File.exist?(SimpleCov::ResultMerger.resultset_path)
SimpleCov::ResultMerger.store_result(result1)
SimpleCov::ResultMerger.store_result(result2)
end
it "has stored data in resultset_path JSON file" do
expect(File.readlines(SimpleCov::ResultMerger.resultset_path).length).to be > 50
end
it "returns a hash containing keys ['result1' and 'result2'] for resultset" do
expect(SimpleCov::ResultMerger.read_resultset.keys.sort).to eq %w[result1 result2]
end
it "returns proper values for merged_result" do
result = SimpleCov::ResultMerger.merged_result
expect_resultset_1_and_2_merged(result.to_hash)
end
context "with second result way above the merge_timeout" do
let(:result2) { outdated(super()) }
before do
SimpleCov::ResultMerger.store_result(result2)
end
it "has only one result in SimpleCov::ResultMerger.results" do
# second result does not appear in the merged results
merged_coverage = SimpleCov::ResultMerger.merged_result
expect(merged_coverage.command_name).to eq "result1"
expect(merged_coverage.original_result).to eq resultset1
end
end
end
describe ".merge_and_store" do
let(:resultset_prefix) { "test_resultset" }
let(:resultset1_path) { "#{resultset_prefix}1.json" }
let(:resultset2_path) { "#{resultset_prefix}2.json" }
describe "merging behavior" do
before :each do
store_result(result1, path: resultset1_path)
store_result(result2, path: resultset2_path)
end
after :each do
FileUtils.rm Dir.glob("#{resultset_prefix}*.json")
end
context "2 normal results" do
it "correctly merges the 2 results" do
result = SimpleCov::ResultMerger.merge_and_store(resultset1_path, resultset2_path)
expect_resultset_1_and_2_merged(result.to_hash)
end
it "has the result stored" do
SimpleCov::ResultMerger.merge_and_store(resultset1_path, resultset2_path)
expect_resultset_1_and_2_merged(SimpleCov::ResultMerger.read_resultset)
end
end
context "1 resultset is outdated" do
let(:result1) { outdated(super()) }
it "completely omits the result from the merge" do
result_hash = SimpleCov::ResultMerger.merge_and_store(resultset1_path, resultset2_path).to_hash
expect(result_hash.keys).to eq ["result2"]
merged_coverage = result_hash.fetch("result2").fetch("coverage")
expect(merged_coverage).to eq(resultset2)
end
it "includes it when we say ignore_timeout: true" do
result_hash = SimpleCov::ResultMerger.merge_and_store(resultset1_path, resultset2_path, ignore_timeout: true).to_hash
expect_resultset_1_and_2_merged(result_hash)
end
end
context "both resultsets outdated" do
let(:result1) { outdated(super()) }
let(:result2) { outdated(super()) }
it "completely omits the result from the merge" do
allow(SimpleCov::ResultMerger).to receive(:store)
result = SimpleCov::ResultMerger.merge_and_store(resultset1_path, resultset2_path)
expect(result).to eq nil
expect(SimpleCov::ResultMerger).not_to have_received(:store)
end
it "includes both when we say ignore_timeout: true" do
result_hash = SimpleCov::ResultMerger.merge_and_store(resultset1_path, resultset2_path, ignore_timeout: true).to_hash
expect_resultset_1_and_2_merged(result_hash)
end
end
end
context "pre 0.18 result format" do
let(:file_path) { "old_resultset.json" }
let(:content) { {source_fixture("three.rb") => [nil, 1, 2]} }
before :each do
data = {
"some command name" => {
"coverage" => content,
"timestamp" => Time.now.to_i
}
}
File.open(file_path, "w+") do |f|
f.puts JSON.pretty_generate(data)
end
end
after :each do
FileUtils.rm file_path
end
it "gets the same content back but under \"lines\"" do
result = SimpleCov::ResultMerger.merge_and_store(file_path)
expect(result.original_result).to eq(
source_fixture("three.rb") => {"lines" => [nil, 1, 2]}
)
end
end
end
describe ".store_result" do
it "refreshes the resultset" do
set = SimpleCov::ResultMerger.read_resultset
SimpleCov::ResultMerger.store_result({})
new_set = SimpleCov::ResultMerger.read_resultset
expect(new_set).not_to be(set)
end
it "persists to disk" do
SimpleCov::ResultMerger.store_result("a" => [1])
new_set = SimpleCov::ResultMerger.read_resultset
expect(new_set).to eq("a" => [1])
end
it "synchronizes writes" do
expect(SimpleCov::ResultMerger).to receive(:synchronize_resultset)
SimpleCov::ResultMerger.store_result({})
end
end
describe ".resultset" do
it "synchronizes reads" do
expect(SimpleCov::ResultMerger).to receive(:synchronize_resultset)
SimpleCov::ResultMerger.read_resultset
end
end
describe ".synchronize_resultset" do
it "is reentrant (i.e. doesn't block its own process)" do
# without @resultset_locked, this spec would fail and
# `.store_result` wouldn't work
expect do
Timeout.timeout(1) do
SimpleCov::ResultMerger.synchronize_resultset do
SimpleCov::ResultMerger.synchronize_resultset do
# nothing
end
end
end
end.not_to raise_error
end
it "blocks other processes" do
file = Tempfile.new("foo")
test_script = <<-CODE
require "simplecov"
SimpleCov.coverage_dir(#{SimpleCov.coverage_dir.inspect})
# ensure the parent process has enough time to get a
# lock before we do
sleep 0.5
$stdout.sync = true
puts "running" # see `sleep`s in parent process
SimpleCov::ResultMerger.synchronize_resultset do
File.open(#{file.path.inspect}, "a") { |f| f.write("process 2\n") }
end
CODE
# rubocop:disable Security/Open
other_process = open("|ruby -e #{Shellwords.escape(test_script)} 2>/dev/null")
# rubocop:enable Security/Open
SimpleCov::ResultMerger.synchronize_resultset do
# wait until the child process is going, and then wait some more
# so we can be sure it blocks on the lock we already have.
sleep 0.1 until other_process.gets == "running\n"
sleep 1
# despite the sleeps, this will be written first since we got
# the first lock
File.open(file.path, "a") { |f| f.write("process 1\n") }
end
# wait for it to finish
other_process.gets
expect(file.read).to eq("process 1\nprocess 2\n")
end
end
private
def store_result(result, path:)
File.open(path, "w+") { |f| f.puts JSON.pretty_generate(result.to_hash) }
end
def outdated(result)
result.created_at = Time.now - 172_800
result
end
def expect_resultset_1_and_2_merged(result_hash)
merged_coverage = result_hash.fetch("result1, result2").fetch("coverage")
expect(merged_coverage).to eq(merged_resultset1_and2)
end
end
simplecov-0.22.0/spec/result_spec.rb 0000664 0000000 0000000 00000016407 14351411403 0017407 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
require "helper"
describe SimpleCov::Result do
context "with a (mocked) Coverage.result" do
before do
@prev_filters = SimpleCov.filters
SimpleCov.filters = []
@prev_groups = SimpleCov.groups
SimpleCov.groups = {}
@prev_formatter = SimpleCov.formatter
SimpleCov.formatter = nil
end
after do
SimpleCov.filters = @prev_filters
SimpleCov.groups = @prev_groups
SimpleCov.formatter = @prev_formatter
end
let(:original_result) do
{
source_fixture("sample.rb") => {"lines" => [nil, 1, 1, 1, nil, nil, 1, 1, nil, nil]},
source_fixture("app/models/user.rb") => {"lines" => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil]},
source_fixture("app/controllers/sample_controller.rb") => {"lines" => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil]}
}
end
context "a simple cov result initialized from that" do
subject { SimpleCov::Result.new(original_result) }
it "has 3 filenames" do
expect(subject.filenames.count).to eq(3)
end
it "has 3 source files" do
expect(subject.source_files.count).to eq(3)
subject.source_files.each do |source_file|
expect(source_file).to be_a SimpleCov::SourceFile
end
end
it "returns an instance of SimpleCov::FileList for source_files and files" do
expect(subject.files).to be_a SimpleCov::FileList
expect(subject.source_files).to be_a SimpleCov::FileList
end
it "has files equal to source_files" do
expect(subject.files).to eq(subject.source_files)
end
it "has accurate covered percent" do
# in our fixture, there are 13 covered line (result in 1) in all 15 relevant line (result in non-nil)
expect(subject.covered_percent).to eq(86.66666666666667)
end
it "has accurate covered percentages" do
expect(subject.covered_percentages).to eq([80.0, 80.0, 100.0])
end
it "has accurate least covered file" do
expect(subject.least_covered_file).to match(/sample_controller.rb/)
end
%i[covered_percent covered_percentages least_covered_file covered_strength covered_lines missed_lines total_lines].each do |msg|
it "responds to #{msg}" do
expect(subject).to respond_to(msg)
end
end
context "dumped with to_hash" do
it "is a hash" do
expect(subject.to_hash).to be_a Hash
end
context "loaded back with from_hash" do
let(:dumped_result) do
SimpleCov::Result.from_hash(subject.to_hash).first
end
it "has 3 source files" do
expect(dumped_result.source_files.count).to eq(subject.source_files.count)
end
it "has the same covered_percent" do
expect(dumped_result.covered_percent).to eq(subject.covered_percent)
end
it "has the same covered_percentages" do
expect(dumped_result.covered_percentages).to eq(subject.covered_percentages)
end
it "has the same timestamp" do
expect(dumped_result.created_at.to_i).to eq(subject.created_at.to_i)
end
it "has the same command_name" do
expect(dumped_result.command_name).to eq(subject.command_name)
end
it "has the same original_result" do
expect(dumped_result.original_result).to eq(subject.original_result)
end
end
end
end
context "with some filters set up" do
before do
SimpleCov.add_filter "sample.rb"
end
it "has 2 files in a new simple cov result" do
expect(SimpleCov::Result.new(original_result).source_files.length).to eq(2)
end
it "has 80 covered percent" do
expect(SimpleCov::Result.new(original_result).covered_percent).to eq(80)
end
it "has [80.0, 80.0] covered percentages" do
expect(SimpleCov::Result.new(original_result).covered_percentages).to eq([80.0, 80.0])
end
end
context "with groups set up for all files" do
before do
SimpleCov.add_group "Models", "app/models"
SimpleCov.add_group "Controllers", ["app/controllers"]
SimpleCov.add_group "Other" do |src_file|
File.basename(src_file.filename) == "sample.rb"
end
end
subject do
SimpleCov::Result.new(original_result)
end
it "has 3 groups" do
expect(subject.groups.length).to eq(3)
end
it "has user.rb in 'Models' group" do
expect(File.basename(subject.groups["Models"].first.filename)).to eq("user.rb")
end
it "has sample_controller.rb in 'Controllers' group" do
expect(File.basename(subject.groups["Controllers"].first.filename)).to eq("sample_controller.rb")
end
context "and simple formatter being used" do
before do
SimpleCov.formatter = SimpleCov::Formatter::SimpleFormatter
end
it "returns a formatted string with result.format!" do
expect(subject.format!).to be_a String
end
end
context "and multi formatter being used" do
before do
SimpleCov.formatters = [
SimpleCov::Formatter::SimpleFormatter,
SimpleCov::Formatter::SimpleFormatter
]
end
it "returns an array containing formatted string with result.format!" do
formatted = subject.format!
expect(formatted.count).to eq(2)
expect(formatted.first).to be_a String
end
end
end
context "with groups set up that do not match all files" do
before do
SimpleCov.configure do
add_group "Models", "app/models"
add_group "Controllers", "app/controllers"
end
end
subject { SimpleCov::Result.new(original_result) }
it "has 3 groups" do
expect(subject.groups.length).to eq(3)
end
it "has 1 item per group" do
subject.groups.each_value do |files|
expect(files.length).to eq(1)
end
end
it 'has sample.rb in "Ungrouped" group' do
expect(File.basename(subject.groups["Ungrouped"].first.filename)).to eq("sample.rb")
end
it "returns all groups as instances of SimpleCov::FileList" do
subject.groups.each_value do |files|
expect(files).to be_a SimpleCov::FileList
end
end
end
describe ".from_hash" do
let(:other_result) do
{
source_fixture("sample.rb") => {"lines" => [nil, 1, 1, 1, nil, nil, 0, 0, nil, nil]}
}
end
let(:created_at) { Time.now.to_i }
it "can consume multiple commands" do
input = {
"rspec" => {
"coverage" => original_result,
"timestamp" => created_at
},
"cucumber" => {
"coverage" => other_result,
"timestamp" => created_at
}
}
result = described_class.from_hash(input)
expect(result.size).to eq 2
sorted = result.sort_by(&:command_name)
expect(sorted.map(&:command_name)).to eq %w[cucumber rspec]
expect(sorted.map(&:created_at).map(&:to_i)).to eq [created_at, created_at]
expect(sorted.map(&:original_result)).to eq [other_result, original_result]
end
end
end
end
simplecov-0.22.0/spec/return_codes_spec.rb 0000664 0000000 0000000 00000003631 14351411403 0020560 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
require "helper"
# Make sure that exit codes of tests are propagated properly
# See https://github.com/simplecov-ruby/simplecov/issues/5
describe "return codes" do
context "inside fixtures/frameworks" do
around do |test|
Dir.chdir(File.join(File.dirname(__FILE__), "fixtures", "frameworks")) do
FileUtils.rm_rf("./coverage")
test.call
end
end
before do
@stdout, @stderr, @status = Open3.capture3(command)
end
shared_examples "good tests" do
it "has a zero exit status" do
expect(@status.exitstatus).to be_zero
end
it "prints nothing to STDERR" do
expect(@stderr).to be_empty
end
end
shared_examples "bad tests" do
context "with default configuration" do
it "has a non-zero exit status" do
expect(@status.exitstatus).not_to be_zero
end
it "prints a message to STDERR" do
expect(@stderr).to match(/stopped.+SimpleCov.+previous.+error/i)
end
end
context "when print_error_status is disabled" do
let(:command) { "PRINT_ERROR_STATUS=false #{super()}" }
it "has a non-zero exit status" do
expect(@status.exitstatus).not_to be_zero
end
it "does not print anything to STDERR" do
expect(@stderr).to be_empty
end
end
end
context "when running testunit_good.rb" do
let(:command) { "ruby testunit_good.rb" }
it_behaves_like "good tests"
end
context "when running rspec_good.rb" do
let(:command) { "rspec rspec_good.rb" }
it_behaves_like "good tests"
end
context "when running testunit_bad.rb" do
let(:command) { "ruby testunit_bad.rb" }
it_behaves_like "bad tests"
end
context "when running rspec_bad.rb" do
let(:command) { "rspec rspec_bad.rb" }
it_behaves_like "bad tests"
end
end
end
simplecov-0.22.0/spec/simplecov_spec.rb 0000664 0000000 0000000 00000024441 14351411403 0020067 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
require "helper"
require "coverage"
describe SimpleCov do
describe ".result" do
before do
SimpleCov.clear_result
allow(Coverage).to receive(:result).once.and_return({})
end
context "with merging disabled" do
before do
allow(SimpleCov).to receive(:use_merging).once.and_return(false)
expect(SimpleCov).to_not receive(:wait_for_other_processes)
end
context "when not running" do
before do
allow(SimpleCov).to receive(:running).and_return(false)
end
it "returns nil" do
expect(SimpleCov.result).to be_nil
end
end
context "when running" do
before do
allow(SimpleCov).to receive(:running).and_return(true, false)
end
it "uses the result from Coverage" do
expect(Coverage).to receive(:result).once.and_return(__FILE__ => [0, 1])
expect(SimpleCov.result.filenames).to eq [__FILE__]
end
it "adds not-loaded-files" do
expect(SimpleCov).to receive(:add_not_loaded_files).once.and_return({})
SimpleCov.result
end
it "doesn't store the current coverage" do
expect(SimpleCov::ResultMerger).not_to receive(:store_result)
SimpleCov.result
end
it "doesn't merge the result" do
expect(SimpleCov::ResultMerger).not_to receive(:merged_result)
SimpleCov.result
end
it "caches its result" do
result = SimpleCov.result
expect(SimpleCov.result).to be(result)
end
end
end
context "with merging enabled" do
let(:the_merged_result) { double }
before do
allow(SimpleCov).to receive(:use_merging).once.and_return(true)
allow(SimpleCov::ResultMerger).to receive(:store_result).once
allow(SimpleCov::ResultMerger).to receive(:merged_result).once.and_return(the_merged_result)
expect(SimpleCov).to receive(:wait_for_other_processes)
end
context "when not running" do
before do
allow(SimpleCov).to receive(:running).and_return(false)
end
it "merges the result" do
expect(SimpleCov.result).to be(the_merged_result)
end
end
context "when running" do
before do
allow(SimpleCov).to receive(:running).and_return(true, false)
end
it "uses the result from Coverage" do
expect(Coverage).to receive(:result).once.and_return({})
SimpleCov.result
end
it "adds not-loaded-files" do
expect(SimpleCov).to receive(:add_not_loaded_files).once.and_return({})
SimpleCov.result
end
it "stores the current coverage" do
expect(SimpleCov::ResultMerger).to receive(:store_result).once
SimpleCov.result
end
it "merges the result" do
expect(SimpleCov.result).to be(the_merged_result)
end
it "caches its result" do
result = SimpleCov.result
expect(SimpleCov.result).to be(result)
end
end
end
end
describe ".exit_status_from_exception" do
context "when no exception has occurred" do
it "returns nil" do
expect(SimpleCov.exit_status_from_exception).to eq(nil)
end
end
context "when a SystemExit has occurred" do
it "returns the SystemExit status" do
raise SystemExit, 1
rescue SystemExit
expect(SimpleCov.exit_status_from_exception).to eq(1)
end
end
context "when a non SystemExit occurs" do
it "return SimpleCov::ExitCodes::EXCEPTION" do
raise "no system exit"
rescue StandardError
expect(SimpleCov.exit_status_from_exception).to eq(SimpleCov::ExitCodes::EXCEPTION)
end
end
end
describe ".process_result" do
let(:result) { SimpleCov::Result.new({}) }
context "when minimum coverage is 100%" do
before do
allow(SimpleCov).to receive(:minimum_coverage).and_return(line: 100)
allow(SimpleCov).to receive(:result?).and_return(true)
end
context "when actual coverage is almost 100%" do
before do
allow(result).to receive(:coverage_statistics).and_return(line: double("statistics", percent: 100 * 32_847.0 / 32_848))
end
it "return SimpleCov::ExitCodes::MINIMUM_COVERAGE" do
expect(
SimpleCov.process_result(result)
).to eq(SimpleCov::ExitCodes::MINIMUM_COVERAGE)
end
end
context "when actual coverage is exactly 100%" do
before do
allow(result).to receive(:covered_percent).and_return(100.0)
allow(result).to receive(:coverage_statistics).and_return(
line: double("statistics", percent: 100.0)
)
allow(result).to receive(:covered_percentages).and_return([])
allow(SimpleCov::LastRun).to receive(:read).and_return(nil)
end
it "return SimpleCov::ExitCodes::SUCCESS" do
expect(
SimpleCov.process_result(result)
).to eq(SimpleCov::ExitCodes::SUCCESS)
end
end
context "branch coverage" do
before do
allow(SimpleCov).to receive(:minimum_coverage).and_return(branch: 90)
allow(SimpleCov).to receive(:result?).and_return(true)
end
it "errors out when the coverage is too low" do
allow(result).to receive(:coverage_statistics).and_return(branch: double("statistics", percent: 89.99))
expect(
SimpleCov.process_result(result)
).to eq(SimpleCov::ExitCodes::MINIMUM_COVERAGE)
end
end
end
end
describe ".collate" do
let(:resultset1) do
{source_fixture("sample.rb") => {"lines" => [nil, 1, 1, 1, nil, nil, 1, 1, nil, nil]}}
end
let(:resultset2) do
{source_fixture("sample.rb") => {"lines" => [1, nil, 1, 1, nil, nil, 1, 1, nil, nil]}}
end
let(:resultset_path) { SimpleCov::ResultMerger.resultset_path }
let(:resultset_folder) { File.dirname(resultset_path) }
let(:merged_result) do
{
"result1, result2" => {
"coverage" => {
source_fixture("sample.rb") => {
"lines" => [1, 1, 2, 2, nil, nil, 2, 2, nil, nil]
}
}
}
}
end
let(:collated) do
JSON.parse(File.read(resultset_path)).transform_values { |v| v.reject { |k| k == "timestamp" } }
end
context "when no files to be merged" do
it "shows an error message" do
expect do
glob = Dir.glob("#{resultset_folder}/*.final", File::FNM_DOTMATCH)
SimpleCov.collate glob
end.to raise_error("There are no reports to be merged")
end
end
context "when files to be merged" do
before do
expect(SimpleCov).to receive(:run_exit_tasks!)
end
context "and a single report to be merged" do
before do
create_mergeable_report("result1", resultset1)
end
after do
clear_mergeable_reports
end
it "creates a merged report identical to the original" do
glob = Dir.glob("#{resultset_folder}/*.final", File::FNM_DOTMATCH)
SimpleCov.collate glob
expected = {"result1" => {"coverage" => resultset1}}
expect(collated).to eq(expected)
end
end
context "and multiple reports to be merged" do
before do
create_mergeable_report("result1", resultset1)
create_mergeable_report("result2", resultset2)
end
after do
clear_mergeable_reports
end
it "creates a merged report" do
glob = Dir.glob("#{resultset_folder}/*.final", File::FNM_DOTMATCH)
SimpleCov.collate glob
expect(collated).to eq(merged_result)
end
end
context "and multiple reports to be merged, one of them outdated" do
before do
create_mergeable_report("result1", resultset1)
create_mergeable_report("result2", resultset2, outdated: true)
end
after do
clear_mergeable_reports
end
it "ignores timeout by default creating a report with all values" do
glob = Dir.glob("#{resultset_folder}/*.final", File::FNM_DOTMATCH)
SimpleCov.collate glob
expect(collated).to eq(merged_result)
end
it "creates a merged report with only the results from the current resultset if ignore_timeout: false" do
glob = Dir.glob("#{resultset_folder}/*.final", File::FNM_DOTMATCH)
SimpleCov.collate glob, ignore_timeout: false
expected = {"result1" => {"coverage" => resultset1}}
expect(collated).to eq(expected)
end
end
private
def create_mergeable_report(name, resultset, outdated: false)
result = SimpleCov::Result.new(resultset)
result.command_name = name
result.created_at = Time.now - 172_800 if outdated
SimpleCov::ResultMerger.store_result(result)
FileUtils.mv resultset_path, "#{resultset_path}#{name}.final"
end
def clear_mergeable_reports
SimpleCov.clear_result
FileUtils.rm Dir.glob("#{resultset_path}*")
end
def expect_merged
expected = {"result1, result2" => {"coverage" => {source_fixture("sample.rb") => {"lines" => [1, 1, 2, 2, nil, nil, 2, 2, nil, nil]}}}}
expect(collated).to eq(expected)
end
end
end
# Normally wouldn't test private methods but just start has side effects that
# cause errors so for time this is pragmatic (tm)
describe ".start_coverage_measurement", if: SimpleCov.coverage_start_arguments_supported? do
after :each do
# SimpleCov is a Singleton/global object so once any test enables
# any kind of coverage data it stays there.
# Hence, we use clear_coverage_data to create a "clean slate" for these tests
SimpleCov.clear_coverage_criteria
end
it "starts coverage in lines mode by default" do
expect(Coverage).to receive(:start).with(lines: true)
SimpleCov.send :start_coverage_measurement
end
it "starts coverage with lines and branches if branches is activated" do
expect(Coverage).to receive(:start).with(lines: true, branches: true)
SimpleCov.enable_coverage :branch
SimpleCov.send :start_coverage_measurement
end
end
end
simplecov-0.22.0/spec/source_file/ 0000775 0000000 0000000 00000000000 14351411403 0017021 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/spec/source_file/branch_spec.rb 0000664 0000000 0000000 00000005604 14351411403 0021622 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
require "helper"
describe SimpleCov::SourceFile::Branch do
let(:if_branch) do
described_class.new(start_line: 1, end_line: 3, coverage: 0, inline: false, type: :then)
end
let(:else_branch) do
described_class.new(start_line: 1, end_line: 3, coverage: 0, inline: false, type: :else)
end
context "a source branch if..else" do
it "correct branch report" do
expect(if_branch.report).to eq([:then, 0])
expect(else_branch.report).to eq([:else, 0])
end
end
context "A source branch with coverage" do
let(:covered_branch) do
described_class.new(start_line: 1, end_line: 3, coverage: 1, inline: false, type: :then)
end
it "is covered" do
expect(covered_branch).to be_covered
end
it "is neither covered not missed if skipped" do
covered_branch.skipped!
expect(covered_branch).not_to be_covered
expect(covered_branch).not_to be_missed
end
it "is not missed" do
expect(covered_branch).not_to be_missed
end
end
context "a source branch without coverage" do
let(:uncovered_branch) do
described_class.new(start_line: 1, end_line: 3, coverage: 0, inline: false, type: :then)
end
it "isn't covered" do
expect(uncovered_branch).not_to be_covered
end
it "is missed" do
expect(uncovered_branch).to be_missed
end
it "is neither covered not missed if skipped" do
uncovered_branch.skipped!
expect(uncovered_branch).not_to be_covered
expect(uncovered_branch).not_to be_missed
end
end
describe "skipping lines" do
subject { described_class.new(start_line: 5, end_line: 7, coverage: 0, inline: false, type: :then) }
it "isn't skipped by default" do
expect(subject).not_to be_skipped
end
it "can be skipped" do
subject.skipped!
expect(subject).to be_skipped
end
end
describe "#overlaps_with?(range)" do
subject { described_class.new(start_line: 5, end_line: 7, coverage: 0, inline: false, type: :then) }
it "doesn't overlap with a range beyond its lines" do
expect(subject.overlaps_with?(8..10)).to eq false
end
it "doesn't overlap with a range before its lines" do
expect(subject.overlaps_with?(3..4)).to eq false
end
it "overlaps with a range that fully includes everything" do
expect(subject.overlaps_with?(1..100)).to eq true
end
it "overlaps with a range that exactly includes it" do
expect(subject.overlaps_with?(5..7)).to eq true
end
it "overlaps with a range that partially includes its beginning" do
expect(subject.overlaps_with?(1..5)).to eq true
end
it "overlaps with a range that partially includes its end" do
expect(subject.overlaps_with?(7..10)).to eq true
end
it "overlaps with a range that pends in its middle" do
expect(subject.overlaps_with?(1..6)).to eq true
end
end
end
simplecov-0.22.0/spec/source_file/line_spec.rb 0000664 0000000 0000000 00000006642 14351411403 0021317 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
require "helper"
describe SimpleCov::SourceFile::Line do
context "a source line" do
subject do
SimpleCov::SourceFile::Line.new("# the ruby source", 5, 3)
end
it 'returns "# the ruby source" as src' do
expect(subject.src).to eq("# the ruby source")
end
it "returns the same for source as for src" do
expect(subject.src).to eq(subject.source)
end
it "has line number 5" do
expect(subject.line_number).to eq(5)
end
it "has equal line_number, line and number" do
expect(subject.line).to eq(subject.line_number)
expect(subject.number).to eq(subject.line_number)
end
context "flagged as skipped!" do
before do
subject.skipped!
end
it "is not covered" do
expect(subject).not_to be_covered
end
it "is skipped" do
expect(subject).to be_skipped
end
it "is not missed" do
expect(subject).not_to be_missed
end
it "is not never" do
expect(subject).not_to be_never
end
it "status is skipped" do
expect(subject.status).to eq("skipped")
end
end
end
context "A source line with coverage" do
subject do
SimpleCov::SourceFile::Line.new("# the ruby source", 5, 3)
end
it "has coverage of 3" do
expect(subject.coverage).to eq(3)
end
it "is covered" do
expect(subject).to be_covered
end
it "is not skipped" do
expect(subject).not_to be_skipped
end
it "is not missed" do
expect(subject).not_to be_missed
end
it "is not never" do
expect(subject).not_to be_never
end
it "status is covered" do
expect(subject.status).to eq("covered")
end
end
context "A source line without coverage" do
subject do
SimpleCov::SourceFile::Line.new("# the ruby source", 5, 0)
end
it "has coverage of 0" do
expect(subject.coverage).to be_zero
end
it "is not covered" do
expect(subject).not_to be_covered
end
it "is not skipped" do
expect(subject).not_to be_skipped
end
it "is missed" do
expect(subject).to be_missed
end
it "is not never" do
expect(subject).not_to be_never
end
it "status is missed" do
expect(subject.status).to eq("missed")
end
end
context "A source line with no code" do
subject do
SimpleCov::SourceFile::Line.new("# the ruby source", 5, nil)
end
it "has nil coverage" do
expect(subject.coverage).to be_nil
end
it "is not covered" do
expect(subject).not_to be_covered
end
it "is not skipped" do
expect(subject).not_to be_skipped
end
it "is not missed" do
expect(subject).not_to be_missed
end
it "is never" do
expect(subject).to be_never
end
it "status is never" do
expect(subject.status).to eq("never")
end
end
it "raises ArgumentError when initialized with invalid src" do
expect { SimpleCov::SourceFile::Line.new(:symbol, 5, 3) }.to raise_error(ArgumentError)
end
it "raises ArgumentError when initialized with invalid line_number" do
expect { SimpleCov::SourceFile::Line.new("some source", "five", 3) }.to raise_error(ArgumentError)
end
it "raises ArgumentError when initialized with invalid coverage" do
expect { SimpleCov::SourceFile::Line.new("some source", 5, "three") }.to raise_error(ArgumentError)
end
end
simplecov-0.22.0/spec/source_file_spec.rb 0000664 0000000 0000000 00000056720 14351411403 0020372 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
require "helper"
describe SimpleCov::SourceFile do
COVERAGE_FOR_SAMPLE_RB = {
"lines" => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil, nil, 1, 0, nil, nil, nil],
"branches" => {}
}.freeze
COVERAGE_FOR_SAMPLE_RB_WITH_MORE_LINES = {
"lines" => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil, nil, nil, nil, nil, nil, nil, nil]
}.freeze
context "a source file initialized with some coverage data" do
subject do
SimpleCov::SourceFile.new(source_fixture("sample.rb"), COVERAGE_FOR_SAMPLE_RB)
end
it "has a filename" do
expect(subject.filename).not_to be_nil
end
it "has source equal to src" do
expect(subject.src).to eq(subject.source)
end
it "has a project filename which removes the project directory" do
expect(subject.project_filename).to eq("/spec/fixtures/sample.rb")
end
it "has source_lines equal to lines" do
expect(subject.lines).to eq(subject.source_lines)
end
it "has 16 source lines" do
expect(subject.lines.count).to eq(16)
end
it "has all source lines of type SimpleCov::SourceFile::Line" do
subject.lines.each do |line|
expect(line).to be_a SimpleCov::SourceFile::Line
end
end
it "has 'class Foo' as line(2).source" do
expect(subject.line(2).source).to eq("class Foo\n")
end
describe "line coverage" do
it "returns lines number 2, 3, 4, 7 for covered_lines" do
expect(subject.covered_lines.map(&:line)).to eq([2, 3, 4, 7])
end
it "returns lines number 8 for missed_lines" do
expect(subject.missed_lines.map(&:line)).to eq([8])
end
it "returns lines number 1, 5, 6, 9, 10, 16 for never_lines" do
expect(subject.never_lines.map(&:line)).to eq([1, 5, 6, 9, 10, 16])
end
it "returns line numbers 11, 12, 13, 14, 15 for skipped_lines" do
expect(subject.skipped_lines.map(&:line)).to eq([11, 12, 13, 14, 15])
end
it "has 80% covered_percent" do
expect(subject.covered_percent).to eq(80.0)
end
end
describe "branch coverage" do
it "has total branches count 0" do
expect(subject.total_branches.size).to eq(0)
end
it "has covered branches count 0" do
expect(subject.covered_branches.size).to eq(0)
end
it "has missed branches count 0" do
expect(subject.missed_branches.size).to eq(0)
end
it "is considered 100% branches covered" do
expect(subject.branches_coverage_percent).to eq(100.0)
end
it "has branch coverage report" do
expect(subject.branches_report).to eq({})
end
end
end
context "file with branches" do
COVERAGE_FOR_BRANCHES_RB = {
"lines" => [1, 1, 1, nil, 1, nil, 1, 0, nil, 1, nil, nil, nil],
"branches" => {
[:if, 0, 3, 4, 3, 21] =>
{[:then, 1, 3, 4, 3, 10] => 0, [:else, 2, 3, 4, 3, 21] => 1},
[:if, 3, 5, 4, 5, 26] =>
{[:then, 4, 5, 16, 5, 20] => 1, [:else, 5, 5, 23, 5, 26] => 0},
[:if, 6, 7, 4, 11, 7] =>
{[:then, 7, 8, 6, 8, 10] => 0, [:else, 8, 10, 6, 10, 9] => 1}
}
}.freeze
subject do
SimpleCov::SourceFile.new(source_fixture("branches.rb"), COVERAGE_FOR_BRANCHES_RB)
end
describe "branch coverage" do
it "has 50% branch coverage" do
expect(subject.branches_coverage_percent).to eq 50.0
end
it "has total branches count 6" do
expect(subject.total_branches.size).to eq(6)
end
it "has covered branches count 3" do
expect(subject.covered_branches.size).to eq(3)
end
it "has missed branches count 3" do
expect(subject.missed_branches.size).to eq(3)
end
it "has coverage report" do
expect(subject.branches_report).to eq(
3 => [[:then, 0], [:else, 1]],
5 => [[:then, 1], [:else, 0]],
7 => [[:then, 0]],
9 => [[:else, 1]]
)
end
it "has line 7 with missed branches branch" do
expect(subject.line_with_missed_branch?(7)).to eq(true)
end
it "has line 3 with missed branches branch" do
expect(subject.line_with_missed_branch?(3)).to eq(true)
end
end
describe "line coverage" do
it "has line coverage" do
expect(subject.covered_percent).to be_within(0.01).of(85.71)
end
it "has 6 covered lines" do
expect(subject.covered_lines.size).to eq 6
end
it "has 1 missed line" do
expect(subject.missed_lines.size).to eq 1
end
it "has 7 relevant lines" do
expect(subject.relevant_lines).to eq 7
end
end
end
context "simulating potential Ruby 1.9 defect -- see Issue #56" do
subject do
SimpleCov::SourceFile.new(source_fixture("sample.rb"), COVERAGE_FOR_SAMPLE_RB_WITH_MORE_LINES)
end
it "has 16 source lines regardless of extra data in coverage array" do
# Do not litter test output with known warning
capture_stderr { expect(subject.lines.count).to eq(16) }
end
it "prints a warning to stderr if coverage array contains more data than lines in the file" do
captured_output = capture_stderr do
subject.lines
end
expect(captured_output).to match(/^Warning: coverage data provided/)
end
end
context "A file that has inline branches" do
COVERAGE_FOR_INLINE = {
"lines" => [1, 1, 1, nil, 1, 1, 0, nil, 1, nil, nil, nil, nil],
"branches" => {
[:if, 0, 3, 11, 3, 33] =>
{[:then, 1, 3, 23, 3, 27] => 1, [:else, 2, 3, 30, 3, 33] => 0},
[:if, 3, 6, 6, 10, 9] =>
{[:then, 4, 7, 8, 7, 12] => 0, [:else, 5, 9, 8, 9, 11] => 1}
}
}.freeze
subject do
SimpleCov::SourceFile.new(source_fixture("inline.rb"), COVERAGE_FOR_INLINE)
end
it "has branches report on 3 lines" do
expect(subject.branches_report.keys.size).to eq(3)
expect(subject.branches_report.keys).to eq([3, 6, 8])
end
it "has covered branches count 2" do
expect(subject.covered_branches.size).to eq(2)
end
it "has dual element in condition at line 3 report" do
expect(subject.branches_report[3]).to eq([[:then, 1], [:else, 0]])
end
it "has branches coverage percent 50.00" do
expect(subject.branches_coverage_percent).to eq(50.00)
end
end
context "a file that is never relevant" do
COVERAGE_FOR_NEVER_RB = {"lines" => [nil, nil], "branches" => {}}.freeze
subject do
SimpleCov::SourceFile.new(source_fixture("never.rb"), COVERAGE_FOR_NEVER_RB)
end
it "has 0.0 covered_strength" do
expect(subject.covered_strength).to eq 0.0
end
it "has 100.0 covered_percent" do
expect(subject.covered_percent).to eq 100.0
end
it "has 100.0 branch coverage" do
expect(subject.branches_coverage_percent).to eq(100.00)
end
end
context "a file where nothing is ever executed mixed with skipping #563" do
COVERAGE_FOR_SKIPPED_RB = {"lines" => [nil, nil, nil, nil]}.freeze
subject do
SimpleCov::SourceFile.new(source_fixture("skipped.rb"), COVERAGE_FOR_SKIPPED_RB)
end
it "has 0.0 covered_strength" do
expect(subject.covered_strength).to eq 0.0
end
it "has 0.0 covered_percent" do
expect(subject.covered_percent).to eq 100.0
end
end
context "a file where everything is skipped and missed #563" do
COVERAGE_FOR_SKIPPED_RB_2 = {"lines" => [nil, nil, 0, nil]}.freeze
subject do
SimpleCov::SourceFile.new(source_fixture("skipped.rb"), COVERAGE_FOR_SKIPPED_RB_2)
end
it "has 0.0 covered_strength" do
expect(subject.covered_strength).to eq 0.0
end
it "has 0.0 covered_percent" do
expect(subject.covered_percent).to eq 100.0
end
it "has no covered or missed lines" do
expect(subject.covered_lines).to be_empty
expect(subject.missed_lines).to be_empty
end
end
context "a file where everything is skipped/irrelevant but executed #563" do
COVERAGE_FOR_SKIPPED_AND_EXECUTED_RB = {
"lines" => [nil, nil, 1, 1, 0, 0, nil, 0, nil, nil, nil, nil],
"branches" => {
[:if, 0, 5, 4, 9, 7] =>
{[:then, 1, 6, 6, 6, 7] => 1, [:else, 2, 8, 6, 8, 7] => 0}
}
}.freeze
subject do
SimpleCov::SourceFile.new(source_fixture("skipped_and_executed.rb"), COVERAGE_FOR_SKIPPED_AND_EXECUTED_RB)
end
describe "line coverage" do
it "has no relevant lines" do
expect(subject.relevant_lines).to eq(0)
end
it "has no covered lines" do
expect(subject.covered_lines.size).to eq(0)
end
it "has no missed lines" do
expect(subject.missed_lines.size).to eq(0)
end
it "has a whole lot of skipped lines" do
expect(subject.skipped_lines.size).to eq(11)
end
it "has 0.0 covered_strength" do
expect(subject.covered_strength).to eq 0.0
end
it "has 0.0 covered_percent" do
expect(subject.covered_percent).to eq 100.0
end
end
describe "branch coverage" do
it "has an empty branch report" do
expect(subject.branches_report).to eq({})
end
it "has no branches" do
expect(subject.total_branches.size).to eq 0
expect(subject.no_branches?).to eq true
end
it "does has neither covered nor missed branches" do
expect(subject.missed_branches.size).to eq 0
expect(subject.covered_branches.size).to eq 0
end
end
end
context "a file with more complex skipping" do
COVERAGE_FOR_NOCOV_COMPLEX_RB = {
"lines" => [nil, nil, 1, 1, nil, 1, nil, nil, nil, 1, nil, nil, 1, nil, nil, 0, nil, 1, nil, 0, nil, nil, 1, nil, nil, nil, nil],
"branches" => {
[:if, 0, 6, 4, 11, 7] =>
{[:then, 1, 7, 6, 7, 7] => 0, [:else, 2, 10, 6, 10, 7] => 1},
[:if, 3, 13, 4, 13, 24] =>
{[:then, 4, 13, 4, 13, 12] => 1, [:else, 5, 13, 4, 13, 24] => 0},
[:while, 6, 16, 4, 16, 27] =>
{[:body, 7, 16, 4, 16, 12] => 2},
[:case, 8, 18, 4, 24, 7] => {
[:when, 9, 20, 6, 20, 11] => 0,
[:when, 10, 23, 6, 23, 10] => 1,
[:else, 11, 18, 4, 24, 7] => 0
}
}
}.freeze
subject do
SimpleCov::SourceFile.new(source_fixture("nocov_complex.rb"), COVERAGE_FOR_NOCOV_COMPLEX_RB)
end
describe "line coverage" do
it "has 6 relevant lines" do
expect(subject.relevant_lines).to eq(5)
end
it "has 6 covered lines" do
expect(subject.covered_lines.size).to eq(5)
end
it "has no missed lines" do
expect(subject.missed_lines.size).to eq(0)
end
it "has a whole lot of skipped lines" do
expect(subject.skipped_lines.size).to eq(11)
end
it "has 100.0 covered_percent" do
expect(subject.covered_percent).to eq 100.0
end
end
describe "branch coverage" do
it "has an empty branch report" do
expect(subject.branches_report).to eq(
9 => [[:else, 1]],
13 => [[:then, 1], [:else, 0]],
22 => [[:when, 1]]
)
end
it "covers 3/4 branches" do
expect(subject.total_branches.size).to eq 4
expect(subject.missed_branches.size).to eq 1
expect(subject.covered_branches.size).to eq 3
end
end
end
context "a file with nested branches" do
COVERAGE_FOR_NESTED_BRANCHES_RB = {
"lines" => [nil, nil, 1, 1, 1, 1, 1, 1, nil, nil, 0, nil, nil, nil, nil],
"branches" => {
[:while, 0, 7, 8, 7, 31] =>
{[:body, 1, 7, 8, 7, 16] => 2},
[:if, 2, 6, 6, 9, 9] =>
{[:then, 3, 7, 8, 8, 11] => 1, [:else, 4, 6, 6, 9, 9] => 0},
[:if, 5, 5, 4, 12, 7] =>
{[:then, 6, 6, 6, 9, 9] => 1, [:else, 7, 11, 6, 11, 11] => 0}
}
}.freeze
subject do
SimpleCov::SourceFile.new(source_fixture("nested_branches.rb"), COVERAGE_FOR_NESTED_BRANCHES_RB)
end
describe "line coverage" do
it "covers 6/7" do
expect(subject.covered_percent).to be_within(0.01).of(85.71)
end
end
describe "branch coverage" do
it "covers 3/5" do
expect(subject.total_branches.size).to eq 5
expect(subject.covered_branches.size).to eq 3
expect(subject.missed_branches.size).to eq 2
end
it "registered 2 hits for the while branch" do
expect(subject.branches_report[7]).to eq [[:body, 2]]
end
end
end
context "a file with case" do
COVERAGE_FOR_CASE_STATEMENT_RB = {
"lines" => [1, 1, 1, nil, 0, nil, 1, nil, 0, nil, 0, nil, nil, nil],
"branches" => {
[:case, 0, 3, 4, 12, 7] => {
[:when, 1, 5, 6, 5, 10] => 0,
[:when, 2, 7, 6, 7, 10] => 1,
[:when, 3, 9, 6, 9, 10] => 0,
[:else, 4, 11, 6, 11, 11] => 0
}
}
}.freeze
subject do
SimpleCov::SourceFile.new(source_fixture("case.rb"), COVERAGE_FOR_CASE_STATEMENT_RB)
end
describe "line coverage" do
it "covers 4/7" do
expect(subject.relevant_lines).to eq 7
expect(subject.covered_lines.size).to eq 4
expect(subject.missed_lines.size).to eq 3
end
end
describe "branch coverage" do
it "covers 1/4" do
expect(subject.total_branches.size).to eq 4
expect(subject.covered_branches.size).to eq 1
expect(subject.missed_branches.size).to eq 3
end
it "covers all the things right" do
expect(subject.branches_report).to eq(
4 => [[:when, 0]],
6 => [[:when, 1]],
8 => [[:when, 0]],
10 => [[:else, 0]]
)
end
end
end
context "a file with case without else" do
COVERAGE_FOR_CASE_WITHOUT_ELSE_STATEMENT_RB = {
"lines" => [1, 1, 1, nil, 0, nil, 1, nil, 0, nil, nil, nil],
"branches" => {
[:case, 0, 3, 4, 10, 7] => {
[:when, 1, 5, 6, 5, 10] => 0,
[:when, 2, 7, 6, 7, 10] => 1,
[:when, 3, 9, 6, 9, 10] => 0,
[:else, 4, 3, 4, 10, 7] => 0
}
}
}.freeze
subject do
SimpleCov::SourceFile.new(source_fixture("case_without_else.rb"), COVERAGE_FOR_CASE_WITHOUT_ELSE_STATEMENT_RB)
end
describe "line coverage" do
it "covers 4/6" do
expect(subject.relevant_lines).to eq 6
expect(subject.covered_lines.size).to eq 4
expect(subject.missed_lines.size).to eq 2
end
end
describe "branch coverage" do
it "covers 1/4 (counting the else branch)" do
expect(subject.total_branches.size).to eq 4
expect(subject.covered_branches.size).to eq 1
expect(subject.missed_branches.size).to eq 3
end
it "marks the non declared else branch as missing at the point of the case" do
expect(subject.branches_for_line(3)).to eq [[:else, 0]]
end
it "covers the branch that includes 42" do
expect(subject.branches_report).to eq(
3 => [[:else, 0]],
4 => [[:when, 0]],
6 => [[:when, 1]],
8 => [[:when, 0]]
)
end
end
end
context "a file with if/elsif" do
COVERAGE_FOR_ELSIF_RB = {
"lines" => [1, 1, 1, 0, 1, 0, 1, 1, nil, 0, nil, nil, nil],
"branches" => {
[:if, 0, 7, 4, 10, 10] =>
{[:then, 1, 8, 6, 8, 10] => 1, [:else, 2, 10, 6, 10, 10] => 0},
[:if, 3, 5, 4, 10, 10] =>
{[:then, 4, 6, 6, 6, 10] => 0, [:else, 5, 7, 4, 10, 10] => 1},
[:if, 6, 3, 4, 11, 7] =>
{[:then, 7, 4, 6, 4, 10] => 0, [:else, 8, 5, 4, 10, 10] => 1}
}
}.freeze
subject do
SimpleCov::SourceFile.new(source_fixture("elsif.rb"), COVERAGE_FOR_ELSIF_RB)
end
describe "line coverage" do
it "covers 6/9" do
expect(subject.relevant_lines).to eq 9
expect(subject.covered_lines.size).to eq 6
expect(subject.missed_lines.size).to eq 3
end
end
describe "branch coverage" do
it "covers 3/6" do
expect(subject.total_branches.size).to eq 6
expect(subject.covered_branches.size).to eq 3
expect(subject.missed_branches.size).to eq 3
end
it "covers the branch that includes 42" do
expect(subject.branches_report[7]).to eq [[:then, 1]]
end
end
end
context "the branch tester script" do
COVERAGE_FOR_BRANCH_TESTER_RB = {
"lines" => [nil, nil, 1, 1, nil, 1, nil, 1, 1, nil, nil, 1, 0, nil, nil, 1, 0, nil, 1, nil, nil, 1, 1, 1, nil, nil, 1, 0, nil, nil, 1, 1, nil, 0, nil, 1, 1, 0, 0, 1, 5, 0, 0, nil, 0, nil, 0, nil, nil, nil],
"branches" => {
[:if, 0, 4, 0, 4, 19] =>
{[:then, 1, 4, 12, 4, 15] => 0, [:else, 2, 4, 18, 4, 19] => 1},
[:unless, 3, 6, 0, 6, 23] =>
{[:else, 4, 6, 0, 6, 23] => 0, [:then, 5, 6, 0, 6, 6] => 1},
[:unless, 6, 8, 0, 10, 3] =>
{[:else, 7, 8, 0, 10, 3] => 0, [:then, 8, 9, 2, 9, 14] => 1},
[:unless, 9, 12, 0, 14, 3] =>
{[:else, 10, 12, 0, 14, 3] => 1, [:then, 11, 13, 2, 13, 14] => 0},
[:unless, 12, 16, 0, 20, 3] =>
{[:else, 13, 19, 2, 19, 13] => 1, [:then, 14, 17, 2, 17, 14] => 0},
[:if, 15, 22, 0, 22, 19] =>
{[:then, 16, 22, 0, 22, 6] => 0, [:else, 17, 22, 0, 22, 19] => 1},
[:if, 18, 23, 0, 25, 3] =>
{[:then, 19, 24, 2, 24, 14] => 1, [:else, 20, 23, 0, 25, 3] => 0},
[:if, 21, 27, 0, 29, 3] =>
{[:then, 22, 28, 2, 28, 14] => 0, [:else, 23, 27, 0, 29, 3] => 1},
[:if, 24, 31, 0, 35, 3] =>
{[:then, 25, 32, 2, 32, 14] => 1, [:else, 26, 34, 2, 34, 13] => 0},
[:if, 27, 42, 0, 47, 8] =>
{[:then, 28, 43, 2, 45, 13] => 0, [:else, 29, 47, 2, 47, 8] => 0},
[:if, 30, 40, 0, 47, 8] =>
{[:then, 31, 41, 2, 41, 25] => 1, [:else, 32, 42, 0, 47, 8] => 0},
[:if, 33, 37, 0, 48, 3] =>
{[:then, 34, 38, 2, 39, 21] => 0, [:else, 35, 40, 0, 47, 8] => 1}
}
}.freeze
subject do
SimpleCov::SourceFile.new(source_fixture("branch_tester_script.rb"), COVERAGE_FOR_BRANCH_TESTER_RB)
end
describe "line coverage" do
it "covers 18/28" do
expect(subject.relevant_lines).to eq 28
expect(subject.covered_lines.size).to eq 18
end
end
describe "branch coverage" do
it "covers 10/24" do
expect(subject.total_branches.size).to eq 24
expect(subject.covered_branches.size).to eq 11
end
it "notifies us of the missing else branch on line 27 that's hit" do
expect(subject.branches_report[27]).to eq [[:then, 0], [:else, 1]]
end
end
end
context "a file entirely ignored with a single # :nocov:" do
COVERAGE_FOR_SINGLE_NOCOV_RB = {
"lines" => [nil, 1, 1, 1, 0, 1, 0, 1, 1, nil, 0, nil, nil, nil],
"branches" => {
[:if, 0, 8, 4, 11, 10] =>
{[:then, 1, 9, 6, 9, 10] => 1, [:else, 2, 11, 6, 11, 10] => 0},
[:if, 3, 6, 4, 11, 10] =>
{[:then, 4, 7, 6, 7, 10] => 0, [:else, 5, 8, 4, 11, 10] => 1},
[:if, 6, 4, 4, 12, 7] =>
{[:then, 7, 5, 6, 5, 10] => 0, [:else, 8, 6, 4, 11, 10] => 1}
}
}.freeze
subject do
SimpleCov::SourceFile.new(source_fixture("single_nocov.rb"), COVERAGE_FOR_SINGLE_NOCOV_RB)
end
describe "line coverage" do
it "has all lines skipped" do
expect(subject.skipped_lines.size).to eq(subject.lines.size)
expect(subject.skipped_lines.size).to eq(14)
end
it "reports 100% coverage on 0/0" do
expect(subject.covered_percent).to eq 100.0
expect(subject.relevant_lines).to eq 0
expect(subject.covered_lines.size).to eq 0
end
end
describe "branch coverage" do
it "has 100% branch coverage on 0/0" do
branch_coverage = subject.coverage_statistics.fetch(:branch)
expect(branch_coverage.percent).to eq 100.0
expect(branch_coverage.total).to eq 0
expect(branch_coverage.covered).to eq 0
end
it "has all branches marked as skipped" do
expect(subject.branches.all?(&:skipped?)).to eq true
end
end
end
context "a file with an uneven usage of # :nocov:s" do
COVERAGE_FOR_UNEVEN_NOCOV_RB = {
"lines" => [1, 1, nil, 1, 0, 1, 0, nil, 1, 1, nil, nil, 0, nil, nil, nil],
"branches" => {
[:if, 0, 9, 4, 13, 10] =>
{[:then, 1, 10, 6, 10, 10] => 1, [:else, 2, 13, 6, 13, 10] => 0},
[:if, 3, 6, 4, 13, 10] =>
{[:then, 4, 7, 6, 7, 10] => 0, [:else, 5, 9, 4, 13, 10] => 1},
[:if, 6, 4, 4, 14, 7] =>
{[:then, 7, 5, 6, 5, 10] => 0, [:else, 8, 6, 4, 13, 10] => 1}
}
}.freeze
subject do
SimpleCov::SourceFile.new(source_fixture("uneven_nocovs.rb"), COVERAGE_FOR_UNEVEN_NOCOV_RB)
end
describe "line coverage" do
it "has 12 lines skipped" do
expect(subject.skipped_lines.size).to eq(12)
end
it "reports 100% coverage on 4/4" do
expect(subject.covered_percent).to eq 100.0
expect(subject.relevant_lines).to eq 4
expect(subject.covered_lines.size).to eq 4
end
end
describe "branch coverage" do
it "has 100% branch coverage on 1/1" do
branch_coverage = subject.coverage_statistics.fetch(:branch)
expect(branch_coverage.percent).to eq 100.0
expect(branch_coverage.total).to eq 1
expect(branch_coverage.covered).to eq 1
end
it "has 5 branches marked as skipped" do
expect(subject.branches.select(&:skipped?).size).to eq 5
end
end
end
context "a file contains non-ASCII characters" do
COVERAGE_FOR_SINGLE_LINE = {"lines" => [nil]}.freeze
COVERAGE_FOR_DOUBLE_LINES = {"lines" => [nil, 1]}.freeze
COVERAGE_FOR_TRIPLE_LINES = {"lines" => [nil, nil, 1]}.freeze
DEGREE_135_LINE = "puts \"135°C\"\n"
shared_examples_for "converting to UTF-8" do
it "has all source lines of encoding UTF-8" do
subject.lines.each do |line|
expect(line.source.encoding).to eq(Encoding::UTF_8)
expect(line.source).to be_valid_encoding
end
end
end
describe "UTF-8 without magic comment" do
subject do
SimpleCov::SourceFile.new(source_fixture("utf-8.rb"), COVERAGE_FOR_SINGLE_LINE)
end
it_behaves_like "converting to UTF-8"
it "has the line with 135°C" do
expect(subject.line(1).source).to eq DEGREE_135_LINE
end
end
describe "UTF-8 with magic comment" do
subject do
SimpleCov::SourceFile.new(source_fixture("utf-8-magic.rb"), COVERAGE_FOR_DOUBLE_LINES)
end
it_behaves_like "converting to UTF-8"
it "has the line with 135°C" do
expect(subject.line(2).source).to eq DEGREE_135_LINE
end
end
describe "EUC-JP with magic comment" do
subject do
SimpleCov::SourceFile.new(source_fixture("euc-jp.rb"), COVERAGE_FOR_DOUBLE_LINES)
end
it_behaves_like "converting to UTF-8"
it "has the line with 135°C" do
expect(subject.line(2).source).to eq DEGREE_135_LINE
end
end
describe "EUC-JP with magic comment and shebang" do
subject do
SimpleCov::SourceFile.new(source_fixture("euc-jp-shebang.rb"), COVERAGE_FOR_TRIPLE_LINES)
end
it_behaves_like "converting to UTF-8"
it "has all the right lines" do
expect(subject.lines.map(&:source)).to eq [
"#!/usr/bin/env ruby\n",
"# encoding: EUC-JP\n",
DEGREE_135_LINE
]
end
end
describe "empty euc-jp file" do
subject do
SimpleCov::SourceFile.new(source_fixture("empty_euc-jp.rb"), "lines" => [])
end
it "has empty lines" do
expect(subject.lines).to be_empty
end
end
end
end
simplecov-0.22.0/spec/support/ 0000775 0000000 0000000 00000000000 14351411403 0016236 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/spec/support/fail_rspec_on_ruby_warning.rb 0000664 0000000 0000000 00000003332 14351411403 0024155 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
# Borrowed and heavily adjusted from:
# https://github.com/metricfu/metric_fu/blob/master/spec/capture_warnings.rb
require "fileutils"
class FailOnWarnings
def initialize
@stderr_stream = StringIO.new
@app_root = Dir.pwd
end
def collect_warnings
$stderr = @stderr_stream
$VERBOSE = true
end
def process_warnings
lines = close_stream
app_warnings, other_warnings = split_lines(lines)
print_own_warnings(app_warnings) if app_warnings.any?
write_other_warnings_to_tmp(other_warnings) if other_warnings.any?
fail_script(app_warnings) if app_warnings.any?
end
private
def close_stream
$stderr = STDERR
@stderr_stream.rewind
lines = @stderr_stream.read.split("\n")
lines.uniq!
@stderr_stream.close
lines
end
def split_lines(lines)
lines.partition { |line| line.include?(@app_root) }
end
def print_own_warnings(app_warnings)
puts ""
puts ""
puts <<-WARNINGS
#{'-' * 30} app warnings: #{'-' * 30}
#{app_warnings.join("\n")}
#{'-' * 75}
WARNINGS
end
def write_other_warnings_to_tmp(other_warnings)
output_dir = File.join(@app_root, "tmp")
FileUtils.mkdir_p(output_dir)
output_file = File.join(output_dir, "warnings.txt")
File.open(output_file, "w") do |file|
file.write(other_warnings.join("\n") << "\n")
end
puts
puts "Non-app warnings written to tmp/warnings.txt"
puts
end
def fail_script(app_warnings)
abort "Failing build due to app warnings: #{app_warnings.inspect}"
end
end
warning_collector = FailOnWarnings.new
warning_collector.collect_warnings
RSpec.configure do |config|
config.after(:suite) do
warning_collector.process_warnings
end
end
simplecov-0.22.0/spec/useless_results_remover_spec.rb 0000664 0000000 0000000 00000002067 14351411403 0023071 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
require "helper"
describe SimpleCov::UselessResultsRemover do
let(:gem_file_path) { "usr/bin/lib/2.5.0/gems/sample-gem/sample.rb" }
let(:source_path) { source_fixture("app/models/user.rb") }
let(:result_set) do
{
gem_file_path => {
"lines" => [nil, 1, 1, 1, nil, nil, 1, 1, nil, nil],
"branches" => {[:if, 3, 8, 6, 8, 36] => {[:then, 4, 8, 6, 8, 12] => 47, [:else, 5, 8, 6, 8, 36] => 24}}
},
source_path => {
"lines" => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil],
"branches" => {[:if, 3, 8, 6, 8, 36] => {[:then, 4, 8, 6, 8, 12] => 47, [:else, 5, 8, 6, 8, 36] => 24}}
}
}
end
subject do
SimpleCov::UselessResultsRemover.call(result_set)
end
it "Result ignore gem file path from result set" do
expect(result_set[gem_file_path]).to be_kind_of(Hash)
expect(subject).not_to have_key(gem_file_path)
end
it "still retains the app path" do
expect(subject).to have_key(source_path)
expect(subject[source_path]["lines"]).to be_kind_of(Array)
end
end
simplecov-0.22.0/test_projects/ 0000775 0000000 0000000 00000000000 14351411403 0016460 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/test_projects/encodings/ 0000775 0000000 0000000 00000000000 14351411403 0020431 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/test_projects/encodings/lib/ 0000775 0000000 0000000 00000000000 14351411403 0021177 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/test_projects/encodings/lib/euc_jp.rb 0000664 0000000 0000000 00000000165 14351411403 0022773 0 ustar 00root root 0000000 0000000 # encoding: EUC-JP
# frozen_string_literal: true
class Fun2
MSG = "¤ª¤Ï¤è¤¦"
def no_moji
"tada!"
end
end
simplecov-0.22.0/test_projects/encodings/lib/euc_jp_not_declared.rb 0000664 0000000 0000000 00000000305 14351411403 0025472 0 ustar 00root root 0000000 0000000 # 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
simplecov-0.22.0/test_projects/encodings/lib/euc_jp_not_declared_tracked.rb 0000664 0000000 0000000 00000000337 14351411403 0027174 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
# Ruby can't even execute this file but it might be added
# via track_files or similar means and we still don't wanna crash!
class NoDeclare
MSG = "¤ª¤Ï¤è¤¦"
def ??
"tada!"
end
end
simplecov-0.22.0/test_projects/encodings/lib/utf8.rb 0000664 0000000 0000000 00000000146 14351411403 0022413 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
class Fun
MSG = "ãŠã¯ã‚ˆã†"
def 🇯🇵
"tada!"
end
end
simplecov-0.22.0/test_projects/encodings/spec/ 0000775 0000000 0000000 00000000000 14351411403 0021363 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/test_projects/encodings/spec/simple_spec.rb 0000664 0000000 0000000 00000000173 14351411403 0024214 0 ustar 00root root 0000000 0000000 require_relative "spec_helper"
describe Fun do
it "call things" do
expect(subject.🇯🇵).to eq "tada!"
end
end
simplecov-0.22.0/test_projects/encodings/spec/spec_helper.rb 0000664 0000000 0000000 00000000366 14351411403 0024206 0 ustar 00root root 0000000 0000000 # 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"
simplecov-0.22.0/test_projects/faked_project/ 0000775 0000000 0000000 00000000000 14351411403 0021260 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/test_projects/faked_project/Rakefile 0000664 0000000 0000000 00000001357 14351411403 0022733 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
require "bundler"
require "rake/testtask"
Rake::TestTask.new(:test) do |test|
test.libs << "lib" << "test"
test.test_files = FileList["test/**/*_test.rb"].sort
test.verbose = true
end
Rake::TestTask.new(:part1) do |test|
test.libs << "lib"
test.test_files = FileList["test/**/*_test.rb"].sort
test.verbose = true
end
Rake::TestTask.new(:part2) do |test|
test.libs << "test"
test.test_files = FileList["test/**/*_test.rb"].sort
test.verbose = true
end
task :collate do
require "simplecov"
SimpleCov.collate Dir["coverage/resultset*.json"]
end
Rake::TestTask.new(:minitest) do |test|
test.libs << "minitest"
test.test_files = FileList["minitest/**/*_test.rb"].sort
test.verbose = true
end
simplecov-0.22.0/test_projects/faked_project/bad_spec/ 0000775 0000000 0000000 00000000000 14351411403 0023020 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/test_projects/faked_project/bad_spec/fail_with_5.rb 0000664 0000000 0000000 00000000050 14351411403 0025532 0 ustar 00root root 0000000 0000000 require_relative "spec_helper"
exit(5)
simplecov-0.22.0/test_projects/faked_project/bad_spec/failing_spec.rb 0000664 0000000 0000000 00000000154 14351411403 0025770 0 ustar 00root root 0000000 0000000 require_relative "spec_helper"
RSpec.describe "failing" do
it "fails" do
exoect(1).to eq 2
end
end
simplecov-0.22.0/test_projects/faked_project/bad_spec/spec_helper.rb 0000664 0000000 0000000 00000000165 14351411403 0025640 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
require "bundler/setup"
require "simplecov"
SimpleCov.start
require "faked_project"
simplecov-0.22.0/test_projects/faked_project/cucumber.yml 0000664 0000000 0000000 00000001147 14351411403 0023613 0 ustar 00root root 0000000 0000000 <%
rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : ""
rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}"
std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} --strict --tags 'not @wip'"
interp_opts = if defined?(RUBY_ENGINE)
" --tags 'not @exclude-#{RUBY_ENGINE}'"
else
''
end
%>
default: <%= std_opts %><%= interp_opts %> features
wip: --tags @wip:30 --wip features<%= interp_opts %>
rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags 'not @wip'<%= interp_opts %>
simplecov-0.22.0/test_projects/faked_project/features/ 0000775 0000000 0000000 00000000000 14351411403 0023076 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/test_projects/faked_project/features/step_definitions/ 0000775 0000000 0000000 00000000000 14351411403 0026444 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/test_projects/faked_project/features/step_definitions/my_steps.rb 0000664 0000000 0000000 00000001331 14351411403 0030632 0 ustar 00root root 0000000 0000000 # 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
simplecov-0.22.0/test_projects/faked_project/features/support/ 0000775 0000000 0000000 00000000000 14351411403 0024612 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/test_projects/faked_project/features/support/env.rb 0000664 0000000 0000000 00000000577 14351411403 0025740 0 ustar 00root root 0000000 0000000 # 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"
simplecov-0.22.0/test_projects/faked_project/features/test_stuff.feature 0000664 0000000 0000000 00000000257 14351411403 0026645 0 ustar 00root root 0000000 0000000 Feature: Foo
Scenario: Test stuff
Given I want to keep stuff simple
When I write my cukes for the fake project
Then I make all necessary tests in a single step
simplecov-0.22.0/test_projects/faked_project/lib/ 0000775 0000000 0000000 00000000000 14351411403 0022026 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/test_projects/faked_project/lib/faked_project.rb 0000664 0000000 0000000 00000000542 14351411403 0025154 0 ustar 00root root 0000000 0000000 # 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
simplecov-0.22.0/test_projects/faked_project/lib/faked_project/ 0000775 0000000 0000000 00000000000 14351411403 0024626 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/test_projects/faked_project/lib/faked_project/framework_specific.rb 0000664 0000000 0000000 00000000621 14351411403 0031014 0 ustar 00root root 0000000 0000000 # 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
simplecov-0.22.0/test_projects/faked_project/lib/faked_project/meta_magic.rb 0000664 0000000 0000000 00000000754 14351411403 0027247 0 ustar 00root root 0000000 0000000 # 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
simplecov-0.22.0/test_projects/faked_project/lib/faked_project/some_class.rb 0000664 0000000 0000000 00000000613 14351411403 0027303 0 ustar 00root root 0000000 0000000 # 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
simplecov-0.22.0/test_projects/faked_project/lib/faked_project/untested_class.rb 0000664 0000000 0000000 00000000325 14351411403 0030173 0 ustar 00root root 0000000 0000000 # 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
simplecov-0.22.0/test_projects/faked_project/minitest/ 0000775 0000000 0000000 00000000000 14351411403 0023114 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/test_projects/faked_project/minitest/other_test.rb 0000664 0000000 0000000 00000000732 14351411403 0025623 0 ustar 00root root 0000000 0000000 # 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
simplecov-0.22.0/test_projects/faked_project/minitest/some_test.rb 0000664 0000000 0000000 00000000476 14351411403 0025452 0 ustar 00root root 0000000 0000000 # 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
simplecov-0.22.0/test_projects/faked_project/minitest/test_helper.rb 0000664 0000000 0000000 00000000476 14351411403 0025766 0 ustar 00root root 0000000 0000000 # 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"
simplecov-0.22.0/test_projects/faked_project/spec/ 0000775 0000000 0000000 00000000000 14351411403 0022212 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/test_projects/faked_project/spec/faked_spec.rb 0000664 0000000 0000000 00000000444 14351411403 0024625 0 ustar 00root root 0000000 0000000 # 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
simplecov-0.22.0/test_projects/faked_project/spec/forking_spec.rb 0000664 0000000 0000000 00000000410 14351411403 0025203 0 ustar 00root root 0000000 0000000 # 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
simplecov-0.22.0/test_projects/faked_project/spec/meta_magic_spec.rb 0000664 0000000 0000000 00000001052 14351411403 0025635 0 ustar 00root root 0000000 0000000 # 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
simplecov-0.22.0/test_projects/faked_project/spec/some_class_spec.rb 0000664 0000000 0000000 00000000440 14351411403 0025677 0 ustar 00root root 0000000 0000000 # 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
simplecov-0.22.0/test_projects/faked_project/spec/spec_helper.rb 0000664 0000000 0000000 00000000473 14351411403 0025034 0 ustar 00root root 0000000 0000000 # 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"
simplecov-0.22.0/test_projects/faked_project/test/ 0000775 0000000 0000000 00000000000 14351411403 0022237 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/test_projects/faked_project/test/faked_test.rb 0000664 0000000 0000000 00000000434 14351411403 0024676 0 ustar 00root root 0000000 0000000 # 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
simplecov-0.22.0/test_projects/faked_project/test/meta_magic_test.rb 0000664 0000000 0000000 00000000651 14351411403 0025713 0 ustar 00root root 0000000 0000000 # 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
simplecov-0.22.0/test_projects/faked_project/test/some_class_test.rb 0000664 0000000 0000000 00000000457 14351411403 0025761 0 ustar 00root root 0000000 0000000 # 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
simplecov-0.22.0/test_projects/faked_project/test/test_helper.rb 0000664 0000000 0000000 00000000517 14351411403 0025105 0 ustar 00root root 0000000 0000000 # 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"
simplecov-0.22.0/test_projects/monorepo/ 0000775 0000000 0000000 00000000000 14351411403 0020316 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/test_projects/monorepo/Gemfile 0000664 0000000 0000000 00000000601 14351411403 0021606 0 ustar 00root root 0000000 0000000 source "https://rubygems.org"
gem "rspec"
gem "base", path: "base"
gem "extra", path: "extra"
# when the tests are executed the project is in tmp/aruba/project
# which is a different nesting from its usual place
root = File.expand_path("../..", __dir__)
unless File.exist?("#{root}/simplecov.gemspec")
root = File.expand_path("../../..", __dir__)
end
gem "simplecov", path: root
simplecov-0.22.0/test_projects/monorepo/Gemfile.lock 0000664 0000000 0000000 00000001573 14351411403 0022546 0 ustar 00root root 0000000 0000000 PATH
remote: ../..
specs:
simplecov (0.22.0)
docile (~> 1.1)
simplecov-html (~> 0.11)
simplecov_json_formatter (~> 0.1)
PATH
remote: base
specs:
base (0.0.1)
PATH
remote: extra
specs:
extra (0.0.1)
base
GEM
remote: https://rubygems.org/
specs:
diff-lcs (1.3)
docile (1.4.0)
rspec (3.9.0)
rspec-core (~> 3.9.0)
rspec-expectations (~> 3.9.0)
rspec-mocks (~> 3.9.0)
rspec-core (3.9.2)
rspec-support (~> 3.9.3)
rspec-expectations (3.9.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.9.0)
rspec-mocks (3.9.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.9.0)
rspec-support (3.9.3)
simplecov-html (0.12.3)
simplecov_json_formatter (0.1.4)
PLATFORMS
ruby
universal-java-1.8
DEPENDENCIES
base!
extra!
rspec
simplecov!
BUNDLED WITH
2.3.26
simplecov-0.22.0/test_projects/monorepo/base/ 0000775 0000000 0000000 00000000000 14351411403 0021230 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/test_projects/monorepo/base/base.gemspec 0000664 0000000 0000000 00000000574 14351411403 0023515 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
Gem::Specification.new do |gem|
gem.name = "base"
gem.version = "0.0.1"
gem.authors = ["Someone"]
gem.email = ["someonesemail"]
gem.homepage = "https://example.org"
gem.summary = "Base stuff"
gem.description = %(Base stuff, really)
gem.license = "MIT"
gem.files = ["lib/monorepo/base.rb"]
end
simplecov-0.22.0/test_projects/monorepo/base/lib/ 0000775 0000000 0000000 00000000000 14351411403 0021776 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/test_projects/monorepo/base/lib/monorepo/ 0000775 0000000 0000000 00000000000 14351411403 0023634 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/test_projects/monorepo/base/lib/monorepo/base.rb 0000664 0000000 0000000 00000000253 14351411403 0025073 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
module Monorepo
class Base
def initialize(label)
@label = label
end
def reverse
@label.reverse
end
end
end
simplecov-0.22.0/test_projects/monorepo/bin/ 0000775 0000000 0000000 00000000000 14351411403 0021066 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/test_projects/monorepo/bin/rspec_binstub_that_chdirs 0000775 0000000 0000000 00000000711 14351411403 0026231 0 ustar 00root root 0000000 0000000 #!/usr/bin/env ruby
require "bundler/setup"
if ARGV[0]
cleaned_file_path = ARGV[0].split("./").last
argument_parts = cleaned_file_path.split("/")
first_part = argument_parts[0]
if File.directory?(first_part)
Dir.chdir(first_part)
other_parts = argument_parts[1..-1]
new_args = [!other_parts.empty? ? other_parts.join("/") : nil, *ARGV[1..-1]].compact
ARGV.replace(new_args)
end
end
load Gem.bin_path("rspec-core", "rspec")
simplecov-0.22.0/test_projects/monorepo/extra/ 0000775 0000000 0000000 00000000000 14351411403 0021441 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/test_projects/monorepo/extra/extra.gemspec 0000664 0000000 0000000 00000000634 14351411403 0024134 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
Gem::Specification.new do |gem|
gem.name = "extra"
gem.version = "0.0.1"
gem.authors = ["Someone"]
gem.email = ["someonesemail"]
gem.homepage = "https://example.org"
gem.summary = "Extra stuff"
gem.description = %(Extra stuff, really)
gem.license = "MIT"
gem.add_dependency "base"
gem.files = ["lib/monorepo/extra.rb"]
end
simplecov-0.22.0/test_projects/monorepo/extra/lib/ 0000775 0000000 0000000 00000000000 14351411403 0022207 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/test_projects/monorepo/extra/lib/monorepo/ 0000775 0000000 0000000 00000000000 14351411403 0024045 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/test_projects/monorepo/extra/lib/monorepo/extra.rb 0000664 0000000 0000000 00000000342 14351411403 0025514 0 ustar 00root root 0000000 0000000 # 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
simplecov-0.22.0/test_projects/monorepo/extra/spec/ 0000775 0000000 0000000 00000000000 14351411403 0022373 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/test_projects/monorepo/extra/spec/extra_spec.rb 0000664 0000000 0000000 00000000400 14351411403 0025047 0 ustar 00root root 0000000 0000000 # 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
simplecov-0.22.0/test_projects/monorepo/extra/spec/spec_helper.rb 0000664 0000000 0000000 00000000114 14351411403 0025205 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
require "simplecov"
require "monorepo/base"
simplecov-0.22.0/test_projects/old_coverage_json/ 0000775 0000000 0000000 00000000000 14351411403 0022142 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/test_projects/old_coverage_json/.rspec 0000664 0000000 0000000 00000000026 14351411403 0023255 0 ustar 00root root 0000000 0000000 --require spec_helper
simplecov-0.22.0/test_projects/old_coverage_json/coverage/ 0000775 0000000 0000000 00000000000 14351411403 0023735 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/test_projects/old_coverage_json/coverage/.last_run.json 0000664 0000000 0000000 00000000063 14351411403 0026534 0 ustar 00root root 0000000 0000000 {
"result": {
"covered_percent": 88.89
}
}
simplecov-0.22.0/test_projects/old_coverage_json/coverage/.resultset.json 0000664 0000000 0000000 00000000673 14351411403 0026746 0 ustar 00root root 0000000 0000000 {
"RSpec Different Name to avoid overriding": {
"coverage": {
"$$path/lib/code.rb": [
null,
null,
1,
1,
1,
1,
null,
0,
null,
null,
null
],
"$$path/spec/code_spec.rb": [
null,
null,
1,
null,
1,
1,
1,
null,
null
]
},
"timestamp": 1579085826
}
}
simplecov-0.22.0/test_projects/old_coverage_json/coverage/.resultset.json.lock 0000664 0000000 0000000 00000000000 14351411403 0027655 0 ustar 00root root 0000000 0000000 simplecov-0.22.0/test_projects/old_coverage_json/lib/ 0000775 0000000 0000000 00000000000 14351411403 0022710 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/test_projects/old_coverage_json/lib/code.rb 0000664 0000000 0000000 00000000173 14351411403 0024150 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
class Code
def foo(arg)
if arg == 42
:foo
else
:bar
end
end
end
simplecov-0.22.0/test_projects/old_coverage_json/spec/ 0000775 0000000 0000000 00000000000 14351411403 0023074 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/test_projects/old_coverage_json/spec/code_spec.rb 0000664 0000000 0000000 00000000252 14351411403 0025344 0 ustar 00root root 0000000 0000000 # 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
simplecov-0.22.0/test_projects/old_coverage_json/spec/spec_helper.rb 0000664 0000000 0000000 00000000144 14351411403 0025711 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
require "simplecov"
SimpleCov.start
require_relative "../lib/code"
simplecov-0.22.0/test_projects/pagination/ 0000775 0000000 0000000 00000000000 14351411403 0020611 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/test_projects/pagination/.rspec 0000664 0000000 0000000 00000000026 14351411403 0021724 0 ustar 00root root 0000000 0000000 --require spec_helper
simplecov-0.22.0/test_projects/pagination/lib/ 0000775 0000000 0000000 00000000000 14351411403 0021357 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/test_projects/pagination/lib/a.rb 0000664 0000000 0000000 00000000026 14351411403 0022122 0 ustar 00root root 0000000 0000000 # nothing to see here
simplecov-0.22.0/test_projects/pagination/lib/b.rb 0000664 0000000 0000000 00000000000 14351411403 0022113 0 ustar 00root root 0000000 0000000 simplecov-0.22.0/test_projects/pagination/lib/c.rb 0000664 0000000 0000000 00000000000 14351411403 0022114 0 ustar 00root root 0000000 0000000 simplecov-0.22.0/test_projects/pagination/lib/d.rb 0000664 0000000 0000000 00000000000 14351411403 0022115 0 ustar 00root root 0000000 0000000 simplecov-0.22.0/test_projects/pagination/lib/e.rb 0000664 0000000 0000000 00000000000 14351411403 0022116 0 ustar 00root root 0000000 0000000 simplecov-0.22.0/test_projects/pagination/lib/f.rb 0000664 0000000 0000000 00000000000 14351411403 0022117 0 ustar 00root root 0000000 0000000 simplecov-0.22.0/test_projects/pagination/lib/g.rb 0000664 0000000 0000000 00000000000 14351411403 0022120 0 ustar 00root root 0000000 0000000 simplecov-0.22.0/test_projects/pagination/lib/h.rb 0000664 0000000 0000000 00000000000 14351411403 0022121 0 ustar 00root root 0000000 0000000 simplecov-0.22.0/test_projects/pagination/lib/i.rb 0000664 0000000 0000000 00000000000 14351411403 0022122 0 ustar 00root root 0000000 0000000 simplecov-0.22.0/test_projects/pagination/lib/j.rb 0000664 0000000 0000000 00000000000 14351411403 0022123 0 ustar 00root root 0000000 0000000 simplecov-0.22.0/test_projects/pagination/lib/k.rb 0000664 0000000 0000000 00000000000 14351411403 0022124 0 ustar 00root root 0000000 0000000 simplecov-0.22.0/test_projects/pagination/lib/l.rb 0000664 0000000 0000000 00000000026 14351411403 0022135 0 ustar 00root root 0000000 0000000 # nothing to see here
simplecov-0.22.0/test_projects/pagination/spec/ 0000775 0000000 0000000 00000000000 14351411403 0021543 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/test_projects/pagination/spec/spec_helper.rb 0000664 0000000 0000000 00000000202 14351411403 0024353 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
require "simplecov"
SimpleCov.start
Dir["lib/*.rb"].each {|file| require_relative "../#{file}" }
simplecov-0.22.0/test_projects/parallel_tests/ 0000775 0000000 0000000 00000000000 14351411403 0021476 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/test_projects/parallel_tests/.rspec 0000664 0000000 0000000 00000000026 14351411403 0022611 0 ustar 00root root 0000000 0000000 --require spec_helper
simplecov-0.22.0/test_projects/parallel_tests/Gemfile 0000664 0000000 0000000 00000000641 14351411403 0022772 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
source "https://rubygems.org"
gem "parallel_tests"
gem "rspec"
# when the tests are executed the project is in tmp/aruba/project
# which is a different nesting from its usual place
if File.exist?("../../simplecov.gemspec")
gem "simplecov", path: "../.."
else
# rubocop:disable Bundler/DuplicatedGem
gem "simplecov", path: "../../.."
# rubocop:enable Bundler/DuplicatedGem
end
simplecov-0.22.0/test_projects/parallel_tests/Gemfile.lock 0000664 0000000 0000000 00000001520 14351411403 0023716 0 ustar 00root root 0000000 0000000 PATH
remote: ../..
specs:
simplecov (0.22.0)
docile (~> 1.1)
simplecov-html (~> 0.11)
simplecov_json_formatter (~> 0.1)
GEM
remote: https://rubygems.org/
specs:
diff-lcs (1.3)
docile (1.4.0)
parallel (1.19.2)
parallel_tests (3.1.0)
parallel
rspec (3.9.0)
rspec-core (~> 3.9.0)
rspec-expectations (~> 3.9.0)
rspec-mocks (~> 3.9.0)
rspec-core (3.9.1)
rspec-support (~> 3.9.1)
rspec-expectations (3.9.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.9.0)
rspec-mocks (3.9.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.9.0)
rspec-support (3.9.2)
simplecov-html (0.12.3)
simplecov_json_formatter (0.1.4)
PLATFORMS
ruby
universal-java-1.8
DEPENDENCIES
parallel_tests
rspec
simplecov!
BUNDLED WITH
2.3.26
simplecov-0.22.0/test_projects/parallel_tests/lib/ 0000775 0000000 0000000 00000000000 14351411403 0022244 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/test_projects/parallel_tests/lib/a.rb 0000664 0000000 0000000 00000000214 14351411403 0023006 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
class A
def foo
:foo
end
def cond(arg)
if arg
:yes
else
:no
end
end
end
simplecov-0.22.0/test_projects/parallel_tests/lib/all.rb 0000664 0000000 0000000 00000000163 14351411403 0023341 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
require_relative "a"
require_relative "b"
require_relative "c"
require_relative "d"
simplecov-0.22.0/test_projects/parallel_tests/lib/b.rb 0000664 0000000 0000000 00000000136 14351411403 0023012 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
class B
def foo
:foo
end
def bar
:bar
end
end
simplecov-0.22.0/test_projects/parallel_tests/lib/c.rb 0000664 0000000 0000000 00000000146 14351411403 0023014 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
class C
def guard(arg)
return if arg == 42
:super
end
end
simplecov-0.22.0/test_projects/parallel_tests/lib/d.rb 0000664 0000000 0000000 00000000275 14351411403 0023020 0 ustar 00root root 0000000 0000000 # 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
simplecov-0.22.0/test_projects/parallel_tests/spec/ 0000775 0000000 0000000 00000000000 14351411403 0022430 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/test_projects/parallel_tests/spec/a_spec.rb 0000664 0000000 0000000 00000000277 14351411403 0024215 0 ustar 00root root 0000000 0000000 # 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
simplecov-0.22.0/test_projects/parallel_tests/spec/b_spec.rb 0000664 0000000 0000000 00000000177 14351411403 0024215 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
require "spec_helper"
describe B do
it "bar" do
expect(subject.bar).to eq :bar
end
end
simplecov-0.22.0/test_projects/parallel_tests/spec/c_spec.rb 0000664 0000000 0000000 00000000206 14351411403 0024207 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
require "spec_helper"
describe C do
it "guard" do
expect(subject.guard(42)).to be_nil
end
end
simplecov-0.22.0/test_projects/parallel_tests/spec/d_spec.rb 0000664 0000000 0000000 00000000312 14351411403 0024206 0 ustar 00root root 0000000 0000000 # 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
simplecov-0.22.0/test_projects/parallel_tests/spec/spec_helper.rb 0000664 0000000 0000000 00000000450 14351411403 0025245 0 ustar 00root root 0000000 0000000 # 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"
simplecov-0.22.0/test_projects/rails/ 0000775 0000000 0000000 00000000000 14351411403 0017572 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/test_projects/rails/README.md 0000664 0000000 0000000 00000000766 14351411403 0021062 0 ustar 00root root 0000000 0000000 What, why are there entire rails projects in here?
The reality is, this is the environment SimpleCov is used in most often.
To test the complex interactions interactions of different projects nothing beats the full and real thing.
Command to generate stripped down rails apps:
```
rails new --skip-action-mailer --skip-action-mailbox --skip-action-text --skip-active-storage --skip-action-cable --skip-javascript --skip-turbolinks --skip-sprockets --skip-git --skip-keep --skip-listen some_name
```
simplecov-0.22.0/test_projects/rails/rspec_rails/ 0000775 0000000 0000000 00000000000 14351411403 0022100 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/test_projects/rails/rspec_rails/.gitignore 0000664 0000000 0000000 00000000023 14351411403 0024063 0 ustar 00root root 0000000 0000000 /log
/db/*.sqlite3
simplecov-0.22.0/test_projects/rails/rspec_rails/.rspec 0000664 0000000 0000000 00000000026 14351411403 0023213 0 ustar 00root root 0000000 0000000 --require spec_helper
simplecov-0.22.0/test_projects/rails/rspec_rails/Gemfile 0000664 0000000 0000000 00000003272 14351411403 0023377 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
source "https://rubygems.org"
# added gems
gem "rspec-rails"
gem "simplecov", path: "../../.."
if defined?(JRUBY_VERSION)
gem "activerecord-jdbcsqlite3-adapter", "~> 61.0", platform: :jruby
else
gem "sqlite3", "~> 1.4"
end
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem "rails", "~> 6.1.4"
# Use Puma as the app server
gem "puma", "~> 5.0"
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem "jbuilder", "~> 2.7"
# Use Active Model has_secure_password
# gem 'bcrypt', '~> 3.1.7'
# Reduces boot times through caching; required in config/boot.rb
gem "bootsnap", ">= 1.4.4", require: false
group :development, :test do
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
gem "byebug", platforms: %i[mri mingw x64_mingw]
end
group :development do
# Access an interactive console on exception pages or by calling 'console' anywhere in the code.
gem "web-console", ">= 4.1.0"
# Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
gem "spring"
end
group :test do
# Adds support for Capybara system testing and selenium driver
gem "capybara", ">= 3.36.0"
# 'selenium-webdriver' and 'webdrivers' did not work with Ruby 3.0 at the
# moment this file was updated. Since they are not needed to run
# SimpleCov's specs, they have been commented out
# gem 'selenium-webdriver'
# Easy installation and use of web drivers to run system tests with browsers
# gem 'webdrivers'
end
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem "tzinfo-data", platforms: %i[mingw mswin x64_mingw jruby]
simplecov-0.22.0/test_projects/rails/rspec_rails/Gemfile.lock 0000664 0000000 0000000 00000012532 14351411403 0024325 0 ustar 00root root 0000000 0000000 PATH
remote: ../../..
specs:
simplecov (0.22.0)
docile (~> 1.1)
simplecov-html (~> 0.11)
simplecov_json_formatter (~> 0.1)
GEM
remote: https://rubygems.org/
specs:
actioncable (6.1.7)
actionpack (= 6.1.7)
activesupport (= 6.1.7)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
actionmailbox (6.1.7)
actionpack (= 6.1.7)
activejob (= 6.1.7)
activerecord (= 6.1.7)
activestorage (= 6.1.7)
activesupport (= 6.1.7)
mail (>= 2.7.1)
actionmailer (6.1.7)
actionpack (= 6.1.7)
actionview (= 6.1.7)
activejob (= 6.1.7)
activesupport (= 6.1.7)
mail (~> 2.5, >= 2.5.4)
rails-dom-testing (~> 2.0)
actionpack (6.1.7)
actionview (= 6.1.7)
activesupport (= 6.1.7)
rack (~> 2.0, >= 2.0.9)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.2.0)
actiontext (6.1.7)
actionpack (= 6.1.7)
activerecord (= 6.1.7)
activestorage (= 6.1.7)
activesupport (= 6.1.7)
nokogiri (>= 1.8.5)
actionview (6.1.7)
activesupport (= 6.1.7)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
activejob (6.1.7)
activesupport (= 6.1.7)
globalid (>= 0.3.6)
activemodel (6.1.7)
activesupport (= 6.1.7)
activerecord (6.1.7)
activemodel (= 6.1.7)
activesupport (= 6.1.7)
activestorage (6.1.7)
actionpack (= 6.1.7)
activejob (= 6.1.7)
activerecord (= 6.1.7)
activesupport (= 6.1.7)
marcel (~> 1.0)
mini_mime (>= 1.1.0)
activesupport (6.1.7)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
tzinfo (~> 2.0)
zeitwerk (~> 2.3)
addressable (2.8.1)
public_suffix (>= 2.0.2, < 6.0)
bindex (0.8.1)
bootsnap (1.5.1)
msgpack (~> 1.0)
bootsnap (1.5.1-java)
msgpack (~> 1.0)
builder (3.2.4)
byebug (11.1.3)
capybara (3.36.0)
addressable
matrix
mini_mime (>= 0.1.3)
nokogiri (~> 1.8)
rack (>= 1.6.0)
rack-test (>= 0.6.3)
regexp_parser (>= 1.5, < 3.0)
xpath (~> 3.2)
concurrent-ruby (1.1.7)
crass (1.0.6)
diff-lcs (1.4.4)
docile (1.4.0)
erubi (1.10.0)
globalid (1.0.0)
activesupport (>= 5.0)
i18n (1.8.5)
concurrent-ruby (~> 1.0)
jbuilder (2.10.1)
activesupport (>= 5.0.0)
loofah (2.8.0)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mail (2.7.1)
mini_mime (>= 0.1.1)
marcel (1.0.2)
matrix (0.4.2)
method_source (1.0.0)
mini_mime (1.1.2)
mini_portile2 (2.5.3)
minitest (5.15.0)
msgpack (1.3.3)
msgpack (1.3.3-java)
nio4r (2.5.4)
nio4r (2.5.4-java)
nokogiri (1.11.0)
mini_portile2 (~> 2.5.0)
racc (~> 1.4)
nokogiri (1.11.0-java)
racc (~> 1.4)
public_suffix (4.0.7)
puma (5.1.1)
nio4r (~> 2.0)
puma (5.1.1-java)
nio4r (~> 2.0)
racc (1.6.0)
racc (1.6.0-java)
rack (2.2.3)
rack-test (1.1.0)
rack (>= 1.0, < 3)
rails (6.1.7)
actioncable (= 6.1.7)
actionmailbox (= 6.1.7)
actionmailer (= 6.1.7)
actionpack (= 6.1.7)
actiontext (= 6.1.7)
actionview (= 6.1.7)
activejob (= 6.1.7)
activemodel (= 6.1.7)
activerecord (= 6.1.7)
activestorage (= 6.1.7)
activesupport (= 6.1.7)
bundler (>= 1.15.0)
railties (= 6.1.7)
sprockets-rails (>= 2.0.0)
rails-dom-testing (2.0.3)
activesupport (>= 4.2.0)
nokogiri (>= 1.6)
rails-html-sanitizer (1.3.0)
loofah (~> 2.3)
railties (6.1.7)
actionpack (= 6.1.7)
activesupport (= 6.1.7)
method_source
rake (>= 12.2)
thor (~> 1.0)
rake (13.0.3)
regexp_parser (2.6.1)
rspec-core (3.10.0)
rspec-support (~> 3.10.0)
rspec-expectations (3.10.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-mocks (3.10.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.10.0)
rspec-rails (4.0.1)
actionpack (>= 4.2)
activesupport (>= 4.2)
railties (>= 4.2)
rspec-core (~> 3.9)
rspec-expectations (~> 3.9)
rspec-mocks (~> 3.9)
rspec-support (~> 3.9)
rspec-support (3.10.0)
simplecov-html (0.12.3)
simplecov_json_formatter (0.1.4)
spring (2.1.1)
sprockets (4.1.1)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.4.2)
actionpack (>= 5.2)
activesupport (>= 5.2)
sprockets (>= 3.0.0)
sqlite3 (1.4.4)
thor (1.0.1)
tzinfo (2.0.4)
concurrent-ruby (~> 1.0)
tzinfo-data (1.2022.6)
tzinfo (>= 1.0.0)
web-console (4.1.0)
actionview (>= 6.0.0)
activemodel (>= 6.0.0)
bindex (>= 0.4.0)
railties (>= 6.0.0)
websocket-driver (0.7.5)
websocket-extensions (>= 0.1.0)
websocket-driver (0.7.5-java)
websocket-extensions (>= 0.1.0)
websocket-extensions (0.1.5)
xpath (3.2.0)
nokogiri (~> 1.8)
zeitwerk (2.4.2)
PLATFORMS
java
ruby
universal-java-1.8
DEPENDENCIES
bootsnap (>= 1.4.4)
byebug
capybara (>= 3.36.0)
jbuilder (~> 2.7)
puma (~> 5.0)
rails (~> 6.1.4)
rspec-rails
simplecov!
spring
sqlite3 (~> 1.4)
tzinfo-data
web-console (>= 4.1.0)
BUNDLED WITH
2.3.4
simplecov-0.22.0/test_projects/rails/rspec_rails/Rakefile 0000664 0000000 0000000 00000000343 14351411403 0023545 0 ustar 00root root 0000000 0000000 # Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require_relative 'config/application'
Rails.application.load_tasks
simplecov-0.22.0/test_projects/rails/rspec_rails/app/ 0000775 0000000 0000000 00000000000 14351411403 0022660 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/test_projects/rails/rspec_rails/app/controllers/ 0000775 0000000 0000000 00000000000 14351411403 0025226 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/test_projects/rails/rspec_rails/app/controllers/application_controller.rb 0000664 0000000 0000000 00000000071 14351411403 0032317 0 ustar 00root root 0000000 0000000 class ApplicationController < ActionController::Base
end
simplecov-0.22.0/test_projects/rails/rspec_rails/app/helpers/ 0000775 0000000 0000000 00000000000 14351411403 0024322 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/test_projects/rails/rspec_rails/app/helpers/application_helper.rb 0000664 0000000 0000000 00000000035 14351411403 0030507 0 ustar 00root root 0000000 0000000 module ApplicationHelper
end
simplecov-0.22.0/test_projects/rails/rspec_rails/app/jobs/ 0000775 0000000 0000000 00000000000 14351411403 0023615 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/test_projects/rails/rspec_rails/app/jobs/application_job.rb 0000664 0000000 0000000 00000000415 14351411403 0027277 0 ustar 00root root 0000000 0000000 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
simplecov-0.22.0/test_projects/rails/rspec_rails/app/models/ 0000775 0000000 0000000 00000000000 14351411403 0024143 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/test_projects/rails/rspec_rails/app/models/application_record.rb 0000664 0000000 0000000 00000000116 14351411403 0030327 0 ustar 00root root 0000000 0000000 class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true
end
simplecov-0.22.0/test_projects/rails/rspec_rails/app/models/foo.rb 0000664 0000000 0000000 00000000050 14351411403 0025246 0 ustar 00root root 0000000 0000000 class Foo
def bar
"bar"
end
end
simplecov-0.22.0/test_projects/rails/rspec_rails/app/views/ 0000775 0000000 0000000 00000000000 14351411403 0024015 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/test_projects/rails/rspec_rails/app/views/layouts/ 0000775 0000000 0000000 00000000000 14351411403 0025515 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/test_projects/rails/rspec_rails/app/views/layouts/application.html.erb 0000664 0000000 0000000 00000000346 14351411403 0031460 0 ustar 00root root 0000000 0000000
RspecRails
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<%= stylesheet_link_tag 'application', media: 'all' %>
<%= yield %>
simplecov-0.22.0/test_projects/rails/rspec_rails/config.ru 0000664 0000000 0000000 00000000240 14351411403 0023711 0 ustar 00root root 0000000 0000000 # This file is used by Rack-based servers to start the application.
require_relative "config/environment"
run Rails.application
Rails.application.load_server
simplecov-0.22.0/test_projects/rails/rspec_rails/config/ 0000775 0000000 0000000 00000000000 14351411403 0023345 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/test_projects/rails/rspec_rails/config/application.rb 0000664 0000000 0000000 00000002142 14351411403 0026174 0 ustar 00root root 0000000 0000000 require_relative "boot"
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
simplecov-0.22.0/test_projects/rails/rspec_rails/config/boot.rb 0000664 0000000 0000000 00000000200 14351411403 0024625 0 ustar 00root root 0000000 0000000 ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
require "bundler/setup" # Set up gems listed in the Gemfile.
simplecov-0.22.0/test_projects/rails/rspec_rails/config/database.yml 0000664 0000000 0000000 00000001056 14351411403 0025636 0 ustar 00root root 0000000 0000000 # SQLite. Versions 3.8.0 and up are supported.
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem 'sqlite3'
#
default: &default
adapter: sqlite3
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
timeout: 5000
development:
<<: *default
database: db/development.sqlite3
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: db/test.sqlite3
simplecov-0.22.0/test_projects/rails/rspec_rails/config/environment.rb 0000664 0000000 0000000 00000000200 14351411403 0026226 0 ustar 00root root 0000000 0000000 # Load the Rails application.
require_relative "application"
# Initialize the Rails application.
Rails.application.initialize!
simplecov-0.22.0/test_projects/rails/rspec_rails/config/environments/ 0000775 0000000 0000000 00000000000 14351411403 0026074 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/test_projects/rails/rspec_rails/config/environments/development.rb 0000664 0000000 0000000 00000004254 14351411403 0030750 0 ustar 00root root 0000000 0000000 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
simplecov-0.22.0/test_projects/rails/rspec_rails/config/environments/test.rb 0000664 0000000 0000000 00000003571 14351411403 0027406 0 ustar 00root root 0000000 0000000 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
simplecov-0.22.0/test_projects/rails/rspec_rails/config/initializers/ 0000775 0000000 0000000 00000000000 14351411403 0026053 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/test_projects/rails/rspec_rails/config/initializers/cookies_serializer.rb 0000664 0000000 0000000 00000000364 14351411403 0032270 0 ustar 00root root 0000000 0000000 # 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
simplecov-0.22.0/test_projects/rails/rspec_rails/config/initializers/filter_parameter_logging.rb 0000664 0000000 0000000 00000000404 14351411403 0033431 0 ustar 00root root 0000000 0000000 # 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
]
simplecov-0.22.0/test_projects/rails/rspec_rails/config/initializers/wrap_parameters.rb 0000664 0000000 0000000 00000000745 14351411403 0031602 0 ustar 00root root 0000000 0000000 # 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
simplecov-0.22.0/test_projects/rails/rspec_rails/config/puma.rb 0000664 0000000 0000000 00000003374 14351411403 0024643 0 ustar 00root root 0000000 0000000 # 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
simplecov-0.22.0/test_projects/rails/rspec_rails/config/routes.rb 0000664 0000000 0000000 00000000214 14351411403 0025210 0 ustar 00root root 0000000 0000000 Rails.application.routes.draw do
# For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html
end
simplecov-0.22.0/test_projects/rails/rspec_rails/config/spring.rb 0000664 0000000 0000000 00000000141 14351411403 0025170 0 ustar 00root root 0000000 0000000 Spring.watch(
".ruby-version",
".rbenv-vars",
"tmp/restart.txt",
"tmp/caching-dev.txt"
)
simplecov-0.22.0/test_projects/rails/rspec_rails/spec/ 0000775 0000000 0000000 00000000000 14351411403 0023032 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/test_projects/rails/rspec_rails/spec/foo_spec.rb 0000664 0000000 0000000 00000000214 14351411403 0025151 0 ustar 00root root 0000000 0000000 require "rails_helper"
RSpec.describe Foo do
describe "#bar" do
it "bars" do
expect(subject.bar).to eq "bar"
end
end
end
simplecov-0.22.0/test_projects/rails/rspec_rails/spec/rails_helper.rb 0000664 0000000 0000000 00000002436 14351411403 0026035 0 ustar 00root root 0000000 0000000 # 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
simplecov-0.22.0/test_projects/rails/rspec_rails/spec/spec_helper.rb 0000664 0000000 0000000 00000000054 14351411403 0025647 0 ustar 00root root 0000000 0000000 require "simplecov"
SimpleCov.start "rails"
simplecov-0.22.0/test_projects/subprocesses/ 0000775 0000000 0000000 00000000000 14351411403 0021200 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/test_projects/subprocesses/.simplecov 0000664 0000000 0000000 00000000325 14351411403 0023202 0 ustar 00root root 0000000 0000000 SimpleCov.enable_for_subprocesses true
# different versions of ruby were tracking different numbers of files. idk why.
# lets only worry about one file.
SimpleCov.add_filter /command/
SimpleCov.add_filter /spawn/
simplecov-0.22.0/test_projects/subprocesses/.simplecov_spawn.rb 0000664 0000000 0000000 00000000177 14351411403 0025021 0 ustar 00root root 0000000 0000000 require 'bundler/setup'
require 'simplecov'
SimpleCov.command_name 'spawn'
SimpleCov.at_fork.call(Process.pid)
SimpleCov.start
simplecov-0.22.0/test_projects/subprocesses/lib/ 0000775 0000000 0000000 00000000000 14351411403 0021746 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/test_projects/subprocesses/lib/command 0000775 0000000 0000000 00000000132 14351411403 0023306 0 ustar 00root root 0000000 0000000 #!/usr/bin/env ruby
require_relative './subprocesses'
Subprocesses.new.run
puts 'done'
simplecov-0.22.0/test_projects/subprocesses/lib/subprocesses.rb 0000664 0000000 0000000 00000000431 14351411403 0025011 0 ustar 00root root 0000000 0000000 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
simplecov-0.22.0/test_projects/subprocesses/spec/ 0000775 0000000 0000000 00000000000 14351411403 0022132 5 ustar 00root root 0000000 0000000 simplecov-0.22.0/test_projects/subprocesses/spec/simple_spec.rb 0000664 0000000 0000000 00000000174 14351411403 0024764 0 ustar 00root root 0000000 0000000 require_relative "spec_helper"
describe Subprocesses do
it "call things" do
expect(subject.run).to be true
end
end
simplecov-0.22.0/test_projects/subprocesses/spec/spawn_spec.rb 0000664 0000000 0000000 00000000420 14351411403 0024615 0 ustar 00root root 0000000 0000000 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
simplecov-0.22.0/test_projects/subprocesses/spec/spec_helper.rb 0000664 0000000 0000000 00000000156 14351411403 0024752 0 ustar 00root root 0000000 0000000 # frozen_string_literal: true
require "simplecov"
SimpleCov.start
require_relative "../lib/subprocesses.rb"