pax_global_header00006660000000000000000000000064121473360770014524gustar00rootroot0000000000000052 comment=f2b92f20432448a348463bc78f492fc2e2300867 ruby-simplecov-0.7.1/000077500000000000000000000000001214733607700145115ustar00rootroot00000000000000ruby-simplecov-0.7.1/.gitignore000066400000000000000000000003511214733607700165000ustar00rootroot00000000000000.bundle Gemfile.lock gemfiles/*.lock ## MAC OS .DS_Store .document ## TEXTMATE *.tmproj tmtags ## EMACS *~ \#* .\#* ## VIM *.swp ## PROJECT::GENERAL coverage rdoc pkg tmp capybara*.html .rvmrc ## PROJECT::SPECIFIC .yardoc doc ruby-simplecov-0.7.1/.travis.yml000066400000000000000000000005031214733607700166200ustar00rootroot00000000000000before_install: - echo "yes" | gem uninstall json script: - bundle - rake appraisal:install - rake appraisal rvm: - 1.8.7 - 1.9.2 - 1.9.3 - ruby-head - ree - rbx-18mode - jruby-18mode matrix: allow_failures: - rvm: ruby-head notifications: email: on_success: always on_failure: always ruby-simplecov-0.7.1/.yardopts000066400000000000000000000000121214733607700163500ustar00rootroot00000000000000- **/*.md ruby-simplecov-0.7.1/Appraisals000066400000000000000000000002731214733607700165350ustar00rootroot00000000000000# See https://github.com/colszowka/simplecov/issues/132 appraise "multi_json-new" do gem "multi_json", ">= 1.3.4" end appraise "multi_json-legacy" do gem "multi_json", "~> 1.0.0" endruby-simplecov-0.7.1/CHANGELOG.md000066400000000000000000000234121214733607700163240ustar00rootroot00000000000000Unreleased ([changes](https://github.com/colszowka/simplecov/compare/v0.7.0...master)) ------------------- v0.7.1, 2012-10-12 ([changes](https://github.com/colszowka/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/colszowka/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/colszowka/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/colszowka/simplecov/pull/151, https://github.com/colszowka/simplecov/issues/11, https://github.com/colszowka/simplecov/issues/90, and https://github.com/colszowka/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/colszowka/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/colszowka/simplecov-html/pull/14 (thanks to @ebelgarts) * [REFACTORING] A few more ruby warnings removed. See https://github.com/colszowka/simplecov/issues/106 and https://github.com/colszowka/simplecov/pull/139. (thanks to @lukejahnke) * A [Pledgie button](https://github.com/colszowka/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/colszowka/simplecov/compare/v0.6.3...v0.6.4)) ------------------- * [BUGFIX] Encoding issues with ISO-8859-encoded source files fixed. See https://github.com/colszowka/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/colszowka/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/colszowka/simplecov/issues/106 and https://github.com/colszowka/simplecov/pull/119. (thanks to @mvz and @gioele) v0.6.3, 2012-05-10 ([changes](https://github.com/colszowka/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/colszowka/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/colszowka/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/colszowka/simplecov/pull/122 v0.6.1, 2012-02-24 ([changes](https://github.com/colszowka/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/colszowka/simplecov/issues/113 v0.6.0, 2012-02-22 ([changes](https://github.com/colszowka/simplecov/compare/v0.5.4...v0.6.0)) ------------------- * [FEATURE] Auto-magic `rake simplecov` task for rails (see https://github.com/colszowka/simplecov/pull/83, thanks @sunaku) * [BUGFIX] Treat source files as UTF-8 to avoid encoding errors (see https://github.com/colszowka/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/colszowka/simplecov/issues/110) * [FEATURE] If guessing command name from the terminal command fails, try guessing from defined constants (see https://github.com/colszowka/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/colszowka/simplecov/compare/v0.5.4...v0.6.0 v0.5.4, 2011-10-12 ([changes](https://github.com/colszowka/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/colszowka/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/colszowka/simplecov/issues/85, thanks @robinroestenburg) * Mailers are now part of the Rails adapter as their own group (see https://github.com/colszowka/simplecov/issues/79, thanks @geetarista) * Removed fix for JRuby 1.6 RC1 float bug because it's been fixed (see https://github.com/colszowka/simplecov/issues/86) * Readme formatted in Markdown :) v0.5.3, 2011-09-13 ([changes](https://github.com/colszowka/simplecov/compare/v0.5.2...v0.5.3)) ------------------- * Fix for encoding issues that came from the nocov processing mechanism (see https://github.com/colszowka/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/colszowka/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/colszowka/simplecov/pull/75, thanks @sferik) v0.5.1, 2011-09-12 ([changes](https://github.com/colszowka/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/colszowka/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/colszowka/simplecov/issues/72 and https://github.com/colszowka/simplecov/pull/74, thanks @sferik) v0.5.0, 2011-09-09 ([changes](https://github.com/colszowka/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 themruby-simplecov-0.7.1/CONTRIBUTING.md000066400000000000000000000012441214733607700167430ustar00rootroot00000000000000# Making Contributions To fetch & test the library for development, do: $ git clone https://github.com/colszowka/simplecov.git $ cd simplecov $ bundle $ rake appraisal:install $ rake appraisal For more information on the appraisal gem (for testing against multiple gem dependency versions), please see https://github.com/thoughtbot/appraisal/ 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. ruby-simplecov-0.7.1/Gemfile000066400000000000000000000003111214733607700157770ustar00rootroot00000000000000source "http://rubygems.org" gemspec # Uncomment this to use local copy of simplecov-html in development when checked out # gem 'simplecov-html', :path => File.dirname(__FILE__) + '/../simplecov-html'ruby-simplecov-0.7.1/LICENSE000066400000000000000000000020531214733607700155160ustar00rootroot00000000000000Copyright (c) 2010-2012 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. ruby-simplecov-0.7.1/README.md000066400000000000000000000455231214733607700160010ustar00rootroot00000000000000SimpleCov [![Build Status](https://secure.travis-ci.org/colszowka/simplecov.png)][Continuous Integration] [![Dependency Status](https://gemnasium.com/colszowka/simplecov.png)][Dependencies] ========= **Code coverage for Ruby 1.9** * [Source Code] * [API documentation] * [Changelog] * [Rubygem] * [Continuous Integration] [Coverage]: http://www.ruby-doc.org/stdlib-1.9.3/libdoc/coverage/rdoc/Coverage.html "API doc for Ruby 1.9's Coverage library" [Source Code]: https://github.com/colszowka/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/colszowka/simplecov/blob/master/CHANGELOG.md "Project Changelog" [Rubygem]: http://rubygems.org/gems/simplecov "SimpleCov @ rubygems.org" [Continuous Integration]: http://travis-ci.org/colszowka/simplecov "SimpleCov is built around the clock by travis-ci.org" [Dependencies]: https://gemnasium.com/colszowka/simplecov "SimpleCov dependencies on Gemnasium" [simplecov-html]: https://github.com/colszowka/simplecov-html "SimpleCov HTML Formatter Source Code @ GitHub" [Pledgie]: http://www.pledgie.com/campaigns/18379 [![You can support the development of SimpleCov via Pledgie - thanks for your help](http://www.pledgie.com/campaigns/18379.png?skin_name=chrome)][Pledgie] SimpleCov is a code coverage analysis tool for Ruby 1.9. It uses [1.9'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, thus giving you a complete code coverage suite that can be set up with just a couple lines of code. 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 then 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]. Getting started --------------- 1. Add SimpleCov to your `Gemfile` and `bundle install`: 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`, cucumber `env.rb`, or whatever your preferred test framework uses*): 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!** SimpleCov must be running in the process that you want the code coverage analysis to happen on. When testing a server process (i.e. a JSON API endpoint) via a separate test process (i.e. 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'll want to add something like this to the top of `script/rails`: if ENV['RAILS_ENV'] == 'test' require 'simplecov' SimpleCov.start 'rails' puts "required simplecov" end 3. Run your tests, open up `coverage/index.html` in your browser and check out what you've missed so far. 4. Add the following to your `.gitignore` file to ensure that coverage results are not tracked by Git (optional): coverage If you're making a Rails application, SimpleCov comes with a built-in adapter (see below for more information on what adapters are) which will get you started with groups for your Controllers, Views, Models and Helpers. To use it, the first two lines of your test_helper should be like this: require 'simplecov' SimpleCov.start 'rails' ## Example output **Coverage results report, fully browsable locally with sorting and much more:** ![SimpleCov coverage report](http://colszowka.github.com/simplecov/devise_result-0.5.3.png) **Source file coverage details view:** ![SimpleCov source file detail view](http://colszowka.github.com/simplecov/devise_source_file-0.5.3.png) ## Use it with any framework! Similarily 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: 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:
FrameworkNotesIssue #
Test/Unit 2 Test Unit 2 used to mess with ARGV, leading to failure to detect the test process name in SimpleCov. test-unit releases 2.4.3+ (Dec 11th, 2011) should have this problem resolved. SimpleCov #45 & Test/Unit #12
Spork Because of the how Spork works internally (using preforking) there used to be trouble when using SimpleCov with it, but that apparently has been resolved with a specific configuration strategy. See this comment. SimpleCov #42
parallel_tests SimpleCov does not detect parallel_test automatically yet but can be taught to do so with a simple workaround explained at Issue #64. SimpleCov #64
Riot A user has reported problems with the coverage report using the riot framework. If you experience similar trouble please follow up on the related Github issue. SimpleCov #80
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')` SimpleCov #95
## 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: SimpleCov.start do some_config_option 'foo' end * You can also set all configuration options directly: 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: 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 (i.e. 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 and move the `SimpleCov.start` code with all your custom config options into `.simplecov`: # 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 ## 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 a billion of coverage reports for source files in the gems you are using. Of course 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 (that will then be Regexp-matched against each source file's path), a block or by passing in your own Filter class. #### String filter SimpleCov.start do add_filter "/test/" end This simple string filter will remove all files that match "/test/" in their path. #### Block filter 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 then 5 lines of code. #### Custom filter class 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. ## 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, Libs and Plugins. Group definition works similar to Filters (and indeed 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: 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 "Short files", LineFilter.new(5) # Using the LineFilter class defined in Filters section above end ## Merging results Normally, you want to have your coverage analyzed across ALL of your test suites, right? Simplecov automatically caches coverage results in your (coverage_path)/.resultset.json. Those results will then be automatically merged 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. There are two things to note here though: ### 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 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. So, 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: # 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 has only to be invoked ONCE PER TEST SUITE, so even if you have 200 unit test files, specifying it in some_test.rb is fair enough. [simplecov-html] prints the used test suites in the footer of the generated coverage report. ### Timeout for merge Of course, your cached coverage data is likely to become invalid at some point. Thus, 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 merging altogether with `SimpleCov.use_merging false`. ## Running coverage only on demand The Ruby STDLIB Coverage library that SimpleCov builds upon is *very* fast (i.e. 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 a ENV variable conditional into your SimpleCov setup block, like this: SimpleCov.start if ENV["COVERAGE"] Then, SimpleCov will only run if you execute your tests like this: $ COVERAGE=true rake test ## Adapters By default, Simplecov's only config assumption is that you only want coverage reports for files inside your project root. To save you from repetitive configuration, you can use predefined blocks of configuration, called 'adapters', or define your own. You can then pass the name of the adapter to be used as the first argument to SimpleCov.start. For example, simplecov comes bundled with a 'rails' adapter. It looks somewhat like this: SimpleCov.adapters.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' add_group 'Plugins', 'vendor/plugins' end As you can see, it's just a glorified SimpleCov.configure block. In your test_helper.rb, launch simplecov with: SimpleCov.start 'rails' **OR** SimpleCov.start 'rails' do # additional config here end ### Custom adapters You can load additional adapters with the SimpleCov.load_adapter('xyz') method. This allows you to build upon an existing adapter and customize it so you can reuse it in unit tests and cucumber features, for example. # lib/simplecov_custom_adapter.rb require 'simplecov' SimpleCov.adapters.define 'myadapter' do load_adapter 'rails' add_filter 'vendor' # Don't include vendored stuff end # features/support/env.rb require 'simplecov_custom_adapter' SimpleCov.start 'myadapter' # test/test_helper.rb require 'simplecov_custom_adapter' SimpleCov.start 'myadapter' ## Customizing exit behaviour You can define what simplecov should do when your test suite finishes by customizing the at_exit hook: 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. SimpleCov.minimum_coverage 90 ### Maximum coverage drop You can define the maximum coverage drop percentage at once. SimpleCov will return non-zero if exceeded. SimpleCov.maximum_coverage_drop 5 ### Refuse dropping coverage You can also entirely refuse dropping coverage between test runs: SimpleCov.refuse_coverage_drop ## Using your own formatter You can use your own formatter with: SimpleCov.formatter = SimpleCov::Formatter::HTMLFormatter When calling SimpleCov.result.format!, it will be invoked with SimpleCov::Formatter::YourFormatter.new.format(result), "result" being an instance of SimpleCov::Result. Do whatever your wish with that! ## Using multiple formatters If you want to use multiple result formats, as of SimpleCov 0.7.0 you can use the built-in MultiFormatter: SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[ SimpleCov::Formatter::HTMLFormatter, SimpleCov::Formatter::CSVFormatter, ] ## Available formatters Apart from the direct companion [simplecov-html], there are other formatters available: ### [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-csv](https://github.com/fguillen/simplecov-csv) *by Fernando Guillen* CSV formatter for SimpleCov code coverage tool for ruby 1.9+ #### [simplecov-vim](https://github.com/nyarly/Simplecov-Vim) *by Judson Lester* A formatter for Simplecov that emits a Vim script to mark up code files with coverage information. ## Ruby version compatibility [![Build Status](https://secure.travis-ci.org/colszowka/simplecov.png)](http://travis-ci.org/colszowka/simplecov) Only Ruby 1.9+ ships with the coverage library that SimpleCov depends upon. SimpleCov is built against various other Rubies, including Rubinius and JRuby, in [Continuous Integration], but this happens only to ensure that SimpleCov does not make your test suite crash right now. Whether SimpleCov will support JRuby/Rubinius in the future depends solely on whether those Ruby interpreters add the coverage library. SimpleCov is built in [Continuous Integration] on 1.8.7, ree, 1.9.2, 1.9.3. ## Contributing See the [contributing guide](https://github.com/colszowka/simplecov/blob/master/CONTRIBUTING.md). ## Kudos Thanks to Aaron Patterson for the original idea for this! ## Copyright Copyright (c) 2010-2012 Christoph Olszowka. See LICENSE for details. ruby-simplecov-0.7.1/Rakefile000066400000000000000000000014221214733607700161550ustar00rootroot00000000000000#!/usr/bin/env rake require 'rubygems' require 'bundler/setup' require 'appraisal' Bundler::GemHelper.install_tasks # See https://github.com/colszowka/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 . -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 'rake/testtask' Rake::TestTask.new(:test) do |test| test.libs << 'lib' << 'test' test.test_files = FileList['test/test_*.rb'] test.verbose = true test.warning = true end require 'cucumber/rake/task' Cucumber::Rake::Task.new task :default => [:test, :cucumber] ruby-simplecov-0.7.1/cucumber.yml000066400000000000000000000011301214733607700170340ustar00rootroot00000000000000<% 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 ~@wip" interp_opts = if defined?(RUBY_ENGINE) " --tags ~@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 ~@wip<%= interp_opts %> ruby-simplecov-0.7.1/features/000077500000000000000000000000001214733607700163275ustar00rootroot00000000000000ruby-simplecov-0.7.1/features/config_adapters.feature000066400000000000000000000024261214733607700230400ustar00rootroot00000000000000@test_unit @config @adapters Feature: In order to re-use SimpleCov settings across projects, adapters can be defined that hold configuration settings that can be loaded at once. Background: Given SimpleCov for Test/Unit is configured with: """ require 'simplecov' """ Scenario: Defining and using a custom adapter Given a file named ".simplecov" with: """ SimpleCov.adapters.define 'custom_command' do command_name "Adapter Command" end SimpleCov.start do load_adapter 'test_frameworks' load_adapter '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 Adapter Command" within "#footer" Scenario: Using existing adapter in custom adapter and supplying adapter to start command Given a file named ".simplecov" with: """ SimpleCov.adapters.define 'my_adapter' do load_adapter 'test_frameworks' command_name "My Adapter" end SimpleCov.start 'my_adapter' """ 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 Adapter" within "#footer" ruby-simplecov-0.7.1/features/config_autoload.feature000066400000000000000000000027211214733607700230430ustar00rootroot00000000000000@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"' 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.0 % | | lib/faked_project/some_class.rb | 80.0 % | | lib/faked_project/framework_specific.rb | 87.5 % | | lib/faked_project/meta_magic.rb | 100.0 % | ruby-simplecov-0.7.1/features/config_command_name.feature000066400000000000000000000020531214733607700236470ustar00rootroot00000000000000@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. 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 | ruby-simplecov-0.7.1/features/config_coverage_dir.feature000066400000000000000000000011411214733607700236570ustar00rootroot00000000000000@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. 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 ruby-simplecov-0.7.1/features/config_deactivate_merging.feature000066400000000000000000000024231214733607700250530ustar00rootroot00000000000000@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 :) 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 | ruby-simplecov-0.7.1/features/config_formatters.feature000066400000000000000000000031621214733607700234210ustar00rootroot00000000000000@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. 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.formatter = SimpleCov::Formatter::MultiFormatter[ 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/ ruby-simplecov-0.7.1/features/config_merge_timeout.feature000066400000000000000000000022441214733607700241000ustar00rootroot00000000000000@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. Scenario: Given SimpleCov for Test/Unit is configured with: """ require 'simplecov' SimpleCov.start do merge_timeout 1 end """ Given SimpleCov for RSpec is configured with: """ require 'simplecov' SimpleCov.start do merge_timeout 1 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 2 seconds And I open the coverage report generated with `bundle exec rspec spec` Then the report should be based upon: | RSpec | ruby-simplecov-0.7.1/features/config_nocov_token.feature000066400000000000000000000046341214733607700235640ustar00rootroot00000000000000@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 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.0 % | | lib/faked_project/some_class.rb | 80.0 % | | lib/faked_project/framework_specific.rb | 75.0 % | | lib/faked_project/meta_magic.rb | 100.0 % | | lib/faked_project/nocov.rb | 100.0 % | And there should be 5 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.0 % | | lib/faked_project/some_class.rb | 80.0 % | | lib/faked_project/framework_specific.rb | 75.0 % | | lib/faked_project/meta_magic.rb | 100.0 % | | lib/faked_project/nocov.rb | 100.0 % | And there should be 5 skipped lines in the source files And the report should be based upon: | Unit Tests | ruby-simplecov-0.7.1/features/config_project_name.feature000066400000000000000000000014321214733607700236770ustar00rootroot00000000000000@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') 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" 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" ruby-simplecov-0.7.1/features/config_styles.feature000066400000000000000000000053111214733607700225540ustar00rootroot00000000000000@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 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: 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" ruby-simplecov-0.7.1/features/cucumber_basic.feature000066400000000000000000000017671214733607700226650ustar00rootroot00000000000000@cucumber Feature: Simply adding the basic simplecov lines to a project should get the user a coverage report after running `cucumber features` 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 | 91.23% | 6 | And I should see the source files: | name | coverage | | lib/faked_project.rb | 100.0 % | | lib/faked_project/some_class.rb | 80.0 % | | lib/faked_project/framework_specific.rb | 75.0 % | | lib/faked_project/meta_magic.rb | 100.0 % | | features/step_definitions/my_steps.rb | 100.0 % | | features/support/simplecov_config.rb | 100.0 % | And the report should be based upon: | Cucumber Features | ruby-simplecov-0.7.1/features/maximum_coverage_drop.feature000066400000000000000000000017441214733607700242660ustar00rootroot00000000000000@test_unit @config Feature: Exit code should be non-zero if the overall coverage decreases by more than the maximum_coverage_drop threshold. Scenario: 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 "Coverage has dropped by 3.32% since the last time (maximum allowed: 3.14%)." And a file named "coverage/.last_run.json" should exist ruby-simplecov-0.7.1/features/merging_test_unit_and_rspec.feature000066400000000000000000000025601214733607700254530ustar00rootroot00000000000000@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. 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.0 % | | lib/faked_project/some_class.rb | 80.0 % | | lib/faked_project/framework_specific.rb | 87.5 % | | lib/faked_project/meta_magic.rb | 100.0 % | ruby-simplecov-0.7.1/features/minimum_coverage.feature000066400000000000000000000026501214733607700232350ustar00rootroot00000000000000@test_unit @config Feature: Exit code should be non-zero if the overall coverage is below the minimum_coverage threshold. Scenario: 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 "Coverage (88.10%) is below the expected minimum coverage (90.00%)." Scenario: Given SimpleCov for Test/Unit is configured with: """ require 'simplecov' SimpleCov.start do add_filter 'test.rb' minimum_coverage 88.11 end """ When I run `bundle exec rake test` Then the exit status should not be 0 And the output should contain "Coverage (88.10%) is below the expected minimum coverage (88.11%)." Scenario: 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 be 0 Scenario: 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 ruby-simplecov-0.7.1/features/refuse_coverage_drop.feature000066400000000000000000000016531214733607700241010ustar00rootroot00000000000000@test_unit @config Feature: Exit code should be non-zero if the overall coverage decreases. Scenario: 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 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 "Coverage has dropped by 3.32% since the last time (maximum allowed: 0.00%)." And a file named "coverage/.last_run.json" should exist ruby-simplecov-0.7.1/features/rspec_basic.feature000066400000000000000000000023521214733607700221630ustar00rootroot00000000000000@rspec Feature: Simply adding the basic simplecov lines to a project should get the user a coverage report after running `rspec` 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 | 90.74% | 6 | And I should see the source files: | name | coverage | | lib/faked_project.rb | 100.0 % | | lib/faked_project/some_class.rb | 80.0 % | | lib/faked_project/framework_specific.rb | 75.0 % | | lib/faked_project/meta_magic.rb | 100.0 % | | spec/meta_magic_spec.rb | 100.0 % | | spec/some_class_spec.rb | 100.0 % | # 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. ruby-simplecov-0.7.1/features/rspec_fails_on_initialization.feature000066400000000000000000000006101214733607700257760ustar00rootroot00000000000000@rspec Feature: Running specs with a failing rspec setup 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 ruby-simplecov-0.7.1/features/rspec_groups_and_filters_basic.feature000066400000000000000000000017201214733607700261320ustar00rootroot00000000000000@rspec Feature: Defining some groups and filters should give a corresponding coverage report that respects those settings after running rspec 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.0 % | | lib/faked_project/some_class.rb | 80.0 % | | lib/faked_project/framework_specific.rb | 75.0 % | | lib/faked_project/meta_magic.rb | 100.0 % | ruby-simplecov-0.7.1/features/rspec_groups_and_filters_complex.feature000066400000000000000000000023711214733607700265230ustar00rootroot00000000000000@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. 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_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 | And I should see the source files: | name | coverage | | lib/faked_project/meta_magic.rb | 100.0 % | ruby-simplecov-0.7.1/features/rspec_groups_using_filter_class.feature000066400000000000000000000030201214733607700263510ustar00rootroot00000000000000@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. 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 | 90.74% | 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.0 % | | lib/faked_project/some_class.rb | 80.0 % | | lib/faked_project.rb | 100.0 % | | lib/faked_project/meta_magic.rb | 100.0 % | | spec/meta_magic_spec.rb | 100.0 % | | spec/some_class_spec.rb | 100.0 % | ruby-simplecov-0.7.1/features/rspec_without_simplecov.feature000066400000000000000000000010101214733607700246540ustar00rootroot00000000000000@rspec Feature: Running specs without simplecov configuration 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 ruby-simplecov-0.7.1/features/skipping_code_blocks_manually.feature000066400000000000000000000042261214733607700257650ustar00rootroot00000000000000@test_unit @nocov Feature: When code is wrapped in :nocov: comment blocks, it does not count against the coverage numbers. Background: 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.0 % | | lib/faked_project/some_class.rb | 80.0 % | | lib/faked_project/framework_specific.rb | 75.0 % | | lib/faked_project/meta_magic.rb | 100.0 % | | lib/faked_project/nocov.rb | 100.0 % | And there should be 5 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 I should see the source files: | name | coverage | | lib/faked_project.rb | 100.0 % | | lib/faked_project/some_class.rb | 80.0 % | | lib/faked_project/framework_specific.rb | 75.0 % | | lib/faked_project/meta_magic.rb | 100.0 % | | lib/faked_project/nocov.rb | 100.0 % | And there should be 5 skipped lines in the source files And the report should be based upon: | Unit Tests | ruby-simplecov-0.7.1/features/step_definitions/000077500000000000000000000000001214733607700216755ustar00rootroot00000000000000ruby-simplecov-0.7.1/features/step_definitions/html_steps.rb000066400000000000000000000030141214733607700244020ustar00rootroot00000000000000module GroupHelpers def available_groups all('#content .file_list_container') end def available_source_files all('.source_files .source_table') end end World(GroupHelpers) 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 expected_groups.count.should == available_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 file_count_in_group.should == group["files"].to_i with_scope "h2" do page.should have_content(group["name"]) page.should have_content(group["coverage"]) end end end end Then /^I should see the source files:$/ do |table| expected_files = table.hashes expected_files.length.should == available_source_files.count # Find all filenames and their coverage present in coverage report files = available_source_files.map {|f| {"name" => f.find('h3').text, "coverage" => f.find('.header span').text} } files.sort_by {|hsh| hsh["name"] }.should == expected_files.sort_by {|hsh| hsh["name"] } end Then /^there should be (\d+) skipped lines in the source files$/ do |expected_count| all(".source_table ol li.skipped").count.should == expected_count.to_i end ruby-simplecov-0.7.1/features/step_definitions/simplecov_steps.rb000066400000000000000000000040561214733607700254460ustar00rootroot00000000000000# 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" else raise ArgumentError, "Could not identify test framework #{framework}!" end steps %Q{ Given a file named "#{framework_dir}/simplecov_config.rb" with: """ #{config_body} """ } end When /^I open the coverage report generated with `([^`]+)`$/ do |command| steps %Q{ 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 %Q{ 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 /^no coverage report should have been generated(?: in "([^"]*)")?$/ do |coverage_dir| coverage_dir ||= 'coverage' steps %Q{ 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 %Q{ Then the output should contain "Coverage report generated for #{frameworks.join(", ")}" And I should see "using #{frameworks.join(", ")}" within "#footer" } end # This is neccessary 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 ruby-simplecov-0.7.1/features/step_definitions/transformers.rb000066400000000000000000000010441214733607700247460ustar00rootroot00000000000000# # 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... # Transform "bundle exec rspec spec" do |t| files = nil # Avoid shadowing in_current_dir { files = Dir['spec/**/*_spec.rb'] } "bundle exec rspec #{files.sort.join(' ')}" end ruby-simplecov-0.7.1/features/step_definitions/web_steps.rb000066400000000000000000000025541214733607700242230ustar00rootroot00000000000000module 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 page.should have_content(text) end end Then /^(?:|I )should see \/([^\/]*)\/(?: within "([^"]*)")?$/ do |regexp, selector| regexp = Regexp.new(regexp) with_scope(selector) do page.should have_xpath('//*', :text => regexp) end end Then /^(?:|I )should not see "([^"]*)"(?: within "([^"]*)")?$/ do |text, selector| with_scope(selector) do page.should have_no_content(text) end end Then /^(?:|I )should not see \/([^\/]*)\/(?: within "([^"]*)")?$/ do |regexp, selector| regexp = Regexp.new(regexp) with_scope(selector) do page.should have_no_xpath('//*', :text => regexp) end end Then /^show me the page$/ do save_and_open_page end Then /^print the page$/ do puts page.body end ruby-simplecov-0.7.1/features/support/000077500000000000000000000000001214733607700200435ustar00rootroot00000000000000ruby-simplecov-0.7.1/features/support/env.rb000066400000000000000000000014251214733607700211620ustar00rootroot00000000000000unless RUBY_VERSION =~ /1\.9/ $stderr.puts "Sorry, Cucumber features are only meant to run on Ruby 1.9 for now :(" exit 0 end require 'bundler' Bundler.setup require 'aruba/cucumber' require 'capybara/cucumber' # Fake rack app for capybara that just returns the latest coverage report from aruba temp project dir Capybara.app = lambda {|env| [200, {'Content-Type' => 'text/html'}, [File.read(File.join(File.dirname(__FILE__), '../../tmp/aruba/project', 'coverage/index.html'))]] } Before do @aruba_timeout_seconds = 20 this_dir = File.dirname(__FILE__) # Clean up and create blank state for fake project in_current_dir do FileUtils.rm_rf 'project' FileUtils.cp_r File.join(this_dir, '../../test/faked_project/'), 'project' end step 'I cd to "project"' end ruby-simplecov-0.7.1/features/test_unit_basic.feature000066400000000000000000000024651214733607700230720ustar00rootroot00000000000000@test_unit Feature: Simply adding the basic simplecov lines to a project should get the user a coverage report after running `rake test` 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.0 % | | lib/faked_project/some_class.rb | 80.0 % | | lib/faked_project/framework_specific.rb | 75.0 % | | lib/faked_project/meta_magic.rb | 100.0 % | | test/meta_magic_test.rb | 100.0 % | | test/some_class_test.rb | 100.0 % | # 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 | ruby-simplecov-0.7.1/features/test_unit_groups_and_filters_basic.feature000066400000000000000000000017311214733607700270360ustar00rootroot00000000000000@test_unit Feature: Defining some groups and filters should give a corresponding coverage report that respects those settings after running tests 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.0 % | | lib/faked_project/some_class.rb | 80.0 % | | lib/faked_project/framework_specific.rb | 75.0 % | | lib/faked_project/meta_magic.rb | 100.0 % | ruby-simplecov-0.7.1/features/test_unit_groups_and_filters_complex.feature000066400000000000000000000024041214733607700274220ustar00rootroot00000000000000@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. 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.0 % | ruby-simplecov-0.7.1/features/test_unit_groups_using_filter_class.feature000066400000000000000000000030331214733607700272570ustar00rootroot00000000000000@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. 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.0 % | | lib/faked_project/some_class.rb | 80.0 % | | lib/faked_project.rb | 100.0 % | | lib/faked_project/meta_magic.rb | 100.0 % | | test/meta_magic_test.rb | 100.0 % | | test/some_class_test.rb | 100.0 % | ruby-simplecov-0.7.1/features/test_unit_without_simplecov.feature000066400000000000000000000010231214733607700255620ustar00rootroot00000000000000@test_unit Feature: Running unit tests without simplecov configuration 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 ruby-simplecov-0.7.1/features/unicode_compatiblity.feature000066400000000000000000000041211214733607700241100ustar00rootroot00000000000000@test_unit @unicode Feature: Files with unicode in their source should be no problem at all for generating a proper coverage report. Background: 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.0 % | | lib/faked_project/some_class.rb | 80.0 % | | lib/faked_project/framework_specific.rb | 75.0 % | | lib/faked_project/meta_magic.rb | 100.0 % | | 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.0 % | | lib/faked_project/some_class.rb | 80.0 % | | lib/faked_project/framework_specific.rb | 75.0 % | | lib/faked_project/meta_magic.rb | 100.0 % | | lib/faked_project/unicode.rb | 66.67 % | And the report should be based upon: | Unit Tests | ruby-simplecov-0.7.1/gemfiles/000077500000000000000000000000001214733607700163045ustar00rootroot00000000000000ruby-simplecov-0.7.1/gemfiles/multi_json-legacy.gemfile000066400000000000000000000001701214733607700232610ustar00rootroot00000000000000# This file was generated by Appraisal source "http://rubygems.org" gem "multi_json", "~> 1.0.0" gemspec :path=>"../"ruby-simplecov-0.7.1/gemfiles/multi_json-new.gemfile000066400000000000000000000001701214733607700226060ustar00rootroot00000000000000# This file was generated by Appraisal source "http://rubygems.org" gem "multi_json", ">= 1.3.4" gemspec :path=>"../"ruby-simplecov-0.7.1/lib/000077500000000000000000000000001214733607700152575ustar00rootroot00000000000000ruby-simplecov-0.7.1/lib/simplecov.rb000066400000000000000000000076031214733607700176130ustar00rootroot00000000000000# # Code coverage for ruby 1.9. Please check out README for a full introduction. # module SimpleCov # Indicates invalid coverage data class CoverageDataError < StandardError; end; class << self attr_accessor :running#, :result # TODO: Remove result? # # Sets up SimpleCov to run against your project. # You can optionally specify an adapter to use as well as configuration with a block: # SimpleCov.start # OR # SimpleCov.start 'rails' # using rails adapter # 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(adapter=nil, &block) return false unless SimpleCov.usable? require 'coverage' load_adapter(adapter) unless adapter.nil? Coverage.start configure(&block) if block_given? @result = nil self.running = true 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 @result ||= SimpleCov::Result.new(Coverage.result) if running # If we're using merging of results, store the current result # first, then merge the results and return those if use_merging SimpleCov::ResultMerger.store_result(@result) if @result return SimpleCov::ResultMerger.merged_result else return @result if defined? @result end ensure self.running = false end # # Returns nil if the result has not been computed # Otherwise, returns the result # def result? defined? @result and @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.length > 0 and (other_files = files.reject {|source_file| grouped_files.include?(source_file)}).length > 0 grouped["Ungrouped"] = SimpleCov::FileList.new(other_files) end grouped end # # Applies the adapter of given name on SimpleCov configuration # def load_adapter(name) adapters.load(name) end # # Checks whether we're on a proper version of ruby (1.9+) and returns false if this is not the case, # also printing an appropriate warning # def usable? unless "1.9".respond_to?(:encoding) warn "WARNING: SimpleCov is activated, but you're not running Ruby 1.9+ - no coverage analysis will happen" return false end true end end end $LOAD_PATH.unshift(File.join(File.dirname(__FILE__))) require 'simplecov/configuration' SimpleCov.send :extend, SimpleCov::Configuration require 'simplecov/exit_codes' require 'simplecov/json' require 'simplecov/adapters' require 'simplecov/source_file' require 'simplecov/file_list' require 'simplecov/result' require 'simplecov/filter' require 'simplecov/formatter' require 'simplecov/last_run' require 'simplecov/merge_helpers' require 'simplecov/result_merger' require 'simplecov/command_guesser' require 'simplecov/version' # Load default config require 'simplecov/defaults' # Load Rails integration (only for Rails 3, see #113) require 'simplecov/railtie' if defined? Rails::Railtie ruby-simplecov-0.7.1/lib/simplecov/000077500000000000000000000000001214733607700172605ustar00rootroot00000000000000ruby-simplecov-0.7.1/lib/simplecov/adapters.rb000066400000000000000000000014671214733607700214200ustar00rootroot00000000000000# # Adapters are glorified SimpleCov configuration procs that can be easily # loaded using SimpleCov.start :rails and defined using # SimpleCov.adapters.define :foo do # # SimpleCov configuration here, same as in SimpleCov.configure # end # class SimpleCov::Adapters < Hash # # Define a SimpleCov adapter: # SimpleCov.adapters.define 'rails' do # # Same as SimpleCov.configure do .. here # end # def define(name, &blk) name = name.to_sym raise "SimpleCov Adapter '#{name}' is already defined" unless self[name].nil? self[name] = blk end # # Applies the adapter of given name on SimpleCov.configure # def load(name) name = name.to_sym raise "Could not find SimpleCov Adapter called '#{name}'" unless has_key?(name) SimpleCov.configure(&self[name]) end end ruby-simplecov-0.7.1/lib/simplecov/command_guesser.rb000066400000000000000000000027451214733607700227700ustar00rootroot00000000000000# # Helper that tries to find out what test suite is running (for SimpleCov.command_name) # module SimpleCov::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_command_line_options || from_defined_constants end private def from_command_line_options case original_run_command when /#{'test/functional/'}/ "Functional Tests" when /#{'test/integration/'}/ "Integration Tests" when /#{'test/'}/ "Unit Tests" when /cucumber/, /features/ "Cucumber Features" when /spec/ "RSpec" else nil 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" 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 endruby-simplecov-0.7.1/lib/simplecov/configuration.rb000066400000000000000000000175121214733607700224620ustar00rootroot00000000000000require 'fileutils' # # 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 SimpleCov::Configuration attr_writer :filters, :groups, :formatter # # 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 and root.nil? @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 and dir.nil? @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 = File.join(root, coverage_dir) FileUtils.mkdir_p coverage_path coverage_path 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 and formatter.nil? @formatter = formatter raise "No formatter configured. Please specify a formatter using SimpleCov.formatter = SimpleCov::Formatter::SimpleFormatter" unless @formatter @formatter 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 and nocov_token.nil? @nocov_token = (nocov_token || 'nocov') end alias_method :skip_token, :nocov_token # # Returns the configured groups. Add groups using SimpleCov.add_group # def groups @groups ||= {} end # # Returns the hash of available adapters # def adapters @adapters ||= SimpleCov::Adapters.new 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) return false unless SimpleCov.usable? instance_exec(&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 or block_given? @at_exit = block if block_given? @at_exit ||= Proc.new { SimpleCov.result.format! } 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 and @project_name and new_name.nil? @project_name = new_name if new_name.kind_of?(String) @project_name ||= File.basename(root.split('/').last).capitalize.gsub('_', ' ') 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 and @use_merging == false end # # Defines them 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.kind_of?(Fixnum) @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) @minimum_coverage ||= (coverage || 0).to_f.round(2) 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) @maximum_coverage_drop ||= (coverage_drop || 100).to_f.round(2) 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 maximum_coverage_drop 0 end # # Add a filter to the processing chain. # There are three 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 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 private # # The actal filter processor. Not meant for direct use # def parse_filter(filter_argument=nil, &filter_proc) if filter_argument.kind_of?(SimpleCov::Filter) filter_argument elsif filter_argument.kind_of?(String) SimpleCov::StringFilter.new(filter_argument) elsif filter_proc SimpleCov::BlockFilter.new(filter_proc) else raise ArgumentError, "Please specify either a string or a block to filter with" end end end ruby-simplecov-0.7.1/lib/simplecov/defaults.rb000066400000000000000000000052711214733607700214210ustar00rootroot00000000000000# Load default formatter gem require 'simplecov-html' SimpleCov.adapters.define 'root_filter' do # Exclude all files outside of simplecov root add_filter do |src| !(src.filename =~ /^#{SimpleCov.root}/) end end SimpleCov.adapters.define 'test_frameworks' do add_filter '/test/' add_filter '/features/' add_filter '/spec/' add_filter '/autotest/' end SimpleCov.adapters.define 'rails' do load_adapter 'test_frameworks' add_filter '/config/' add_filter '/db/' add_filter '/vendor/bundle/' add_group 'Controllers', 'app/controllers' add_group 'Models', 'app/models' add_group 'Mailers', 'app/mailers' add_group 'Helpers', 'app/helpers' add_group 'Libraries', 'lib' add_group 'Plugins', 'vendor/plugins' end # Default configuration SimpleCov.configure do formatter SimpleCov::Formatter::HTMLFormatter # Exclude files outside of SimpleCov.root load_adapter '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 = "#{$0} #{ARGV.join(" ")}" at_exit do # Store the exit status of the test run since it goes away after calling the at_exit proc... if $! #was an exception thrown? #if it was a SystemExit, use the accompanying status #otherwise set a non-zero status representing termination by some other exception #(see github issue 41) @exit_status = $!.is_a?(SystemExit) ? $!.status : SimpleCov::ExitCodes::EXCEPTION end SimpleCov.at_exit.call if SimpleCov.result? # Result has been computed covered_percent = SimpleCov.result.covered_percent.round(2) if @exit_status.to_i == 0 # No other errors @exit_status = if covered_percent < SimpleCov.minimum_coverage $stderr.puts "Coverage (%.2f%%) is below the expected minimum coverage (%.2f%%)." % \ [covered_percent, SimpleCov.minimum_coverage] SimpleCov::ExitCodes::MINIMUM_COVERAGE elsif (last_run = SimpleCov::LastRun.read) diff = last_run['result']['covered_percent'] - covered_percent if diff > SimpleCov.maximum_coverage_drop $stderr.puts "Coverage has dropped by %.2f%% since the last time (maximum allowed: %.2f%%)." % \ [diff, SimpleCov.maximum_coverage_drop] SimpleCov::ExitCodes::MAXIMUM_COVERAGE_DROP end end end metrics = { :result => { :covered_percent => covered_percent } } SimpleCov::LastRun.write(metrics) end exit @exit_status if @exit_status # Force exit with stored status (see github issue #5) end # Autoload config from .simplecov if present config_path = File.join(SimpleCov.root, '.simplecov') load config_path if File.exist?(config_path) ruby-simplecov-0.7.1/lib/simplecov/exit_codes.rb000066400000000000000000000001431214733607700217310ustar00rootroot00000000000000module SimpleCov::ExitCodes EXCEPTION = 1 MINIMUM_COVERAGE = 2 MAXIMUM_COVERAGE_DROP = 3 end ruby-simplecov-0.7.1/lib/simplecov/file_list.rb000066400000000000000000000024471214733607700215660ustar00rootroot00000000000000# An array of SimpleCov SourceFile instances with additional collection helper # methods for calculating coverage across them etc. class SimpleCov::FileList < Array # Returns the count of lines that have coverage def covered_lines return 0.0 if empty? map {|f| f.covered_lines.count }.inject(&:+) end # Returns the count of lines that have been missed def missed_lines return 0.0 if empty? map {|f| f.missed_lines.count }.inject(&:+) 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 # Returns the overall amount of relevant lines of code across all files in this list def lines_of_code covered_lines + missed_lines end # Computes the coverage based upon lines covered and lines missed def covered_percent return 100.0 if empty? or lines_of_code == 0 covered_lines * 100.0 / lines_of_code end # Computes the strength (hits / line) based upon lines covered and lines missed def covered_strength return 0 if empty? or lines_of_code == 0 map {|f| f.covered_strength }.inject(&:+) / size end end ruby-simplecov-0.7.1/lib/simplecov/filter.rb000066400000000000000000000024701214733607700210750ustar00rootroot00000000000000module 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 "DEPRECATION: SimpleCov::Filter#passes?(x) has been renamed to #matches?. Please update your custom filters accordingly!" matches?(source_file) 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.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 end ruby-simplecov-0.7.1/lib/simplecov/formatter.rb000066400000000000000000000003101214733607700216020ustar00rootroot00000000000000module SimpleCov # TODO: Documentation on how to build your own formatters module Formatter end end require 'simplecov/formatter/simple_formatter' require 'simplecov/formatter/multi_formatter' ruby-simplecov-0.7.1/lib/simplecov/formatter/000077500000000000000000000000001214733607700212635ustar00rootroot00000000000000ruby-simplecov-0.7.1/lib/simplecov/formatter/multi_formatter.rb000066400000000000000000000007541214733607700250330ustar00rootroot00000000000000class SimpleCov::Formatter::MultiFormatter def self.[](*args) Class.new(self) do define_method :formatters do @formatters ||= args end end end def format(result) formatters.map do |formatter| begin formatter.new.format(result) rescue => e STDERR.puts("Formatter #{formatter} failed with #{e.class}: #{e.message} (#{e.backtrace.first})") nil end end end def formatters @formatters ||= [] end end ruby-simplecov-0.7.1/lib/simplecov/formatter/simple_formatter.rb000066400000000000000000000007601214733607700251670ustar00rootroot00000000000000# # A ridiculously simple formatter for SimpleCov results. # class SimpleCov::Formatter::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 ruby-simplecov-0.7.1/lib/simplecov/json.rb000066400000000000000000000011421214733607700205540ustar00rootroot00000000000000require 'multi_json' module SimpleCov::JSON class << self def parse(json) # Detect and use available MultiJson API - it changed in v1.3 if MultiJson.respond_to?(:adapter) MultiJson.load(json) else MultiJson.decode(json) end end def dump(string) if defined? ::JSON ::JSON.pretty_generate(string) else # Detect and use available MultiJson API - it changed in v1.3 if MultiJson.respond_to?(:adapter) MultiJson.dump(string) else MultiJson.encode(string) end end end end end ruby-simplecov-0.7.1/lib/simplecov/last_run.rb000066400000000000000000000006131214733607700214340ustar00rootroot00000000000000module SimpleCov::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) SimpleCov::JSON.parse(File.read(last_run_path)) end def write(json) File.open(last_run_path, "w+") do |f| f.puts SimpleCov::JSON.dump(json) end end end end ruby-simplecov-0.7.1/lib/simplecov/merge_helpers.rb000066400000000000000000000017511214733607700224320ustar00rootroot00000000000000module SimpleCov::ArrayMergeHelper # Merges an array of coverage results with self def merge_resultset(array) new_array = [] self.each_with_index do |element, i| new_array[i] = element end array.each_with_index do |element, i| if element.nil? and new_array[i].nil? new_array[i] = nil else local_value = element || 0 other_value = new_array[i] || 0 new_array[i] = local_value + other_value end end new_array end end module SimpleCov::HashMergeHelper # Merges the given Coverage.result hash with self def merge_resultset(hash) new_resultset = {} (self.keys + hash.keys).each do |filename| new_resultset[filename] = [] end new_resultset.each do |filename, data| new_resultset[filename] = (self[filename] || []).merge_resultset(hash[filename] || []) end new_resultset end end Array.send :include, SimpleCov::ArrayMergeHelper Hash.send :include, SimpleCov::HashMergeHelper ruby-simplecov-0.7.1/lib/simplecov/railtie.rb000066400000000000000000000002031214733607700212310ustar00rootroot00000000000000module SimpleCov class Railtie < ::Rails::Railtie rake_tasks do load 'simplecov/railties/tasks.rake' end end end ruby-simplecov-0.7.1/lib/simplecov/railties/000077500000000000000000000000001214733607700210745ustar00rootroot00000000000000ruby-simplecov-0.7.1/lib/simplecov/railties/tasks.rake000066400000000000000000000005611214733607700230670ustar00rootroot00000000000000require 'rake/testtask' Rake::TestTask.new do |t| t.name = 'simplecov' t.loader = :direct # uses require() which skips PWD in Ruby 1.9 t.libs.push 'test', 'spec', Dir.pwd t.test_files = FileList['{test,spec}/**/*_{test,spec}.rb'] t.ruby_opts.push '-r', 'simplecov', '-e', 'SimpleCov.start(:rails)'.inspect end require 'rake/clean' CLOBBER.include 'coverage' ruby-simplecov-0.7.1/lib/simplecov/result.rb000066400000000000000000000100471214733607700211250ustar00rootroot00000000000000require 'digest/sha1' module SimpleCov # # A simplecov code coverage result, initialized from the Hash Ruby 1.9's built-in coverage # library generates (Coverage.result). # class Result # 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_method :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 # Initialize a new SimpleCov::Result from given Coverage.result (a Hash of filenames each containing an array of # coverage data) def initialize(original_result) @original_result = original_result.freeze @files = SimpleCov::FileList.new(original_result.map do |filename, coverage| SimpleCov::SourceFile.new(filename, 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 # The overall percentual coverage for this result def covered_percent # Make sure that weird rounding error from #15, #23 and #24 does not occur again! total_lines.zero? ? 0 : 100.0 * covered_lines / total_lines end # The multiple of coverage for this result def covered_strength return 0 if total_lines.zero? return @covered_strength if @covered_strength m = 0 @files.each do |file| original_result[file.filename].each do |line_result| if line_result m += line_result end end end @covered_strength = m.to_f / total_lines end # Returns the count of lines that are covered def covered_lines return @covered_lines if defined? @covered_lines @covered_lines = 0 @files.each do |file| original_result[file.filename].each do |line_result| @covered_lines += 1 if line_result and line_result > 0 end end @covered_lines end # Returns the count of missed lines def missed_lines return @missed_lines if defined? @missed_lines @missed_lines = 0 @files.each do |file| original_result[file.filename].each do |line_result| @missed_lines += 1 if line_result == 0 end end @missed_lines end # Total count of relevant lines (covered + missed) def total_lines @total_lines ||= (covered_lines + missed_lines) 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 YAML def to_hash {command_name => {"coverage" => original_result.reject {|filename, result| !filenames.include?(filename) }, "timestamp" => created_at.to_i}} end # Loads a SimpleCov::Result#to_hash dump def self.from_hash(hash) command_name, data = hash.first result = SimpleCov::Result.new(data["coverage"]) result.command_name = command_name result.created_at = Time.at(data["timestamp"]) result end private # Applies all configured SimpleCov filters on this result's source files def filter! @files = SimpleCov.filtered(files) end end end ruby-simplecov-0.7.1/lib/simplecov/result_merger.rb000066400000000000000000000044131214733607700224660ustar00rootroot00000000000000# # Singleton that is responsible for caching, loading and merging # SimpleCov::Results into a single result for coverage analysis based # upon multiple test suites. # module SimpleCov::ResultMerger class << self # The path to the .resultset.json cache file def resultset_path File.join(SimpleCov.coverage_path, '.resultset.json') end # Loads the cached resultset from YAML and returns it as a Hash def resultset if stored_data SimpleCov::JSON.parse(stored_data) else {} end end # Returns the contents of the resultset cache as a string or if the file is missing or empty nil def stored_data if File.exist?(resultset_path) and stored_data = File.read(resultset_path) and stored_data.length >= 2 stored_data else nil end end # Gets the resultset hash and re-creates all included instances # of SimpleCov::Result from that. # All results that are above the SimpleCov.merge_timeout will be # dropped. Returns an array of SimpleCov::Result items. def results results = [] resultset.each do |command_name, data| result = SimpleCov::Result.from_hash(command_name => data) # Only add result if the timeout is above the configured threshold if (Time.now - result.created_at) < SimpleCov.merge_timeout results << result end end results end # # Gets all SimpleCov::Results from cache, 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 merged = {} results.each do |result| merged = result.original_result.merge_resultset(merged) end result = SimpleCov::Result.new(merged) # Specify the command name result.command_name = results.map(&:command_name).sort.join(", ") result end # Saves the given SimpleCov::Result in the resultset cache def store_result(result) new_set = resultset command_name, data = result.to_hash.first new_set[command_name] = data File.open(resultset_path, "w+") do |f| f.puts SimpleCov::JSON.dump(new_set) end true end end end ruby-simplecov-0.7.1/lib/simplecov/source_file.rb000066400000000000000000000141411214733607700221050ustar00rootroot00000000000000module SimpleCov # # Representation of a source file including it's coverage data, source code, # source lines and featuring helpers to interpret that data. # 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_method :source, :src alias_method :line, :line_number alias_method :number, :line_number def initialize(src, line_number, coverage) raise ArgumentError, "Only String accepted for source" unless src.kind_of?(String) raise ArgumentError, "Only Fixnum accepted for line_number" unless line_number.kind_of?(Fixnum) raise ArgumentError, "Only Fixnum and nil accepted for coverage" unless coverage.kind_of?(Fixnum) or coverage.nil? @src, @line_number, @coverage = src, line_number, coverage @skipped = false @src.encode!('UTF-8', 'UTF-8', :invalid => :replace) if @src.respond_to?(:encode!) end # Returns true if this is a line that should have been covered, but was not def missed? not never? and not skipped? and coverage == 0 end # Returns true if this is a line that has been covered def covered? not never? and not skipped? and coverage > 0 end # Returns true if this line is not relevant for coverage def never? not skipped? and 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 # 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 # The source code for this file. Aliased as :source attr_reader :src alias_method :source, :src def initialize(filename, coverage) @filename, @coverage = filename, coverage File.open(filename, "r:UTF-8") {|f| @src = f.readlines } 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 return @lines if defined? @lines # Warning to identify condition from Issue #56 if coverage.size > src.size $stderr.puts "Warning: coverage data provided by Coverage [#{coverage.size}] exceeds number of lines in #{filename} [#{src.size}]" end # Initialize lines @lines = [] src.each_with_index do |src, i| @lines << SimpleCov::SourceFile::Line.new(src, i+1, coverage[i]) end process_skipped_lines! @lines end alias_method :source_lines, :lines # 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 relevant lines def covered_percent return 100.0 if lines.length == 0 or lines.length == never_lines.count relevant_lines = lines.count - never_lines.count - skipped_lines.count if relevant_lines == 0 0 else (covered_lines.count) * 100 / relevant_lines.to_f end end def covered_strength return 0 if lines.length == 0 or lines.length == never_lines.count lines_strength = 0 lines.each do |c| lines_strength += c.coverage if c.coverage end effective_lines_count = (lines.count - never_lines.count - skipped_lines.count).to_f if effective_lines_count == 0 0 else strength = lines_strength / effective_lines_count round_float(strength, 1) end end # Returns all covered lines as SimpleCov::SourceFile::Line def covered_lines @covered_lines ||= lines.select {|c| c.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 {|c| c.missed? } end # Returns all lines that are not relevant for coverage as # SimpleCov::SourceFile::Line instances def never_lines @never_lines ||= lines.select {|c| c.never? } end # Returns all lines that were skipped as SimpleCov::SourceFile::Line instances def skipped_lines @skipped_lines ||= lines.select {|c| c.skipped? } end # Returns the number of relevant lines (covered + missed) def lines_of_code covered_lines.count + missed_lines.count end # Will go through all source files and mark lines that are wrapped within # :nocov: comment blocks # as skipped. def process_skipped_lines! skipping = false lines.each do |line| if line.src =~ /^([\s]*)#([\s]*)(\:#{SimpleCov.nocov_token}\:)/ skipping = !skipping else line.skipped! if skipping end end end private # ruby 1.9 could use Float#round(places) instead def round_float(float, places) factor = (10 * places).to_f (float * factor).round / factor end end end ruby-simplecov-0.7.1/lib/simplecov/version.rb000066400000000000000000000000501214733607700212650ustar00rootroot00000000000000module SimpleCov VERSION = "0.7.1" endruby-simplecov-0.7.1/metadata.yml000066400000000000000000000206341214733607700170210ustar00rootroot00000000000000--- !ruby/object:Gem::Specification name: simplecov version: !ruby/object:Gem::Version version: 0.7.1 prerelease: platform: ruby authors: - Christoph Olszowka autorequire: bindir: bin cert_chain: [] date: 2012-10-12 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency name: multi_json requirement: !ruby/object:Gem::Requirement none: false requirements: - - ~> - !ruby/object:Gem::Version version: '1.0' type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement none: false requirements: - - ~> - !ruby/object:Gem::Version version: '1.0' - !ruby/object:Gem::Dependency name: simplecov-html requirement: !ruby/object:Gem::Requirement none: false requirements: - - ~> - !ruby/object:Gem::Version version: 0.7.1 type: :runtime prerelease: false version_requirements: !ruby/object:Gem::Requirement none: false requirements: - - ~> - !ruby/object:Gem::Version version: 0.7.1 - !ruby/object:Gem::Dependency name: aruba requirement: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: capybara requirement: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: appraisal requirement: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: cucumber requirement: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: 1.1.4 type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: 1.1.4 - !ruby/object:Gem::Dependency name: rake requirement: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: rspec requirement: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' - !ruby/object:Gem::Dependency name: shoulda requirement: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' description: Code coverage for Ruby 1.9 with a powerful configuration library and automatic merging of coverage across test suites email: - christoph at olszowka de executables: [] extensions: [] extra_rdoc_files: [] files: - .gitignore - .travis.yml - .yardopts - Appraisals - CHANGELOG.md - CONTRIBUTING.md - Gemfile - LICENSE - README.md - Rakefile - cucumber.yml - features/config_adapters.feature - features/config_autoload.feature - features/config_command_name.feature - features/config_coverage_dir.feature - features/config_deactivate_merging.feature - features/config_formatters.feature - features/config_merge_timeout.feature - features/config_nocov_token.feature - features/config_project_name.feature - features/config_styles.feature - features/cucumber_basic.feature - features/maximum_coverage_drop.feature - features/merging_test_unit_and_rspec.feature - features/minimum_coverage.feature - features/refuse_coverage_drop.feature - features/rspec_basic.feature - features/rspec_fails_on_initialization.feature - features/rspec_groups_and_filters_basic.feature - features/rspec_groups_and_filters_complex.feature - features/rspec_groups_using_filter_class.feature - features/rspec_without_simplecov.feature - features/skipping_code_blocks_manually.feature - features/step_definitions/html_steps.rb - features/step_definitions/simplecov_steps.rb - features/step_definitions/transformers.rb - features/step_definitions/web_steps.rb - features/support/env.rb - features/test_unit_basic.feature - features/test_unit_groups_and_filters_basic.feature - features/test_unit_groups_and_filters_complex.feature - features/test_unit_groups_using_filter_class.feature - features/test_unit_without_simplecov.feature - features/unicode_compatiblity.feature - gemfiles/multi_json-legacy.gemfile - gemfiles/multi_json-new.gemfile - lib/simplecov.rb - lib/simplecov/adapters.rb - lib/simplecov/command_guesser.rb - lib/simplecov/configuration.rb - lib/simplecov/defaults.rb - lib/simplecov/exit_codes.rb - lib/simplecov/file_list.rb - lib/simplecov/filter.rb - lib/simplecov/formatter.rb - lib/simplecov/formatter/multi_formatter.rb - lib/simplecov/formatter/simple_formatter.rb - lib/simplecov/json.rb - lib/simplecov/last_run.rb - lib/simplecov/merge_helpers.rb - lib/simplecov/railtie.rb - lib/simplecov/railties/tasks.rake - lib/simplecov/result.rb - lib/simplecov/result_merger.rb - lib/simplecov/source_file.rb - lib/simplecov/version.rb - simplecov.gemspec - test/faked_project/Gemfile - test/faked_project/Rakefile - test/faked_project/cucumber.yml - test/faked_project/features/step_definitions/my_steps.rb - test/faked_project/features/support/env.rb - test/faked_project/features/test_stuff.feature - test/faked_project/lib/faked_project.rb - test/faked_project/lib/faked_project/framework_specific.rb - test/faked_project/lib/faked_project/meta_magic.rb - test/faked_project/lib/faked_project/some_class.rb - test/faked_project/spec/faked_spec.rb - test/faked_project/spec/meta_magic_spec.rb - test/faked_project/spec/some_class_spec.rb - test/faked_project/spec/spec_helper.rb - test/faked_project/test/faked_test.rb - test/faked_project/test/meta_magic_test.rb - test/faked_project/test/some_class_test.rb - test/faked_project/test/test_helper.rb - test/fixtures/app/controllers/sample_controller.rb - test/fixtures/app/models/user.rb - test/fixtures/deleted_source_sample.rb - test/fixtures/frameworks/rspec_bad.rb - test/fixtures/frameworks/rspec_good.rb - test/fixtures/frameworks/testunit_bad.rb - test/fixtures/frameworks/testunit_good.rb - test/fixtures/iso-8859.rb - test/fixtures/resultset1.rb - test/fixtures/resultset2.rb - test/fixtures/sample.rb - test/fixtures/utf-8.rb - test/helper.rb - test/shoulda_macros.rb - test/test_1_8_fallbacks.rb - test/test_command_guesser.rb - test/test_deleted_source.rb - test/test_file_list.rb - test/test_filters.rb - test/test_merge_helpers.rb - test/test_result.rb - test/test_return_codes.rb - test/test_source_file.rb - test/test_source_file_line.rb homepage: http://github.com/colszowka/simplecov licenses: [] post_install_message: rdoc_options: [] require_paths: - lib required_ruby_version: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' segments: - 0 hash: -2884824259526901790 required_rubygems_version: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' segments: - 0 hash: -2884824259526901790 requirements: [] rubyforge_project: rubygems_version: 1.8.24 signing_key: specification_version: 3 summary: Code coverage for Ruby 1.9 with a powerful configuration library and automatic merging of coverage across test suites test_files: [] ruby-simplecov-0.7.1/simplecov.gemspec000066400000000000000000000022771214733607700200670ustar00rootroot00000000000000# encoding: utf-8 $:.push File.expand_path('../lib', __FILE__) require 'simplecov/version' Gem::Specification.new do |gem| gem.name = 'simplecov' gem.version = SimpleCov::VERSION gem.platform = Gem::Platform::RUBY gem.authors = ["Christoph Olszowka"] gem.email = ['christoph at olszowka de'] gem.homepage = 'http://github.com/colszowka/simplecov' gem.description = %Q{Code coverage for Ruby 1.9 with a powerful configuration library and automatic merging of coverage across test suites} gem.summary = gem.description gem.add_dependency 'multi_json', '~> 1.0' gem.add_dependency 'simplecov-html', '~> 0.7.1' gem.add_development_dependency 'aruba' gem.add_development_dependency 'capybara' gem.add_development_dependency 'appraisal' gem.add_development_dependency 'cucumber', '>= 1.1.4' gem.add_development_dependency 'rake' gem.add_development_dependency 'rspec' gem.add_development_dependency 'shoulda' gem.files = `git ls-files`.split("\n") gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } gem.require_paths = ['lib'] end ruby-simplecov-0.7.1/test/000077500000000000000000000000001214733607700154705ustar00rootroot00000000000000ruby-simplecov-0.7.1/test/faked_project/000077500000000000000000000000001214733607700202705ustar00rootroot00000000000000ruby-simplecov-0.7.1/test/faked_project/Gemfile000066400000000000000000000001521214733607700215610ustar00rootroot00000000000000source :rubygems gem 'simplecov', :path => '../../../' gem 'rake' gem 'rspec', '>= 2.6.0' gem 'cucumber' ruby-simplecov-0.7.1/test/faked_project/Rakefile000066400000000000000000000002771214733607700217430ustar00rootroot00000000000000require '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 ruby-simplecov-0.7.1/test/faked_project/cucumber.yml000066400000000000000000000011301214733607700226130ustar00rootroot00000000000000<% 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 ~@wip" interp_opts = if defined?(RUBY_ENGINE) " --tags ~@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 ~@wip<%= interp_opts %> ruby-simplecov-0.7.1/test/faked_project/features/000077500000000000000000000000001214733607700221065ustar00rootroot00000000000000ruby-simplecov-0.7.1/test/faked_project/features/step_definitions/000077500000000000000000000000001214733607700254545ustar00rootroot00000000000000ruby-simplecov-0.7.1/test/faked_project/features/step_definitions/my_steps.rb000066400000000000000000000012151214733607700276430ustar00rootroot00000000000000Given /^I want to keep stuff simple$/ do 1.should == 1 end When /^I write my cukes for the fake project$/ do 1.should == 1 end Then /^I make all neccessary tests in a single step$/ do FakedProject.foo.should == 'bar' FrameworkSpecific.cucumber.should == "Only tested in Cucumber" FakedProject.a_class_method.should == "this is a mixed-in class method" FakedProject.new.an_instance_method.should == "this is a mixed-in instance method" FakedProject.new.dynamic.should == "A dynamically defined instance method" something = SomeClass.new("foo") something.reverse.should == 'oof' something.compare_with('foo').should be_true end ruby-simplecov-0.7.1/test/faked_project/features/support/000077500000000000000000000000001214733607700236225ustar00rootroot00000000000000ruby-simplecov-0.7.1/test/faked_project/features/support/env.rb000066400000000000000000000005571214733607700247460ustar00rootroot00000000000000require '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 => err $stderr.puts "No SimpleCov config file found!" end $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '/../../lib')) require 'faked_project' ruby-simplecov-0.7.1/test/faked_project/features/test_stuff.feature000066400000000000000000000002601214733607700256470ustar00rootroot00000000000000Feature: Foo Scenario: Test stuff Given I want to keep stuff simple When I write my cukes for the fake project Then I make all neccessary tests in a single step ruby-simplecov-0.7.1/test/faked_project/lib/000077500000000000000000000000001214733607700210365ustar00rootroot00000000000000ruby-simplecov-0.7.1/test/faked_project/lib/faked_project.rb000066400000000000000000000004471214733607700241700ustar00rootroot00000000000000class FakedProject def self.foo "bar" end end Dir[File.join(File.dirname(__FILE__), 'faked_project/*.rb')].each do |file| require file # Require all source files in project dynamically so we can inject some stuff depending on test situation end FakedProject.send :include, MetaMagic ruby-simplecov-0.7.1/test/faked_project/lib/faked_project/000077500000000000000000000000001214733607700236365ustar00rootroot00000000000000ruby-simplecov-0.7.1/test/faked_project/lib/faked_project/framework_specific.rb000066400000000000000000000005621214733607700300300ustar00rootroot00000000000000# A pile of methods that only get tested in their frameworks # and thus make this file only 100% covered when all framework test # results are merged module FrameworkSpecific class << self def cucumber "Only tested in Cucumber" end def rspec "Only tested in RSpec" end def test_unit "Only tested in Test/Unit" end end end ruby-simplecov-0.7.1/test/faked_project/lib/faked_project/meta_magic.rb000066400000000000000000000007151214733607700262540ustar00rootroot00000000000000module MetaMagic module ClassMethods def a_class_method "this is a mixed-in class method" end end module InstanceMethods def an_instance_method "this is a mixed-in instance method" end end def self.included(base) base.send :extend, ClassMethods base.send :include, InstanceMethods base.class_eval do define_method :dynamic do "A dynamically defined instance method" end end end end ruby-simplecov-0.7.1/test/faked_project/lib/faked_project/some_class.rb000066400000000000000000000005571214733607700263220ustar00rootroot00000000000000class 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 return true else raise "Item does not match label" end rescue => err false end private def uncovered "private method" end end ruby-simplecov-0.7.1/test/faked_project/spec/000077500000000000000000000000001214733607700212225ustar00rootroot00000000000000ruby-simplecov-0.7.1/test/faked_project/spec/faked_spec.rb000066400000000000000000000003731214733607700236360ustar00rootroot00000000000000require 'spec_helper' describe FakedProject do it "should return proper foo" do FakedProject.foo.should == 'bar' end it "should test it's framework specific method" do FrameworkSpecific.rspec.should == "Only tested in RSpec" end end ruby-simplecov-0.7.1/test/faked_project/spec/meta_magic_spec.rb000066400000000000000000000005261214733607700246520ustar00rootroot00000000000000require 'spec_helper' describe FakedProject do it "should have added a class method to FakedProject" do FakedProject.a_class_method.should == "this is a mixed-in class method" end its(:an_instance_method) { should == "this is a mixed-in instance method" } its(:dynamic) { should == "A dynamically defined instance method" } end ruby-simplecov-0.7.1/test/faked_project/spec/some_class_spec.rb000066400000000000000000000003221214733607700247060ustar00rootroot00000000000000require 'spec_helper' describe SomeClass do subject { SomeClass.new("foo") } its(:reverse) { should == 'oof' } it "should compare with 'foo'" do subject.compare_with('foo').should be_true end end ruby-simplecov-0.7.1/test/faked_project/spec/spec_helper.rb000066400000000000000000000005541214733607700240440ustar00rootroot00000000000000require '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 => err $stderr.puts "No SimpleCov config file found!" end require 'faked_project' RSpec.configure do |config| # some (optional) config here end ruby-simplecov-0.7.1/test/faked_project/test/000077500000000000000000000000001214733607700212475ustar00rootroot00000000000000ruby-simplecov-0.7.1/test/faked_project/test/faked_test.rb000066400000000000000000000003641214733607700237100ustar00rootroot00000000000000require 'test_helper' class FakedTest < Test::Unit::TestCase def test_something assert_equal 'bar', FakedProject.foo end def test_framework_specific assert_equal "Only tested in Test/Unit", FrameworkSpecific.test_unit end end ruby-simplecov-0.7.1/test/faked_project/test/meta_magic_test.rb000066400000000000000000000006011214733607700247160ustar00rootroot00000000000000require 'test_helper' class MetaMagicTest < Test::Unit::TestCase def test_class_methods assert_equal "this is a mixed-in class method", FakedProject.a_class_method end def test_instance_methods p = FakedProject.new assert_equal "this is a mixed-in instance method", p.an_instance_method assert_equal "A dynamically defined instance method", p.dynamic end end ruby-simplecov-0.7.1/test/faked_project/test/some_class_test.rb000066400000000000000000000004071214733607700247640ustar00rootroot00000000000000require 'test_helper' class SomeClassTest < Test::Unit::TestCase def setup @instance = SomeClass.new("foo") end def test_reverse assert_equal 'oof', @instance.reverse end def test_comparison assert @instance.compare_with('foo') end end ruby-simplecov-0.7.1/test/faked_project/test/test_helper.rb000066400000000000000000000005401214733607700241110ustar00rootroot00000000000000require '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 => err $stderr.puts "No SimpleCov config file found!" end require 'faked_project' require 'test/unit' class Test::Unit::TestCase end ruby-simplecov-0.7.1/test/fixtures/000077500000000000000000000000001214733607700173415ustar00rootroot00000000000000ruby-simplecov-0.7.1/test/fixtures/app/000077500000000000000000000000001214733607700201215ustar00rootroot00000000000000ruby-simplecov-0.7.1/test/fixtures/app/controllers/000077500000000000000000000000001214733607700224675ustar00rootroot00000000000000ruby-simplecov-0.7.1/test/fixtures/app/controllers/sample_controller.rb000066400000000000000000000001341214733607700265360ustar00rootroot00000000000000# Foo class class Foo def initialize @foo = 'baz' end def bar @foo end end ruby-simplecov-0.7.1/test/fixtures/app/models/000077500000000000000000000000001214733607700214045ustar00rootroot00000000000000ruby-simplecov-0.7.1/test/fixtures/app/models/user.rb000066400000000000000000000001341214733607700227050ustar00rootroot00000000000000# Foo class class Foo def initialize @foo = 'baz' end def bar @foo end end ruby-simplecov-0.7.1/test/fixtures/deleted_source_sample.rb000066400000000000000000000005761214733607700242250ustar00rootroot00000000000000$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..')) require 'lib/simplecov' SimpleCov.start { command_name "Test" } dir = File.expand_path(File.dirname(__FILE__)) 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 ruby-simplecov-0.7.1/test/fixtures/frameworks/000077500000000000000000000000001214733607700215215ustar00rootroot00000000000000ruby-simplecov-0.7.1/test/fixtures/frameworks/rspec_bad.rb000066400000000000000000000003751214733607700237750ustar00rootroot00000000000000$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', '..', '..')) require 'lib/simplecov' require 'rspec' SimpleCov.start describe 'exit status' do it "should exit with a non-zero exit status when assertion fails" do 1.should == 2 end end ruby-simplecov-0.7.1/test/fixtures/frameworks/rspec_good.rb000066400000000000000000000003711214733607700241730ustar00rootroot00000000000000$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 1.should == 1 end end ruby-simplecov-0.7.1/test/fixtures/frameworks/testunit_bad.rb000066400000000000000000000003231214733607700245310ustar00rootroot00000000000000$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 false end end ruby-simplecov-0.7.1/test/fixtures/frameworks/testunit_good.rb000066400000000000000000000003221214733607700247320ustar00rootroot00000000000000$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 ruby-simplecov-0.7.1/test/fixtures/iso-8859.rb000066400000000000000000000000371214733607700210730ustar00rootroot00000000000000 # localized to Espaņol thus: ruby-simplecov-0.7.1/test/fixtures/resultset1.rb000066400000000000000000000000541214733607700220000ustar00rootroot00000000000000puts "foo" puts "foo" puts "foo" puts "foo" ruby-simplecov-0.7.1/test/fixtures/resultset2.rb000066400000000000000000000000441214733607700220000ustar00rootroot00000000000000 class Resultset VERSION = 2 end ruby-simplecov-0.7.1/test/fixtures/sample.rb000066400000000000000000000002241214733607700211450ustar00rootroot00000000000000# Foo class class Foo def initialize @foo = 'baz' end def bar @foo end #:nocov: def skipped @foo * 2 end #:nocov: end ruby-simplecov-0.7.1/test/fixtures/utf-8.rb000066400000000000000000000000411214733607700206240ustar00rootroot00000000000000# encoding: utf-8 puts '135°C' ruby-simplecov-0.7.1/test/helper.rb000066400000000000000000000017261214733607700173020ustar00rootroot00000000000000require 'bundler/setup' require 'simplecov' require 'test/unit' require 'shoulda' SimpleCov.coverage_dir('tmp/coverage') class Test::Unit::TestCase def source_fixture(filename) File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', filename)) end # Keep 1.8-rubies from complaining about missing tests in each file that covers only 1.9 functionality def default_test end end require 'shoulda_macros' Test::Unit::TestCase.send :extend, ShouldaMacros # Taken from http://stackoverflow.com/questions/4459330/how-do-i-temporarily-redirect-stderr-in-ruby require "stringio" 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 ruby-simplecov-0.7.1/test/shoulda_macros.rb000066400000000000000000000014101214733607700210140ustar00rootroot00000000000000module ShouldaMacros # # Simple block helper for running certain tests only on specific ruby versions. # The given strings will be regexp-matched against RUBY_VERSION # def on_ruby(*ruby_versions) context "On Ruby #{RUBY_VERSION}" do yield end if ruby_versions.any? {|v| RUBY_VERSION =~ /#{v}/ } end def should_be(boolean_flag) should "be #{boolean_flag}" do assert_equal true, subject.send(boolean_flag) end end def should_not_be(boolean_flag) should "not be #{boolean_flag}" do assert_equal false, subject.send(boolean_flag) end end def should_have(attr_name, expectation) should "have #{attr_name} == #{expectation.inspect}" do assert_equal expectation, subject.send(attr_name) end end end ruby-simplecov-0.7.1/test/test_1_8_fallbacks.rb000066400000000000000000000020321214733607700214420ustar00rootroot00000000000000require 'helper' # Tests that verify that on 1.8 versions of ruby, simplecov simply # does not launch and does not cause errors on the way # # TODO: This should be expanded upon all methods that could potentially # be called in a test/spec-helper simplecov config block # class Test18FallBacks < Test::Unit::TestCase on_ruby '1.8' do should "return false when calling SimpleCov.start" do assert_equal false, SimpleCov.start end should "return false when calling SimpleCov.start with a block" do assert_equal false, SimpleCov.start { raise "Shouldn't reach this!?" } end should "return false when calling SimpleCov.configure with a block" do assert_equal false, SimpleCov.configure { raise "Shouldn't reach this!?" } end should "allow to define an adapter" do begin SimpleCov.adapters.define 'testadapter' do add_filter '/config/' end rescue => err assert false, "Adapter definition should have been fine, but raised #{err}" end end end end ruby-simplecov-0.7.1/test/test_command_guesser.rb000066400000000000000000000017711214733607700222350ustar00rootroot00000000000000require 'helper' class TestCommandGuesser < Test::Unit::TestCase on_ruby '1.9' do def self.should_guess_command_name(expectation, *argv) argv.each do |args| should "return '#{expectation}' for '#{args}'" do SimpleCov::CommandGuesser.original_run_command = args assert_equal expectation, SimpleCov::CommandGuesser.guess end end end should_guess_command_name "Unit Tests", '/some/path/test/units/foo_bar_test.rb', 'test/units/foo.rb', 'test/foo.rb' should_guess_command_name "Functional Tests", '/some/path/test/functional/foo_bar_controller_test.rb' should_guess_command_name "Integration Tests", '/some/path/test/integration/foo_bar_controller_test.rb' should_guess_command_name "Cucumber Features", 'features', 'cucumber', 'cucumber features' should_guess_command_name "RSpec", '/some/path/spec/foo.rb' should_guess_command_name "Unit Tests", 'some_arbitrary_command with arguments' # Because Test::Unit const is defined! end end ruby-simplecov-0.7.1/test/test_deleted_source.rb000066400000000000000000000007101214733607700220400ustar00rootroot00000000000000require 'helper' # Test to verify correct handling of deleted files, # see issue #9 on github class TestDeletedSource < Test::Unit::TestCase on_ruby '1.8', '1.9' do context "A source file which is subsequently deleted" do should "not cause an error" do Dir.chdir(File.join(File.dirname(__FILE__), 'fixtures')) do `ruby deleted_source_sample.rb` assert_equal 0, $?.exitstatus end end end end end ruby-simplecov-0.7.1/test/test_file_list.rb000066400000000000000000000020651214733607700210310ustar00rootroot00000000000000require 'helper' class TestFileList < Test::Unit::TestCase on_ruby "1.9" do context "With a file list from a result" do setup do original_result = {source_fixture('sample.rb') => [nil, 1, 1, 1, nil, nil, 1, 1, nil, nil], source_fixture('app/models/user.rb') => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil], source_fixture('app/controllers/sample_controller.rb') => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil]} @file_list = SimpleCov::Result.new(original_result).files end should("have 13 covered_lines") { assert_equal 13, @file_list.covered_lines } should("have 2 missed_lines") { assert_equal 2, @file_list.missed_lines } should("have 18 never_lines") { assert_equal 18, @file_list.never_lines } should("have 15 lines_of_code") { assert_equal 15, @file_list.lines_of_code } should("have 3 skipped_lines") { assert_equal 3, @file_list.skipped_lines } should "have correct covered_percent" do assert_equal 100.0*13/15, @file_list.covered_percent end end end end ruby-simplecov-0.7.1/test/test_filters.rb000066400000000000000000000061241214733607700205270ustar00rootroot00000000000000require 'helper' class TestFilters < Test::Unit::TestCase on_ruby '1.9' do context "A source file initialized with some coverage data" do setup do @source_file = SimpleCov::SourceFile.new(source_fixture('sample.rb'), [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil]) end should "not match a new SimpleCov::StringFilter 'foobar'" do assert !SimpleCov::StringFilter.new('foobar').matches?(@source_file) end should "not match a new SimpleCov::StringFilter 'some/path'" do assert !SimpleCov::StringFilter.new('some/path').matches?(@source_file) end should "match a new SimpleCov::StringFilter 'test/fixtures'" do assert SimpleCov::StringFilter.new('test/fixtures').matches?(@source_file) end should "match a new SimpleCov::StringFilter 'test/fixtures/sample.rb'" do assert SimpleCov::StringFilter.new('test/fixtures/sample.rb').matches?(@source_file) end should "match a new SimpleCov::StringFilter 'sample.rb'" do assert SimpleCov::StringFilter.new('sample.rb').matches?(@source_file) end should "not match a new SimpleCov::BlockFilter that is not applicable" do assert !SimpleCov::BlockFilter.new(Proc.new {|s| File.basename(s.filename) == 'foo.rb'}).matches?(@source_file) end should "match a new SimpleCov::BlockFilter that is applicable" do assert SimpleCov::BlockFilter.new(Proc.new {|s| File.basename(s.filename) == 'sample.rb'}).matches?(@source_file) end end context "with no filters set up and a basic source file in an array" do setup do SimpleCov.filters = [] @files = [SimpleCov::SourceFile.new(source_fixture('sample.rb'), [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil])] end should "return 0 items after executing SimpleCov.filtered on files when using a 'sample' string filter" do SimpleCov.add_filter "sample" assert_equal 0, SimpleCov.filtered(@files).count end should "return 0 items after executing SimpleCov.filtered on files when using a 'test/fixtures/' string filter" do SimpleCov.add_filter "test/fixtures" assert_equal 0, SimpleCov.filtered(@files).count end should "return 1 item after executing SimpleCov.filtered on files when using a 'fooo' string filter" do SimpleCov.add_filter "fooo" assert_equal 1, SimpleCov.filtered(@files).count end should "return 0 items after executing SimpleCov.filtered on files when using a block filter that returns true" do SimpleCov.add_filter do |src_file| true end assert_equal 0, SimpleCov.filtered(@files).count end should "return 1 item after executing SimpleCov.filtered on files when using an always-false block filter" do SimpleCov.add_filter do |src_file| false end assert_equal 1, SimpleCov.filtered(@files).count end should "return a FileList after filtering" do SimpleCov.add_filter "fooo" assert_equal SimpleCov::FileList, SimpleCov.filtered(@files).class end end end end ruby-simplecov-0.7.1/test/test_merge_helpers.rb000066400000000000000000000104551214733607700217020ustar00rootroot00000000000000require 'helper' class TestMergeHelpers < Test::Unit::TestCase on_ruby '1.9' do context "With two faked coverage resultsets" do setup do SimpleCov.use_merging true @resultset1 = {source_fixture('sample.rb') => [nil, 1, 1, 1, nil, nil, 1, 1, nil, nil], source_fixture('app/models/user.rb') => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil], source_fixture('app/controllers/sample_controller.rb') => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil], source_fixture('resultset1.rb') => [1, 1, 1, 1]} @resultset2 = {source_fixture('sample.rb') => [1, nil, 1, 1, nil, nil, 1, 1, nil, nil], source_fixture('app/models/user.rb') => [nil, 1, 5, 1, nil, nil, 1, 0, nil, nil], source_fixture('app/controllers/sample_controller.rb') => [nil, 3, 1, nil, nil, nil, 1, 0, nil, nil], source_fixture('resultset2.rb') => [nil, 1, 1, nil]} end context "a merge" do setup do assert @merged = @resultset1.merge_resultset(@resultset2) end should "have proper results for sample.rb" do assert_equal [1, 1, 2, 2, nil, nil, 2, 2, nil, nil], @merged[source_fixture('sample.rb')] end should "have proper results for user.rb" do assert_equal [nil, 2, 6, 2, nil, nil, 2, 0, nil, nil], @merged[source_fixture('app/models/user.rb')] end should "have proper results for sample_controller.rb" do assert_equal [nil, 4, 2, 1, nil, nil, 2, 0, nil, nil], @merged[source_fixture('app/controllers/sample_controller.rb')] end should "have proper results for resultset1.rb" do assert_equal [1, 1, 1, 1], @merged[source_fixture('resultset1.rb')] end should "have proper results for resultset2.rb" do assert_equal [nil, 1, 1, nil], @merged[source_fixture('resultset2.rb')] end end # See Github issue #6 should "return an empty hash when the resultset cache file is empty" do File.open(SimpleCov::ResultMerger.resultset_path, "w+") {|f| f.puts ""} assert_equal Hash.new, SimpleCov::ResultMerger.resultset end # See Github issue #6 should "return 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) assert_equal Hash.new, SimpleCov::ResultMerger.resultset end context "and results generated from those" do setup do system "rm #{SimpleCov::ResultMerger.resultset_path}" if File.exist?(SimpleCov::ResultMerger.resultset_path) @result1 = SimpleCov::Result.new(@resultset1) @result1.command_name = "result1" @result2 = SimpleCov::Result.new(@resultset2) @result2.command_name = "result2" end context "with stored results" do setup do assert SimpleCov::ResultMerger.store_result(@result1) assert SimpleCov::ResultMerger.store_result(@result2) end should "have stored data in resultset_path yaml file" do assert File.readlines(SimpleCov::ResultMerger.resultset_path).length > 50 end should "return a hash containing keys ['result1' and 'result2'] for resultset" do assert_equal ['result1', 'result2'], SimpleCov::ResultMerger.resultset.keys.sort end should "return proper values for merged_result" do assert_equal [nil, 2, 6, 2, nil, nil, 2, 0, nil, nil], SimpleCov::ResultMerger.merged_result.source_files.find {|s| s.filename =~ /user/}.lines.map(&:coverage) end context "with second result way above the merge_timeout" do setup do @result2.created_at = Time.now - 172800 # two days ago assert SimpleCov::ResultMerger.store_result(@result2) end should "have only one result in SimpleCov::ResultMerger.results" do assert_equal 1, SimpleCov::ResultMerger.results.length end end context "with merging disabled" do setup { SimpleCov.use_merging false } should "return nil for SimpleCov.result" do assert_nil SimpleCov.result end end end end end end end ruby-simplecov-0.7.1/test/test_result.rb000066400000000000000000000131611214733607700203740ustar00rootroot00000000000000require 'helper' class TestResult < Test::Unit::TestCase on_ruby "1.9" do context "With a (mocked) Coverage.result" do setup do SimpleCov.filters = [] SimpleCov.groups = {} SimpleCov.formatter = nil @original_result = {source_fixture('sample.rb') => [nil, 1, 1, 1, nil, nil, 1, 1, nil, nil], source_fixture('app/models/user.rb') => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil], source_fixture('app/controllers/sample_controller.rb') => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil]} end context "a simple cov result initialized from that" do setup { @result = SimpleCov::Result.new(@original_result) } should "have 3 filenames" do assert_equal 3, @result.filenames.count end should "have 3 source files" do assert_equal 3, @result.source_files.count assert @result.source_files.all? {|s| s.instance_of?(SimpleCov::SourceFile)}, "Not all instances are of SimpleCov::SourceFile type" end should "return an instance of SimpleCov::FileList for source_files and files" do assert_equal SimpleCov::FileList, @result.source_files.class assert_equal SimpleCov::FileList, @result.files.class end should "have files equal to source_files" do assert_equal @result.files, @result.source_files end should "have accurate covered percent" do # in our fixture, there are 13 covered line (result in 1) in all 15 relevant line (result in non-nil) assert_equal 100.0*13/15, @result.covered_percent end context "dumped with to_hash" do setup { @hash = @result.to_hash } should("be a hash") { assert_equal Hash, @hash.class } context "loaded back with from_yaml" do setup { @dumped_result = SimpleCov::Result.from_hash(@hash) } should "have 3 source files" do assert_equal @result.source_files.count, @dumped_result.source_files.count end should "have the same covered_percent" do assert_equal @result.covered_percent, @dumped_result.covered_percent end should "have the same timestamp" do assert_equal @result.created_at.to_i, @dumped_result.created_at.to_i end should "have the same command_name" do assert_equal @result.command_name, @dumped_result.command_name end should "have the same original_result" do assert_equal @result.original_result, @dumped_result.original_result end end end end context "with some filters set up" do setup do SimpleCov.add_filter 'sample.rb' end should "have 2 files in a new simple cov result" do assert_equal 2, SimpleCov::Result.new(@original_result).source_files.length end should "have 80 covered percent" do assert_equal 80, SimpleCov::Result.new(@original_result).covered_percent end end context "with groups set up for all files" do setup 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 @result = SimpleCov::Result.new(@original_result) end should "have 3 groups" do assert_equal 3, @result.groups.length end should "have user.rb in 'Models' group" do assert_equal 'user.rb', File.basename(@result.groups['Models'].first.filename) end should "have sample_controller.rb in 'Controllers' group" do assert_equal 'sample_controller.rb', File.basename(@result.groups['Controllers'].first.filename) end context "and simple formatter being used" do setup {SimpleCov.formatter = SimpleCov::Formatter::SimpleFormatter} should "return a formatted string with result.format!" do assert_equal String, @result.format!.class end end context "and multi formatter being used" do setup do SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[ SimpleCov::Formatter::SimpleFormatter, SimpleCov::Formatter::SimpleFormatter, ] end should "return an array containing formatted string with result.format!" do formated = @result.format! assert_equal 2, formated.count assert_equal String, formated.first.class end end end context "with groups set up that do not match all files" do setup do SimpleCov.configure do add_group 'Models', 'app/models' add_group 'Controllers', 'app/controllers' end @result = SimpleCov::Result.new(@original_result) end should "have 3 groups" do assert_equal 3, @result.groups.length end should "have 1 item per group" do @result.groups.each do |name, files| assert_equal 1, files.length, "Group #{name} should have 1 file" end end should "have sample.rb in 'Ungrouped' group" do assert_equal 'sample.rb', File.basename(@result.groups['Ungrouped'].first.filename) end should "return all groups as instances of SimpleCov::FileList" do @result.groups.each do |name, files| assert_equal SimpleCov::FileList, files.class end end end end end end ruby-simplecov-0.7.1/test/test_return_codes.rb000066400000000000000000000020721214733607700215510ustar00rootroot00000000000000require 'helper' # Make sure that exit codes of tests are propagated properly when using # simplecov. See github issue #5 class TestReturnCodes < Test::Unit::TestCase on_ruby '1.8', '1.9' do context "Inside fixtures/frameworks" do setup do @current_dir = Dir.getwd Dir.chdir(File.join(File.dirname(__FILE__), 'fixtures', 'frameworks')) FileUtils.rm_rf('./coverage') end should "have return code 0 when running testunit_good.rb" do `ruby testunit_good.rb` assert_equal 0, $?.exitstatus end should "have return code 0 when running rspec_good.rb" do `rspec rspec_good.rb` assert_equal 0, $?.exitstatus end should "have non-0 return code when running testunit_bad.rb" do `ruby testunit_bad.rb` assert_not_equal 0, $?.exitstatus end should "have return code 1 when running rspec_bad.rb" do `rspec rspec_bad.rb` assert_not_equal 0, $?.exitstatus end teardown do Dir.chdir(@current_dir) end end end end ruby-simplecov-0.7.1/test/test_source_file.rb000066400000000000000000000060161214733607700213560ustar00rootroot00000000000000require 'helper' class TestSourceFile < Test::Unit::TestCase on_ruby '1.9' do COVERAGE_FOR_SAMPLE_RB = [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil, nil, nil, nil, nil, nil, nil] context "A source file initialized with some coverage data" do setup do @source_file = SimpleCov::SourceFile.new(source_fixture('sample.rb'), COVERAGE_FOR_SAMPLE_RB) end should "have a filename" do assert @source_file.filename end should "have source equal to src" do assert_equal @source_file.source, @source_file.src end should "have source_lines equal to lines" do assert_equal @source_file.source_lines, @source_file.lines end should "have 16 source lines" do assert_equal 16, @source_file.lines.count end should "have all source lines of type SimpleCov::SourceFile::Line" do assert @source_file.lines.all? {|l| l.instance_of?(SimpleCov::SourceFile::Line)} end should "have 'class Foo' as line(2).source" do assert_equal "class Foo\n", @source_file.line(2).source end should "return lines number 2, 3, 4, 7 for covered_lines" do assert_equal [2, 3, 4, 7], @source_file.covered_lines.map(&:line) end should "return lines number 8 for missed_lines" do assert_equal [8], @source_file.missed_lines.map(&:line) end should "return lines number 1, 5, 6, 9, 10, 11, 15, 16 for never_lines" do assert_equal [1, 5, 6, 9, 10, 11, 15, 16], @source_file.never_lines.map(&:line) end should "return line numbers 12, 13, 14 for skipped_lines" do assert_equal [12, 13, 14], @source_file.skipped_lines.map(&:line) end should "have 80% covered_percent" do assert_equal 80.0, @source_file.covered_percent end end context "Simulating potential Ruby 1.9 defect -- see Issue #56" do setup do @source_file = SimpleCov::SourceFile.new(source_fixture('sample.rb'), COVERAGE_FOR_SAMPLE_RB + [nil]) end should "have 16 source lines regardless of extra data in coverage array" do # Do not litter test output with known warning capture_stderr { assert_equal 16, @source_file.lines.count } end should "print a warning to stderr if coverage array contains more data than lines in the file" do captured_output = capture_stderr do @source_file.lines end assert_match(/^Warning: coverage data provided/, captured_output) end end context "Encoding" do should "handle utf-8 encoded source files" do source_file = SimpleCov::SourceFile.new(source_fixture('utf-8.rb'), [nil, nil, 1]) assert_nothing_raised do source_file.process_skipped_lines! end end should "handle iso-8859 encoded source files" do source_file = SimpleCov::SourceFile.new(source_fixture('iso-8859.rb'), [nil, nil, 1]) assert_nothing_raised do source_file.process_skipped_lines! end end end end end ruby-simplecov-0.7.1/test/test_source_file_line.rb000066400000000000000000000053751214733607700223740ustar00rootroot00000000000000require 'helper' class TestSourceFileLine < Test::Unit::TestCase on_ruby '1.9' do context "A source line" do setup do @line = SimpleCov::SourceFile::Line.new('# the ruby source', 5, 3) end subject { @line } should 'return "# the ruby source" as src' do assert_equal '# the ruby source', @line.src end should 'return the same for source as for src' do assert_equal @line.src, @line.source end should 'have line number 5' do assert_equal 5, @line.line_number end should 'have equal line_number, line and number' do assert_equal @line.line_number, @line.line assert_equal @line.line_number, @line.number end context "flagged as skipped!" do setup { @line.skipped! } should_not_be :covered? should_be :skipped? should_not_be :missed? should_not_be :never? should_have :status, 'skipped' end end context "A source line with coverage" do setup do @line = SimpleCov::SourceFile::Line.new('# the ruby source', 5, 3) end subject { @line } should "have coverage of 3" do assert_equal 3, @line.coverage end should_be :covered? should_not_be :skipped? should_not_be :missed? should_not_be :never? should_have :status, 'covered' end context "A source line without coverage" do setup do @line = SimpleCov::SourceFile::Line.new('# the ruby source', 5, 0) end subject { @line } should "have coverage of 0" do assert_equal 0, @line.coverage end should_not_be :covered? should_not_be :skipped? should_be :missed? should_not_be :never? should_have :status, 'missed' end context "A source line with no code" do setup do @line = SimpleCov::SourceFile::Line.new('# the ruby source', 5, nil) end subject { @line } should "have nil coverage" do assert_nil @line.coverage end should_not_be :covered? should_not_be :skipped? should_not_be :missed? should_be :never? should_have :status, 'never' end should "raise ArgumentError when initialized with invalid src" do assert_raise ArgumentError do SimpleCov::SourceFile::Line.new(:symbol, 5, 3) end end should "raise ArgumentError when initialized with invalid line_number" do assert_raise ArgumentError do SimpleCov::SourceFile::Line.new("some source", "five", 3) end end should "raise ArgumentError when initialized with invalid coverage" do assert_raise ArgumentError do SimpleCov::SourceFile::Line.new("some source", 5, "three") end end end end