simplecov-0.14.1/0000755000004100000410000000000013130232776013632 5ustar www-datawww-datasimplecov-0.14.1/Rakefile0000644000004100000410000000213413130232776015277 0ustar www-datawww-data#!/usr/bin/env rake require "rubygems" require "bundler/setup" 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 "rspec/core/rake_task" RSpec::Core::RakeTask.new(:spec) do |spec| spec.pattern = FileList["spec/*_spec.rb"] end begin require "rubocop/rake_task" RuboCop::RakeTask.new rescue LoadError task :rubocop do $stderr.puts "Rubocop is disabled" end end # Cucumber integration test suite is for impls that work with simplecov only - a.k.a. 1.9+ if RUBY_VERSION.start_with? "1.8" task :default => [:spec] else require "cucumber/rake/task" Cucumber::Rake::Task.new if RUBY_VERSION.start_with? "1.9" task :default => [:spec, :cucumber] else task :default => [:rubocop, :spec, :cucumber] end end simplecov-0.14.1/Gemfile0000644000004100000410000000235013130232776015125 0ustar www-datawww-datasource "https://rubygems.org" # Uncomment this to use local copy of simplecov-html in development when checked out # gem 'simplecov-html', :path => ::File.dirname(__FILE__) + '/../simplecov-html' # Uncomment this to use development version of html formatter from github # gem 'simplecov-html', :github => 'colszowka/simplecov-html' gem "rake", Gem::Version.new(RUBY_VERSION) < Gem::Version.new("1.9.3") ? "~>10.3" : ">= 10.3" group :test do gem "rspec", ">= 3.2" # Older versions of some gems required for Ruby 1.8.7 support platforms :ruby_18 do gem "activesupport", "~> 3.2.21" gem "i18n", "~> 0.6.11" end platforms :ruby_18, :ruby_19 do gem "mime-types", "~> 1.25" gem "addressable", "~> 2.3.0" end platforms :ruby_18, :ruby_19, :ruby_20, :ruby_21 do gem "rack", "~> 1.6" end platforms :jruby, :ruby_19, :ruby_20, :ruby_21, :ruby_22, :ruby_23, :ruby_24, :ruby_25 do gem "aruba", "~> 0.7.4" gem "capybara" gem "nokogiri", RUBY_VERSION < "2.1" ? "~> 1.6.0" : ">= 1.7" gem "cucumber" gem "phantomjs", "~> 2.1" gem "poltergeist" gem "rubocop" unless RUBY_VERSION.start_with?("1.") gem "test-unit" end gem "json", RUBY_VERSION.start_with?("1.") ? "~> 1.8" : "~> 2.0" end gemspec simplecov-0.14.1/doc/0000755000004100000410000000000013130232776014377 5ustar www-datawww-datasimplecov-0.14.1/doc/alternate-formatters.md0000644000004100000410000000242013130232776021062 0ustar www-datawww-data## Alternate coverage report formatters The community around simplecov provides a whole bunch of alternate formatters beyond the official [simplecov-html](https://github.com/colszowka/simplecov-html) gem. If you have built or found one that is missing here, please send a Pull Request for this document! #### [simplecov-badge](https://github.com/matthew342/simplecov-badge) *by Matt Hale* A formatter that generates a coverage badge for use in your project's readme using ImageMagick. #### [simplecov-cobertura](https://github.com/dashingrocket/simplecov-cobertura) *by Jesse Bowes* A formatter that generates Cobertura XML. #### [simplecov-csv](https://github.com/fguillen/simplecov-csv) *by Fernando Guillen* CSV formatter for SimpleCov #### [simplecov-json](https://github.com/vicentllongo/simplecov-json) *by Vicent Llongo* JSON formatter for SimpleCov #### [simplecov-rcov](https://github.com/fguillen/simplecov-rcov) *by Fernando Guillen* "The target of this formatter is to cheat on Hudson so I can use the Ruby metrics plugin with SimpleCov." #### [simplecov-single_file_reporter](https://github.com/grosser/simplecov-single_file_reporter) *by [Michael Grosser](http://grosser.it)* A formatter that prints the coverage of the file under test when you run a single test file.simplecov-0.14.1/doc/commercial-services.md0000644000004100000410000000173513130232776020663 0ustar www-datawww-data## Commercial Services with SimpleCov integration There is a bunch of services that offer integration with your existing CI pipeline and SimpleCov coverage reports. Please note these are not associated with the SimpleCov project itself, so please report problems with these integrations with their respective owners. #### [codeclimate](https://github.com/codeclimate/ruby-test-reporter) *by [Code Climate](https://codeclimate.com/)* Upload coverage reports to [codeclimate.com](https://codeclimate.com/), a hosted software quality analysis and that also includes coverage reporting. #### [codecov](https://github.com/codecov/codecov-ruby) *by [Codecov](https://codecov.io/)* Upload coverage reports to [codecov.io](https://codecov.io/), a hosted coverage reporting solution. #### [coveralls](https://github.com/lemurheavy/coveralls-ruby) *by [Coveralls](https://coveralls.io/)* Upload coverage reports to [coveralls.io](https://coveralls.io/), a hosted coverage reporting solution. simplecov-0.14.1/doc/editor-integration.md0000644000004100000410000000062513130232776020533 0ustar www-datawww-data## Editor integration Some editors have a graphical integration for the simplecov gem. #### [Atom Editor: coverage](https://atom.io/packages/coverage) *by Philip Giuliani* Adds an overview of your current test coverage to Atom. #### [cadre](https://github.com/nyarly/cadre) *by Judson Lester* Includes a formatter for Simplecov that emits a Vim script to mark up code files with coverage information.simplecov-0.14.1/features/0000755000004100000410000000000013130232776015450 5ustar www-datawww-datasimplecov-0.14.1/features/refuse_coverage_drop.feature0000644000004100000410000000457613130232776023231 0ustar www-datawww-data@test_unit @config Feature: Exit code should be non-zero if the overall coverage decreases. And last_run file should not be overwritten with new coverage value. Scenario: refuse_coverage_drop configured Given SimpleCov for Test/Unit is configured with: """ require 'simplecov' SimpleCov.start do add_filter 'test.rb' refuse_coverage_drop end """ When I run `bundle exec rake test` Then the exit status should be 0 And a file named "coverage/.last_run.json" should exist And the file "coverage/.last_run.json" should contain: """ { "result": { "covered_percent": 88.1 } } """ 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 And the file "coverage/.last_run.json" should contain: """ { "result": { "covered_percent": 88.1 } } """ Scenario: refuse_coverage_drop not configured updates resultset Given SimpleCov for Test/Unit is configured with: """ require 'simplecov' SimpleCov.start do add_filter 'test.rb' end """ When I run `bundle exec rake test` Then the exit status should be 0 And a file named "coverage/.last_run.json" should exist And the file "coverage/.last_run.json" should contain: """ { "result": { "covered_percent": 88.1 } } """ Given a file named "lib/faked_project/missed.rb" with: """ class UncoveredSourceCode def foo never_reached rescue => err but no one cares about invalid ruby here end end """ When I run `bundle exec rake test` Then the exit status should be 0 And a file named "coverage/.last_run.json" should exist And the file "coverage/.last_run.json" should contain: """ { "result": { "covered_percent": 84.78 } } """ simplecov-0.14.1/features/step_definitions/0000755000004100000410000000000013130232776021016 5ustar www-datawww-datasimplecov-0.14.1/features/step_definitions/transformers.rb0000644000004100000410000000105213130232776024066 0ustar www-datawww-data# # 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 |_| files = nil # Avoid shadowing in_current_directory { files = Dir["spec/**/*_spec.rb"] } "bundle exec rspec #{files.sort.join(' ')}" end simplecov-0.14.1/features/step_definitions/web_steps.rb0000644000004100000410000000263413130232776023343 0ustar www-datawww-datamodule WithinHelpers def with_scope(locator) locator ? within(locator) { yield } : yield end end World(WithinHelpers) When /^I open the coverage report$/ do visit "/" end Given /^(?:|I )am on (.+)$/ do |path| visit path end When /^(?:|I )go to (.+)$/ do |path| visit path end When /^(?:|I )press "([^"]*)"(?: within "([^"]*)")?$/ do |button, selector| with_scope(selector) do click_button(button) end end When /^(?:|I )follow "([^"]*)"(?: within "([^"]*)")?$/ do |link, selector| with_scope(selector) do click_link(link) end end Then /^(?:|I )should see "([^"]*)"(?: within "([^"]*)")?$/ do |text, selector| with_scope(selector) do expect(page).to have_content(text) end end Then /^(?:|I )should see \/([^\/]*)\/(?: within "([^"]*)")?$/ do |regexp, selector| regexp = Regexp.new(regexp) with_scope(selector) do expect(page).to have_xpath("//*", :text => regexp) end end Then /^(?:|I )should not see "([^"]*)"(?: within "([^"]*)")?$/ do |text, selector| with_scope(selector) do expect(page).to have_no_content(text) end end Then /^(?:|I )should not see \/([^\/]*)\/(?: within "([^"]*)")?$/ do |regexp, selector| regexp = Regexp.new(regexp) with_scope(selector) do expect(page).to have_no_xpath("//*", :text => regexp) end end Then /^show me the page$/ do save_and_open_page # rubocop:disable Lint/Debugger end Then /^print the page$/ do puts page.body end simplecov-0.14.1/features/step_definitions/html_steps.rb0000644000004100000410000000305413130232776023527 0ustar www-datawww-datamodule 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 expect(expected_groups.count).to eq(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 expect(file_count_in_group).to eq(group["files"].to_i) with_scope "h2" do expect(page).to have_content(group["name"]) expect(page).to have_content(group["coverage"]) end end end end Then /^I should see the source files:$/ do |table| expected_files = table.hashes expect(expected_files.length).to eq(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("h4 > span").text} } expect(files.sort_by { |hsh| hsh["name"] }).to eq(expected_files.sort_by { |hsh| hsh["name"] }) end Then /^there should be (\d+) skipped lines in the source files$/ do |expected_count| expect(all(".source_table ol li.skipped").count).to eq(expected_count.to_i) end simplecov-0.14.1/features/step_definitions/simplecov_steps.rb0000644000004100000410000000410413130232776024561 0ustar www-datawww-data# 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 = begin 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 end steps %( Given a file named "#{framework_dir}/simplecov_config.rb" with: """ #{config_body} """ ) end When /^I open the coverage report generated with `([^`]+)`$/ do |command| steps %( When I successfully run `#{command}` Then a coverage report should have been generated When I open the coverage report ) end Then /^a coverage report should have been generated(?: in "([^"]*)")?$/ do |coverage_dir| coverage_dir ||= "coverage" steps %( Then the output should contain "Coverage report generated" And a directory named "#{coverage_dir}" should exist And the following files should exist: | #{coverage_dir}/index.html | | #{coverage_dir}/.resultset.json | ) end Then /^no coverage report should have been generated(?: in "([^"]*)")?$/ do |coverage_dir| coverage_dir ||= "coverage" steps %( Then the output should not contain "Coverage report generated" And a directory named "#{coverage_dir}" should not exist And the following files should not exist: | #{coverage_dir}/index.html | | #{coverage_dir}/.resultset.json | ) end Then /^the report should be based upon:$/ do |table| frameworks = table.raw.flatten steps %( Then the output should contain "Coverage report generated for #{frameworks.join(', ')}" And I should see "using #{frameworks.join(', ')}" within "#footer" ) end # This is necessary to ensure timing-dependant tests like the merge timeout # do not fail on powerful machines. When /^I wait for (\d+) seconds$/ do |seconds| sleep seconds.to_i end simplecov-0.14.1/features/config_project_name.feature0000644000004100000410000000147013130232776023022 0ustar www-datawww-data@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" within "title" Scenario: Custom name Given SimpleCov for Test/Unit is configured with: """ require 'simplecov' SimpleCov.start { project_name "Superfancy 2.0" } """ When I open the coverage report generated with `bundle exec rake test` Then I should see "Code coverage for Superfancy 2.0" within "title" simplecov-0.14.1/features/config_coverage_dir.feature0000644000004100000410000000173213130232776023006 0ustar www-datawww-data@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 Scenario: Given SimpleCov for Test/Unit is configured with: """ require 'simplecov' SimpleCov.start do coverage_dir '/tmp/test/simplecov' end """ When I successfully run `bundle exec rake test` Then a coverage report should have been generated in "/tmp/test/simplecov" And a directory named "coverage" should not exist simplecov-0.14.1/features/config_profiles.feature0000644000004100000410000000242613130232776022201 0ustar www-datawww-data@test_unit @config @profiles Feature: In order to re-use SimpleCov settings across projects, profiles can be defined that hold configuration settings that can be loaded at once. Background: Given SimpleCov for Test/Unit is configured with: """ require 'simplecov' """ Scenario: Defining and using a custom profile Given a file named ".simplecov" with: """ SimpleCov.profiles.define 'custom_command' do command_name "Profile Command" end SimpleCov.start do load_profile 'test_frameworks' load_profile 'custom_command' end """ When I open the coverage report generated with `bundle exec rake test` Then I should see "4 files in total." And I should see "using Profile Command" within "#footer" Scenario: Using existing profile in custom profile and supplying profile to start command Given a file named ".simplecov" with: """ SimpleCov.profiles.define 'my_profile' do load_profile 'test_frameworks' command_name "My Profile" end SimpleCov.start 'my_profile' """ When I open the coverage report generated with `bundle exec rake test` Then I should see "4 files in total." And I should see "using My Profile" within "#footer" simplecov-0.14.1/features/config_styles.feature0000644000004100000410000000705613130232776021705 0ustar www-datawww-data@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: Inside start block, using instance var from outside Given a file named ".simplecov" with: """ @filter = 'test' SimpleCov.start do add_filter @filter command_name 'Config Test Runner' end """ When I open the coverage report generated with `bundle exec rake test` Then I should see "4 files in total." And I should see "using Config Test Runner" within "#footer" Scenario: Inside start block, using local var from outside Given a file named ".simplecov" with: """ filter = 'test' SimpleCov.start do add_filter filter command_name 'Config Test Runner' end """ When I open the coverage report generated with `bundle exec rake test` Then I should see "4 files in total." And I should see "using Config Test Runner" within "#footer" Scenario: Explicitly before start block Given a file named ".simplecov" with: """ SimpleCov.add_filter 'test' SimpleCov.command_name 'Config Test Runner' SimpleCov.start """ When I open the coverage report generated with `bundle exec rake test` Then I should see "4 files in total." And I should see "using Config Test Runner" within "#footer" Scenario: Explicitly after start block Given a file named ".simplecov" with: """ SimpleCov.start SimpleCov.add_filter 'test' SimpleCov.command_name 'Config Test Runner' """ When I open the coverage report generated with `bundle exec rake test` Then I should see "4 files in total." And I should see "using Config Test Runner" within "#footer" Scenario: Using configure block after start Given a file named ".simplecov" with: """ SimpleCov.start SimpleCov.configure do add_filter 'test' command_name 'Config Test Runner' end """ When I open the coverage report generated with `bundle exec rake test` Then I should see "4 files in total." And I should see "using Config Test Runner" within "#footer" Scenario: Using configure block before start Given a file named ".simplecov" with: """ SimpleCov.configure do add_filter 'test' command_name 'Config Test Runner' end SimpleCov.start """ When I open the coverage report generated with `bundle exec rake test` Then I should see "4 files in total." And I should see "using Config Test Runner" within "#footer" Scenario: Mixing configure and start block config Given a file named ".simplecov" with: """ SimpleCov.configure do command_name 'Config Test Runner' end SimpleCov.start do add_filter 'test' end """ When I open the coverage report generated with `bundle exec rake test` Then I should see "4 files in total." And I should see "using Config Test Runner" within "#footer" simplecov-0.14.1/features/rspec_groups_and_filters_basic.feature0000644000004100000410000000172013130232776025253 0ustar www-datawww-data@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 % | simplecov-0.14.1/features/test_unit_groups_and_filters_basic.feature0000644000004100000410000000173113130232776026157 0ustar www-datawww-data@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 % | simplecov-0.14.1/features/merging_test_unit_and_rspec.feature0000644000004100000410000000256013130232776024574 0ustar www-datawww-data@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 % | simplecov-0.14.1/features/config_tracked_files.feature0000644000004100000410000000176413130232776023161 0ustar www-datawww-data@test_unit Feature: Using the setting `tracked_files` should add files that were not required to the report. Scenario: Given SimpleCov for Test/Unit is configured with: """ require 'simplecov' SimpleCov.start do track_files "lib/**/*.rb" end """ When I open the coverage report generated with `bundle exec rake test` Then I should see the groups: | name | coverage | files | | All Files | 76.81% | 7 | And I should see the source files: | name | coverage | | lib/faked_project.rb | 100.0 % | | lib/faked_project/untested_class.rb | 0.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 % | simplecov-0.14.1/features/minimum_coverage.feature0000644000004100000410000000265013130232776022356 0ustar www-datawww-data@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 simplecov-0.14.1/features/config_command_name.feature0000644000004100000410000000265113130232776022774 0ustar www-datawww-data@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 | Scenario: RSpec auto detection with spec/features Given SimpleCov for RSpec is configured with: """ require 'simplecov' SimpleCov.start """ And a file named "spec/features/foobar_spec.rb" with: """ """ When I open the coverage report generated with `bundle exec rspec spec` Then the report should be based upon: | RSpec | simplecov-0.14.1/features/maximum_coverage_drop.feature0000644000004100000410000000435413130232776023407 0ustar www-datawww-data@test_unit @config Feature: Exit code should be non-zero if the overall coverage decreases by more than the maximum_coverage_drop threshold. Scenario: maximum_coverage_drop configured cam cause spec failure Given SimpleCov for Test/Unit is configured with: """ require 'simplecov' SimpleCov.start do add_filter 'test.rb' maximum_coverage_drop 3.14 end """ When I run `bundle exec rake test` Then the exit status should be 0 And a file named "coverage/.last_run.json" should exist Given a file named "lib/faked_project/missed.rb" with: """ class UncoveredSourceCode def foo never_reached rescue => err but no one cares about invalid ruby here end end """ When I run `bundle exec rake test` Then the exit status should not be 0 And the output should contain "Coverage has dropped by 3.32% since the last time (maximum allowed: 3.14%)." And a file named "coverage/.last_run.json" should exist And the file "coverage/.last_run.json" should contain: """ { "result": { "covered_percent": 88.1 } } """ Scenario: maximum_coverage_drop not configured updates resultset Given SimpleCov for Test/Unit is configured with: """ require 'simplecov' SimpleCov.start do add_filter 'test.rb' end """ When I run `bundle exec rake test` Then the exit status should be 0 And a file named "coverage/.last_run.json" should exist And the file "coverage/.last_run.json" should contain: """ { "result": { "covered_percent": 88.1 } } """ Given a file named "lib/faked_project/missed.rb" with: """ class UncoveredSourceCode def foo never_reached rescue => err but no one cares about invalid ruby here end end """ When I run `bundle exec rake test` Then the exit status should be 0 And a file named "coverage/.last_run.json" should exist And the file "coverage/.last_run.json" should contain: """ { "result": { "covered_percent": 84.78 } } """ simplecov-0.14.1/features/skipping_code_blocks_manually.feature0000644000004100000410000000422613130232776025106 0ustar www-datawww-data@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 7 skipped lines in the source files And the report should be based upon: | Unit Tests | Scenario: Number of spaces should not mix up nocov results Given a file named "lib/faked_project/nocov.rb" with: """ class SourceCodeWithNocov # :nocov: def some_weird_code never_reached rescue => err but no one cares about invalid ruby here end # :nocov: end """ When I open the coverage report generated with `bundle exec rake test` Then 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 7 skipped lines in the source files And the report should be based upon: | Unit Tests | simplecov-0.14.1/features/rspec_fails_on_initialization.feature0000644000004100000410000000061013130232776025117 0ustar www-datawww-data@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 simplecov-0.14.1/features/config_merge_timeout.feature0000644000004100000410000000224413130232776023221 0ustar www-datawww-data@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 5 end """ Given SimpleCov for RSpec is configured with: """ require 'simplecov' SimpleCov.start do merge_timeout 5 end """ When I open the coverage report generated with `bundle exec rake test` Then the report should be based upon: | Unit Tests | When I wait for 5 seconds And I open the coverage report generated with `bundle exec rspec spec` Then the report should be based upon: | RSpec | simplecov-0.14.1/features/config_formatters.feature0000644000004100000410000000445613130232776022551 0ustar www-datawww-data@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.formatters = [ SimpleCov::Formatter::SimpleFormatter, Class.new do def format(result) raise "Unable to format" end end ] SimpleCov.at_exit do puts SimpleCov.result.format!.join end SimpleCov.start do add_group 'Libs', 'lib/faked_project/' end """ When I successfully run `bundle exec rake test` Then the output should contain "lib/faked_project/meta_magic.rb (coverage: 100.0%)" And the output should match /Formatter [^\s]* failed with RuntimeError: Unable to format/ Scenario: With multiple formatters Given SimpleCov for Test/Unit is configured with: """ require 'simplecov' SimpleCov.formatters = [ SimpleCov::Formatter::SimpleFormatter, Class.new do def format(result) raise "Unable to format" end end ] SimpleCov.at_exit do puts SimpleCov.result.format!.join end SimpleCov.start do add_group 'Libs', 'lib/faked_project/' end """ When I successfully run `bundle exec rake test` Then the output should contain "lib/faked_project/meta_magic.rb (coverage: 100.0%)" And the output should match /Formatter [^\s]* failed with RuntimeError: Unable to format/ simplecov-0.14.1/features/rspec_groups_using_filter_class.feature0000644000004100000410000000311513130232776025477 0ustar www-datawww-data@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 | 91.8% | 7 | | By filter class | 78.26% | 2 | | By string | 100.0% | 1 | | Ungrouped | 100.0% | 4 | And I should see the source files: | name | coverage | | lib/faked_project/framework_specific.rb | 75.0 % | | lib/faked_project/some_class.rb | 80.0 % | | lib/faked_project.rb | 100.0 % | | lib/faked_project/meta_magic.rb | 100.0 % | | spec/forking_spec.rb | 100.0 % | | spec/meta_magic_spec.rb | 100.0 % | | spec/some_class_spec.rb | 100.0 % | simplecov-0.14.1/features/test_unit_without_simplecov.feature0000644000004100000410000000102313130232776024703 0ustar www-datawww-data@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 simplecov-0.14.1/features/config_autoload.feature0000644000004100000410000000272113130232776022164 0ustar www-datawww-data@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 % | simplecov-0.14.1/features/test_unit_groups_and_filters_complex.feature0000644000004100000410000000240413130232776026543 0ustar www-datawww-data@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 % | simplecov-0.14.1/features/cucumber_basic.feature0000644000004100000410000000177013130232776022000 0ustar www-datawww-data@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 | simplecov-0.14.1/features/test_unit_groups_using_filter_class.feature0000644000004100000410000000303313130232776026400 0ustar www-datawww-data@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 % | simplecov-0.14.1/features/unicode_compatiblity.feature0000644000004100000410000000412113130232776023231 0ustar www-datawww-data@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 | simplecov-0.14.1/features/rspec_groups_and_filters_complex.feature0000644000004100000410000000252513130232776025645 0ustar www-datawww-data@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_group 'By array', ['project/meta_magic'] add_filter 'faked_project.rb' # Remove all files that include "describe" in their source add_filter {|src_file| src_file.lines.any? {|line| line.src =~ /describe/ } } add_filter {|src_file| src_file.covered_percent < 100 } end """ When I open the coverage report generated with `bundle exec rspec spec` Then I should see the groups: | name | coverage | files | | All Files | 100.0% | 1 | | By block | 100.0% | 1 | | By string | 100.0% | 1 | | By array | 100.0% | 1 | And I should see the source files: | name | coverage | | lib/faked_project/meta_magic.rb | 100.0 % | simplecov-0.14.1/features/rspec_without_simplecov.feature0000644000004100000410000000101013130232776023775 0ustar www-datawww-data@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 simplecov-0.14.1/features/test_unit_basic.feature0000644000004100000410000000246513130232776022213 0ustar www-datawww-data@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 | simplecov-0.14.1/features/support/0000755000004100000410000000000013130232776017164 5ustar www-datawww-datasimplecov-0.14.1/features/support/env.rb0000644000004100000410000000256313130232776020307 0ustar www-datawww-dataif RUBY_VERSION < "1.9" $stderr.puts "Sorry, Cucumber features are only meant to run on Ruby 1.9+ :(" exit 0 end require "bundler" Bundler.setup require "aruba/cucumber" require "aruba/jruby" if RUBY_ENGINE == "jruby" require "capybara/cucumber" require "phantomjs/poltergeist" # Fake rack app for capybara that just returns the latest coverage report from aruba temp project dir Capybara.app = lambda { |env| request_path = env["REQUEST_PATH"] || "/" request_path = "/index.html" if request_path == "/" [ 200, {"Content-Type" => "text/html"}, [File.read(File.join(File.dirname(__FILE__), "../../tmp/aruba/project/coverage", request_path))], ] } Capybara.default_driver = Capybara.javascript_driver = :poltergeist Capybara.configure do |config| config.ignore_hidden_elements = false end Before do # JRuby takes it's time... See https://github.com/cucumber/aruba/issues/134 @aruba_timeout_seconds = RUBY_ENGINE == "jruby" ? 60 : 20 this_dir = File.dirname(__FILE__) # Clean up and create blank state for fake project in_current_directory do FileUtils.rm_rf "project" FileUtils.cp_r File.join(this_dir, "../../spec/faked_project/"), "project" end step 'I cd to "project"' end # Workaround for https://github.com/cucumber/aruba/pull/125 Aruba.configure do |config| config.before_cmd do set_env("JRUBY_OPTS", "--dev --debug") end end simplecov-0.14.1/features/rspec_basic.feature0000644000004100000410000000244713130232776021311 0ustar www-datawww-data@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 | 91.8% | 7 | 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/forking_spec.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. simplecov-0.14.1/features/config_nocov_token.feature0000644000004100000410000000463413130232776022705 0ustar www-datawww-data@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 7 skipped lines in the source files And the report should be based upon: | Unit Tests | Scenario: Custom nocov token using skip_token Given SimpleCov for Test/Unit is configured with: """ require 'simplecov' SimpleCov.start 'test_frameworks' do skip_token 'skippit' end """ Given a file named "lib/faked_project/nocov.rb" with: """ class SourceCodeWithNocov # :skippit: def some_weird_code never_reached rescue => err but no one cares about invalid ruby here end # :skippit: end """ When I open the coverage report generated with `bundle exec rake test` Then I should see the source files: | name | coverage | | lib/faked_project.rb | 100.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 7 skipped lines in the source files And the report should be based upon: | Unit Tests | simplecov-0.14.1/features/config_deactivate_merging.feature0000644000004100000410000000242313130232776024174 0ustar www-datawww-data@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 | simplecov-0.14.1/.rspec0000644000004100000410000000004113130232776014742 0ustar www-datawww-data--color --order random --warning simplecov-0.14.1/MIT-LICENSE0000644000004100000410000000205313130232776015266 0ustar www-datawww-dataCopyright (c) 2010-2015 Christoph Olszowka Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. simplecov-0.14.1/spec/0000755000004100000410000000000013130232776014564 5ustar www-datawww-datasimplecov-0.14.1/spec/helper.rb0000644000004100000410000000144113130232776016370 0ustar www-datawww-datarequire "rspec" # loaded before simplecov to also capture parse time warnings require "support/fail_rspec_on_ruby_warning" require "simplecov" SimpleCov.coverage_dir("tmp/coverage") def source_fixture(filename) File.expand_path(File.join(File.dirname(__FILE__), "fixtures", filename)) end # 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 simplecov-0.14.1/spec/1_8_fallbacks_spec.rb0000644000004100000410000000167213130232776020522 0ustar www-datawww-datarequire "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 # if RUBY_VERSION.start_with? "1.8" describe "Ruby 1.8 fallback" do it "return false when calling SimpleCov.start" do expect(SimpleCov.start).to be false end it "return false when calling SimpleCov.start with a block" do expect(SimpleCov.start { raise "Shouldn't reach this!" }).to be false end it "return false when calling SimpleCov.configure with a block" do expect(SimpleCov.configure { raise "Shouldn't reach this!" }).to be false end it "allow to define a profile" do expect do SimpleCov.profiles.define "testprofile" do add_filter "/config/" end end.not_to raise_error end end end simplecov-0.14.1/spec/result_merger_spec.rb0000644000004100000410000000725413130232776021012 0ustar www-datawww-datarequire "helper" if SimpleCov.usable? describe SimpleCov::ResultMerger do describe "with two faked coverage resultsets" do before 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], source_fixture("parallel_tests.rb") => [nil, 0, nil, 0], source_fixture("conditionally_loaded_1.rb") => [nil, 0, 1], # loaded only in the first resultset } @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], source_fixture("parallel_tests.rb") => [nil, nil, 0, 0], source_fixture("conditionally_loaded_2.rb") => [nil, 0, 1], # loaded only in the second resultset } end # See Github issue #6 it "returns an empty hash when the resultset cache file is empty" do File.open(SimpleCov::ResultMerger.resultset_path, "w+") { |f| f.puts "" } expect(SimpleCov::ResultMerger.resultset).to be_empty end # See Github issue #6 it "returns an empty hash when the resultset cache file is not present" do system "rm #{SimpleCov::ResultMerger.resultset_path}" if File.exist?(SimpleCov::ResultMerger.resultset_path) expect(SimpleCov::ResultMerger.resultset).to be_empty end context "and results generated from those" do before 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 before do SimpleCov::ResultMerger.store_result(@result1) SimpleCov::ResultMerger.store_result(@result2) end it "has stored data in resultset_path JSON file" do expect(File.readlines(SimpleCov::ResultMerger.resultset_path).length).to be > 50 end it "returns a hash containing keys ['result1' and 'result2'] for resultset" do expect(SimpleCov::ResultMerger.resultset.keys.sort).to eq %w(result1 result2) end it "returns proper values for merged_result" do expect(SimpleCov::ResultMerger.merged_result.source_files.find { |s| s.filename =~ /user/ }.lines.map(&:coverage)).to eq([nil, 2, 6, 2, nil, nil, 2, 0, nil, nil]) end context "with second result way above the merge_timeout" do before do @result2.created_at = Time.now - 172_800 # two days ago SimpleCov::ResultMerger.store_result(@result2) end it "has only one result in SimpleCov::ResultMerger.results" do expect(SimpleCov::ResultMerger.results.length).to eq(1) end end context "with merging disabled" do before { SimpleCov.use_merging false } it "returns nil for SimpleCov.result" do expect(SimpleCov.result).to be_nil end end end end end end end simplecov-0.14.1/spec/command_guesser_spec.rb0000644000004100000410000000374313130232776021305 0ustar www-datawww-datarequire "helper" if SimpleCov.usable? describe SimpleCov::CommandGuesser do subject { SimpleCov::CommandGuesser } it 'correctly guesses "Unit Tests" for unit tests' do subject.original_run_command = "/some/path/test/units/foo_bar_test.rb" expect(subject.guess).to eq("Unit Tests") subject.original_run_command = "test/units/foo.rb" expect(subject.guess).to eq("Unit Tests") subject.original_run_command = "test/foo.rb" expect(subject.guess).to eq("Unit Tests") subject.original_run_command = "test/{models,helpers,unit}/**/*_test.rb" expect(subject.guess).to eq("Unit Tests") end it 'correctly guesses "Functional Tests" for functional tests' do subject.original_run_command = "/some/path/test/functional/foo_bar_controller_test.rb" expect(subject.guess).to eq("Functional Tests") subject.original_run_command = "test/{controllers,mailers,functional}/**/*_test.rb" expect(subject.guess).to eq("Functional Tests") end it 'correctly guesses "Integration Tests" for integration tests' do subject.original_run_command = "/some/path/test/integration/foo_bar_controller_test.rb" expect(subject.guess).to eq("Integration Tests") subject.original_run_command = "test/integration/**/*_test.rb" expect(subject.guess).to eq("Integration Tests") end it 'correctly guesses "Cucumber Features" for cucumber features' do subject.original_run_command = "features" expect(subject.guess).to eq("Cucumber Features") subject.original_run_command = "cucumber" expect(subject.guess).to eq("Cucumber Features") end it 'correctly guesses "RSpec" for RSpec' do subject.original_run_command = "/some/path/spec/foo.rb" expect(subject.guess).to eq("RSpec") end it "defaults to RSpec because RSpec constant is defined" do subject.original_run_command = "some_arbitrary_command with arguments" expect(subject.guess).to eq("RSpec") end end end simplecov-0.14.1/spec/raw_coverage_spec.rb0000644000004100000410000000754313130232776020600 0ustar www-datawww-datarequire "helper" if SimpleCov.usable? describe SimpleCov::RawCoverage do describe "with two faked coverage resultsets" do before do @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], source_fixture("parallel_tests.rb") => [nil, 0, nil, 0], source_fixture("conditionally_loaded_1.rb") => [nil, 0, 1], # loaded only in the first resultset source_fixture("three.rb") => [nil, 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], source_fixture("parallel_tests.rb") => [nil, nil, 0, 0], source_fixture("conditionally_loaded_2.rb") => [nil, 0, 1], # loaded only in the second resultset source_fixture("three.rb") => [nil, 1, 4], } @resultset3 = { source_fixture("three.rb") => [nil, 1, 2], } end context "a merge" do subject do SimpleCov::RawCoverage.merge_results(@resultset1, @resultset2, @resultset3) end it "has proper results for sample.rb" do expect(subject[source_fixture("sample.rb")]).to eq([1, 1, 2, 2, nil, nil, 2, 2, nil, nil]) end it "has proper results for user.rb" do expect(subject[source_fixture("app/models/user.rb")]).to eq([nil, 2, 6, 2, nil, nil, 2, 0, nil, nil]) end it "has proper results for sample_controller.rb" do expect(subject[source_fixture("app/controllers/sample_controller.rb")]).to eq([nil, 4, 2, 1, nil, nil, 2, 0, nil, nil]) end it "has proper results for resultset1.rb" do expect(subject[source_fixture("resultset1.rb")]).to eq([1, 1, 1, 1]) end it "has proper results for resultset2.rb" do expect(subject[source_fixture("resultset2.rb")]).to eq([nil, 1, 1, nil]) end it "has proper results for parallel_tests.rb" do expect(subject[source_fixture("parallel_tests.rb")]).to eq([nil, nil, nil, 0]) end it "has proper results for conditionally_loaded_1.rb" do expect(subject[source_fixture("conditionally_loaded_1.rb")]).to eq([nil, 0, 1]) end it "has proper results for conditionally_loaded_2.rb" do expect(subject[source_fixture("conditionally_loaded_2.rb")]).to eq([nil, 0, 1]) end it "has proper results for three.rb" do expect(subject[source_fixture("three.rb")]).to eq([nil, 3, 7]) end end end it "merges frozen resultsets" do resultset1 = { source_fixture("sample.rb").freeze => [nil, 1, 1, 1, nil, nil, 1, 1, nil, nil].freeze, source_fixture("app/models/user.rb").freeze => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil].freeze, }.freeze resultset2 = { source_fixture("sample.rb").freeze => [1, nil, 1, 1, nil, nil, 1, 1, nil, nil].freeze, }.freeze merged_result = SimpleCov::RawCoverage.merge_results(resultset1, resultset2) expect(merged_result.keys).to eq(resultset1.keys) expect(merged_result.values.map(&:frozen?)).to eq([false, false]) expect(merged_result[source_fixture("sample.rb")]).to eq([1, 1, 2, 2, nil, nil, 2, 2, nil, nil]) expect(merged_result[source_fixture("app/models/user.rb")]).to eq([nil, 1, 1, 1, nil, nil, 1, 0, nil, nil]) end end end simplecov-0.14.1/spec/multi_formatter_spec.rb0000644000004100000410000000106613130232776021343 0ustar www-datawww-datarequire "helper" require "simplecov/formatter/multi_formatter" describe SimpleCov::Formatter::MultiFormatter do describe ".[]" do # Regression test for https://github.com/colszowka/simplecov/issues/428 it "constructs a formatter with multiple children" do # Silence deprecation warnings. allow(described_class).to receive(:warn) children = [ SimpleCov::Formatter::SimpleFormatter, SimpleCov::Formatter::SimpleFormatter, ] expect(described_class[*children].new.formatters).to eq(children) end end end simplecov-0.14.1/spec/fixtures/0000755000004100000410000000000013130232776016435 5ustar www-datawww-datasimplecov-0.14.1/spec/fixtures/resultset2.rb0000644000004100000410000000004313130232776021073 0ustar www-datawww-data class Resultset VERSION = 2 end simplecov-0.14.1/spec/fixtures/iso-8859.rb0000644000004100000410000000003713130232776020167 0ustar www-datawww-data # localized to Español thus: simplecov-0.14.1/spec/fixtures/skipped_and_executed.rb0000644000004100000410000000011313130232776023124 0ustar www-datawww-data# So much skippping # :nocov: class Foo def bar 0 end end #:nocov: simplecov-0.14.1/spec/fixtures/frameworks/0000755000004100000410000000000013130232776020615 5ustar www-datawww-datasimplecov-0.14.1/spec/fixtures/frameworks/rspec_bad.rb0000644000004100000410000000040213130232776023060 0ustar www-datawww-data$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 expect(1).to eq(2) end end simplecov-0.14.1/spec/fixtures/frameworks/testunit_good.rb0000644000004100000410000000032213130232776024026 0ustar www-datawww-data$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "..", "..")) require "lib/simplecov" SimpleCov.start require "test/unit" class FooTest < Test::Unit::TestCase def test_foo assert true end end simplecov-0.14.1/spec/fixtures/frameworks/rspec_good.rb0000644000004100000410000000037613130232776023274 0ustar www-datawww-data$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "..", "..")) require "lib/simplecov" require "rspec" SimpleCov.start describe "exit status" do it "should exit with a zero exit status when assertion fails" do expect(1).to eq(1) end end simplecov-0.14.1/spec/fixtures/frameworks/testunit_bad.rb0000644000004100000410000000032313130232776023625 0ustar www-datawww-data$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 simplecov-0.14.1/spec/fixtures/deleted_source_sample.rb0000644000004100000410000000057613130232776023321 0ustar www-datawww-data$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 simplecov-0.14.1/spec/fixtures/resultset1.rb0000644000004100000410000000005413130232776021074 0ustar www-datawww-dataputs "foo" puts "foo" puts "foo" puts "foo" simplecov-0.14.1/spec/fixtures/skipped.rb0000644000004100000410000000005613130232776020422 0ustar www-datawww-data# Not relevant # :nocov: # Hash.new # :nocov: simplecov-0.14.1/spec/fixtures/utf-8.rb0000644000004100000410000000004113130232776017720 0ustar www-datawww-data# encoding: utf-8 puts "135°C" simplecov-0.14.1/spec/fixtures/app/0000755000004100000410000000000013130232776017215 5ustar www-datawww-datasimplecov-0.14.1/spec/fixtures/app/controllers/0000755000004100000410000000000013130232776021563 5ustar www-datawww-datasimplecov-0.14.1/spec/fixtures/app/controllers/sample_controller.rb0000644000004100000410000000013413130232776025632 0ustar www-datawww-data# Foo class class Foo def initialize @foo = "baz" end def bar @foo end end simplecov-0.14.1/spec/fixtures/app/models/0000755000004100000410000000000013130232776020500 5ustar www-datawww-datasimplecov-0.14.1/spec/fixtures/app/models/user.rb0000644000004100000410000000013413130232776022001 0ustar www-datawww-data# Foo class class Foo def initialize @foo = "baz" end def bar @foo end end simplecov-0.14.1/spec/fixtures/never.rb0000644000004100000410000000004713130232776020102 0ustar www-datawww-data# This class is purely some # comments simplecov-0.14.1/spec/fixtures/sample.rb0000644000004100000410000000022413130232776020241 0ustar www-datawww-data# Foo class class Foo def initialize @foo = "baz" end def bar @foo end #:nocov: def skipped @foo * 2 end #:nocov: end simplecov-0.14.1/spec/source_file_spec.rb0000644000004100000410000001033013130232776020417 0ustar www-datawww-datarequire "helper" if SimpleCov.usable? describe SimpleCov::SourceFile do COVERAGE_FOR_SAMPLE_RB = [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil, nil, nil, nil, nil, nil, nil].freeze context "a source file initialized with some coverage data" do subject do SimpleCov::SourceFile.new(source_fixture("sample.rb"), COVERAGE_FOR_SAMPLE_RB) end it "has a filename" do expect(subject.filename).not_to be_nil end it "has source equal to src" do expect(subject.src).to eq(subject.source) end it "has source_lines equal to lines" do expect(subject.lines).to eq(subject.source_lines) end it "has 16 source lines" do expect(subject.lines.count).to eq(16) end it "has all source lines of type SimpleCov::SourceFile::Line" do subject.lines.each do |line| expect(line).to be_a SimpleCov::SourceFile::Line end end it "has 'class Foo' as line(2).source" do expect(subject.line(2).source).to eq("class Foo\n") end it "returns lines number 2, 3, 4, 7 for covered_lines" do expect(subject.covered_lines.map(&:line)).to eq([2, 3, 4, 7]) end it "returns lines number 8 for missed_lines" do expect(subject.missed_lines.map(&:line)).to eq([8]) end it "returns lines number 1, 5, 6, 9, 10, 16 for never_lines" do expect(subject.never_lines.map(&:line)).to eq([1, 5, 6, 9, 10, 16]) end it "returns line numbers 11, 12, 13, 14, 15 for skipped_lines" do expect(subject.skipped_lines.map(&:line)).to eq([11, 12, 13, 14, 15]) end it "has 80% covered_percent" do expect(subject.covered_percent).to eq(80.0) end end context "simulating potential Ruby 1.9 defect -- see Issue #56" do subject do SimpleCov::SourceFile.new(source_fixture("sample.rb"), COVERAGE_FOR_SAMPLE_RB + [nil]) end it "has 16 source lines regardless of extra data in coverage array" do # Do not litter test output with known warning capture_stderr { expect(subject.lines.count).to eq(16) } end it "prints a warning to stderr if coverage array contains more data than lines in the file" do captured_output = capture_stderr do subject.lines end expect(captured_output).to match(/^Warning: coverage data provided/) end end context "a file that is never relevant" do COVERAGE_FOR_NEVER_RB = [nil, nil].freeze subject do SimpleCov::SourceFile.new(source_fixture("never.rb"), COVERAGE_FOR_NEVER_RB) end it "has 0.0 covered_strength" do expect(subject.covered_strength).to eq 0.0 end it "has 0.0 covered_percent" do expect(subject.covered_percent).to eq 100.0 end end context "a file where nothing is ever executed mixed with skipping #563" do COVERAGE_FOR_SKIPPED_RB = [nil, nil, nil, nil].freeze subject do SimpleCov::SourceFile.new(source_fixture("skipped.rb"), COVERAGE_FOR_SKIPPED_RB) end it "has 0.0 covered_strength" do expect(subject.covered_strength).to eq 0.0 end it "has 0.0 covered_percent" do expect(subject.covered_percent).to eq 0.0 end end context "a file where everything is skipped and missed #563" do COVERAGE_FOR_SKIPPED_RB_2 = [nil, nil, 0, nil].freeze subject do SimpleCov::SourceFile.new(source_fixture("skipped.rb"), COVERAGE_FOR_SKIPPED_RB_2) end it "has 0.0 covered_strength" do expect(subject.covered_strength).to eq 0.0 end it "has 0.0 covered_percent" do expect(subject.covered_percent).to eq 0.0 end end context "a file where everything is skipped/irrelevamt but executed #563" do COVERAGE_FOR_SKIPPED_AND_EXECUTED_RB = [nil, nil, 1, 1, 0, nil, nil, nil].freeze subject do SimpleCov::SourceFile.new(source_fixture("skipped_and_executed.rb"), COVERAGE_FOR_SKIPPED_AND_EXECUTED_RB) end it "has 0.0 covered_strength" do expect(subject.covered_strength).to eq 0.0 end it "has 0.0 covered_percent" do expect(subject.covered_percent).to eq 0.0 end end end end simplecov-0.14.1/spec/filters_spec.rb0000644000004100000410000000720413130232776017576 0ustar www-datawww-datarequire "helper" if SimpleCov.usable? describe SimpleCov::SourceFile do subject do SimpleCov::SourceFile.new(source_fixture("sample.rb"), [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil]) end it "doesn't match a new SimpleCov::StringFilter 'foobar'" do expect(SimpleCov::StringFilter.new("foobar")).not_to be_matches subject end it "doesn't match a new SimpleCov::StringFilter 'some/path'" do expect(SimpleCov::StringFilter.new("some/path")).not_to be_matches subject end it "matches a new SimpleCov::StringFilter 'spec/fixtures'" do expect(SimpleCov::StringFilter.new("spec/fixtures")).to be_matches subject end it "matches a new SimpleCov::StringFilter 'spec/fixtures/sample.rb'" do expect(SimpleCov::StringFilter.new("spec/fixtures/sample.rb")).to be_matches subject end it "matches a new SimpleCov::StringFilter 'sample.rb'" do expect(SimpleCov::StringFilter.new("sample.rb")).to be_matches subject end it "doesn't match a new SimpleCov::BlockFilter that is not applicable" do expect(SimpleCov::BlockFilter.new(proc { |s| File.basename(s.filename) == "foo.rb" })).not_to be_matches subject end it "matches a new SimpleCov::BlockFilter that is applicable" do expect(SimpleCov::BlockFilter.new(proc { |s| File.basename(s.filename) == "sample.rb" })).to be_matches subject end it "matches a new SimpleCov::ArrayFilter when 'sample.rb' is passed as array" do expect(SimpleCov::ArrayFilter.new(["sample.rb"])).to be_matches subject end it "doesn't match a new SimpleCov::ArrayFilter when a file path different than 'sample.rb' is passed as array" do expect(SimpleCov::ArrayFilter.new(["other_file.rb"])).not_to be_matches subject end it "matches a new SimpleCov::ArrayFilter when two file paths including 'sample.rb' are passed as array" do expect(SimpleCov::ArrayFilter.new(["sample.rb", "other_file.rb"])).to be_matches subject end context "with no filters set up and a basic source file in an array" do before do @prev_filters = SimpleCov.filters SimpleCov.filters = [] end subject do [SimpleCov::SourceFile.new(source_fixture("sample.rb"), [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil])] end after do SimpleCov.filters = @prev_filters end it 'returns 0 items after executing SimpleCov.filtered on files when using a "sample" string filter' do SimpleCov.add_filter "sample" expect(SimpleCov.filtered(subject).count).to be_zero end it 'returns 0 items after executing SimpleCov.filtered on files when using a "spec/fixtures" string filter' do SimpleCov.add_filter "spec/fixtures" expect(SimpleCov.filtered(subject).count).to be_zero end it 'returns 1 item after executing SimpleCov.filtered on files when using a "fooo" string filter' do SimpleCov.add_filter "fooo" expect(SimpleCov.filtered(subject).count).to eq(1) end it "returns 0 items after executing SimpleCov.filtered on files when using a block filter that returns true" do SimpleCov.add_filter do true end expect(SimpleCov.filtered(subject).count).to be_zero end it "returns 1 item after executing SimpleCov.filtered on files when using an always-false block filter" do SimpleCov.add_filter do false end expect(SimpleCov.filtered(subject).count).to eq(1) end it "returns a FileList after filtering" do SimpleCov.add_filter "fooo" expect(SimpleCov.filtered(subject)).to be_a SimpleCov::FileList end end end end simplecov-0.14.1/spec/deleted_source_spec.rb0000644000004100000410000000056613130232776021120 0ustar www-datawww-datarequire "helper" # Test to verify correct handling of deleted files # See https://github.com/colszowka/simplecov/issues/9 describe "A source file which is subsequently deleted" do it "does not cause an error" do Dir.chdir(File.join(File.dirname(__FILE__), "fixtures")) do `ruby deleted_source_sample.rb` expect($?.exitstatus).to be_zero end end end simplecov-0.14.1/spec/result_spec.rb0000644000004100000410000001521613130232776017446 0ustar www-datawww-datarequire "helper" if SimpleCov.usable? describe "result" do context "with a (mocked) Coverage.result" do before do @prev_filters = SimpleCov.filters SimpleCov.filters = [] @prev_groups = SimpleCov.groups SimpleCov.groups = {} @prev_formatter = SimpleCov.formatter SimpleCov.formatter = nil end after do SimpleCov.filters = @prev_filters SimpleCov.groups = @prev_groups SimpleCov.formatter = @prev_formatter end let(:original_result) do { source_fixture("sample.rb") => [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 subject { SimpleCov::Result.new(original_result) } it "has 3 filenames" do expect(subject.filenames.count).to eq(3) end it "has 3 source files" do expect(subject.source_files.count).to eq(3) subject.source_files.each do |source_file| expect(source_file).to be_a SimpleCov::SourceFile end end it "returns an instance of SimpleCov::FileList for source_files and files" do expect(subject.files).to be_a SimpleCov::FileList expect(subject.source_files).to be_a SimpleCov::FileList end it "has files equal to source_files" do expect(subject.files).to eq(subject.source_files) end it "has accurate covered percent" do # in our fixture, there are 13 covered line (result in 1) in all 15 relevant line (result in non-nil) expect(subject.covered_percent).to eq(86.66666666666667) end it "has accurate covered percentages" do expect(subject.covered_percentages).to eq([80.0, 80.0, 100.0]) end it "has accurate least covered file" do expect(subject.least_covered_file).to match(/sample_controller.rb/) end [:covered_percent, :covered_percentages, :least_covered_file, :covered_strength, :covered_lines, :missed_lines, :total_lines].each do |msg| it "responds to #{msg}" do expect(subject).to respond_to(msg) end end context "dumped with to_hash" do it "is a hash" do expect(subject.to_hash).to be_a Hash end context "loaded back with from_hash" do let(:dumped_result) do SimpleCov::Result.from_hash(subject.to_hash) end it "has 3 source files" do expect(dumped_result.source_files.count).to eq(subject.source_files.count) end it "has the same covered_percent" do expect(dumped_result.covered_percent).to eq(subject.covered_percent) end it "has the same covered_percentages" do expect(dumped_result.covered_percentages).to eq(subject.covered_percentages) end it "has the same timestamp" do expect(dumped_result.created_at.to_i).to eq(subject.created_at.to_i) end it "has the same command_name" do expect(dumped_result.command_name).to eq(subject.command_name) end it "has the same original_result" do expect(dumped_result.original_result).to eq(subject.original_result) end end end end context "with some filters set up" do before do SimpleCov.add_filter "sample.rb" end it "has 2 files in a new simple cov result" do expect(SimpleCov::Result.new(original_result).source_files.length).to eq(2) end it "has 80 covered percent" do expect(SimpleCov::Result.new(original_result).covered_percent).to eq(80) end it "has [80.0, 80.0] covered percentages" do expect(SimpleCov::Result.new(original_result).covered_percentages).to eq([80.0, 80.0]) end end context "with groups set up for all files" do before do SimpleCov.add_group "Models", "app/models" SimpleCov.add_group "Controllers", ["app/controllers"] SimpleCov.add_group "Other" do |src_file| File.basename(src_file.filename) == "sample.rb" end end subject do SimpleCov::Result.new(original_result) end it "has 3 groups" do expect(subject.groups.length).to eq(3) end it "has user.rb in 'Models' group" do expect(File.basename(subject.groups["Models"].first.filename)).to eq("user.rb") end it "has sample_controller.rb in 'Controllers' group" do expect(File.basename(subject.groups["Controllers"].first.filename)).to eq("sample_controller.rb") end context "and simple formatter being used" do before do SimpleCov.formatter = SimpleCov::Formatter::SimpleFormatter end it "returns a formatted string with result.format!" do expect(subject.format!).to be_a String end end context "and multi formatter being used" do before do SimpleCov.formatters = [ SimpleCov::Formatter::SimpleFormatter, SimpleCov::Formatter::SimpleFormatter, ] end it "returns an array containing formatted string with result.format!" do formatted = subject.format! expect(formatted.count).to eq(2) expect(formatted.first).to be_a String end end end context "with groups set up that do not match all files" do before do SimpleCov.configure do add_group "Models", "app/models" add_group "Controllers", "app/controllers" end end subject { SimpleCov::Result.new(original_result) } it "has 3 groups" do expect(subject.groups.length).to eq(3) end it "has 1 item per group" do subject.groups.each_value do |files| expect(files.length).to eq(1) end end it 'has sample.rb in "Ungrouped" group' do expect(File.basename(subject.groups["Ungrouped"].first.filename)).to eq("sample.rb") end it "returns all groups as instances of SimpleCov::FileList" do subject.groups.each_value do |files| expect(files).to be_a SimpleCov::FileList end end end end end end simplecov-0.14.1/spec/config_loader_spec.rb0000644000004100000410000000046413130232776020722 0ustar www-datawww-datarequire "helper" describe "loading config" do context "without ENV[HOME]" do it "shouldn't raise any errors" do home = ENV.delete("HOME") begin expect { load "simplecov/load_global_config.rb" }.not_to raise_error ensure ENV["HOME"] = home end end end end simplecov-0.14.1/spec/file_list_spec.rb0000644000004100000410000000255713130232776020106 0ustar www-datawww-datarequire "helper" if SimpleCov.usable? describe SimpleCov::Result do subject 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, 2, 2, 0, nil, nil, 0, nil, nil, nil], } SimpleCov::Result.new(original_result).files end it "has 11 covered lines" do expect(subject.covered_lines).to eq(11) end it "has 3 missed lines" do expect(subject.missed_lines).to eq(3) end it "has 17 never lines" do expect(subject.never_lines).to eq(17) end it "has 14 lines of code" do expect(subject.lines_of_code).to eq(14) end it "has 5 skipped lines" do expect(subject.skipped_lines).to eq(5) end it "has the correct covered percent" do expect(subject.covered_percent).to eq(78.57142857142857) end it "has the correct covered percentages" do expect(subject.covered_percentages).to eq([50.0, 80.0, 100.0]) end it "has the correct least covered file" do expect(subject.least_covered_file).to match(/sample_controller.rb/) end it "has the correct covered strength" do expect(subject.covered_strength).to eq(0.9285714285714286) end end end simplecov-0.14.1/spec/last_run_spec.rb0000644000004100000410000000227513130232776017760 0ustar www-datawww-datarequire "helper" if SimpleCov.usable? describe SimpleCov::LastRun do subject { SimpleCov::LastRun } it "defines a last_run_path" do expect(subject.last_run_path).to include "tmp/coverage/.last_run.json" end it "writes json to its last_run_path that can be parsed again" do structure = [{"key" => "value"}] subject.write(structure) file_contents = File.read(subject.last_run_path) expect(JSON.parse(file_contents)).to eq structure end context "reading" do context "but the last_run file does not exist" do before { File.delete(subject.last_run_path) if File.exist?(subject.last_run_path) } it "returns nil" do expect(subject.read).to be_nil end end context "a non empty result" do before { subject.write([]) } it "reads json from its last_run_path" do expect(subject.read).to eq([]) end end context "an empty result" do before do File.open(subject.last_run_path, "w+") do |f| f.puts "" end end it "returns nil" do expect(subject.read).to be_nil end end end end end simplecov-0.14.1/spec/configuration_spec.rb0000644000004100000410000000140413130232776020771 0ustar www-datawww-datarequire "helper" describe SimpleCov::Configuration do let(:config_class) do Class.new do include SimpleCov::Configuration end end let(:config) { config_class.new } describe "#tracked_files" do context "when configured" do let(:glob) { "{app,lib}/**/*.rb" } before { config.track_files(glob) } it "returns the configured glob" do expect(config.tracked_files).to eq glob end context "and configured again with nil" do before { config.track_files(nil) } it "returns nil" do expect(config.tracked_files).to be_nil end end end context "when unconfigured" do it "returns nil" do expect(config.tracked_files).to be_nil end end end end simplecov-0.14.1/spec/support/0000755000004100000410000000000013130232776016300 5ustar www-datawww-datasimplecov-0.14.1/spec/support/fail_rspec_on_ruby_warning.rb0000644000004100000410000000327313130232776024223 0ustar www-datawww-data# Borrowed and heavily adjusted from: # https://github.com/metricfu/metric_fu/blob/master/spec/capture_warnings.rb require "fileutils" class FailOnWarnings def initialize @stderr_stream = StringIO.new @app_root = Dir.pwd end def collect_warnings $stderr = @stderr_stream $VERBOSE = true end def process_warnings lines = close_stream app_warnings, other_warnings = split_lines(lines) print_own_warnings(app_warnings) if app_warnings.any? write_other_warnings_to_tmp(other_warnings) if other_warnings.any? fail_script(app_warnings) if app_warnings.any? end private def close_stream $stderr = STDERR @stderr_stream.rewind lines = @stderr_stream.read.split("\n") lines.uniq! @stderr_stream.close lines end def split_lines(lines) lines.partition { |line| line.include?(@app_root) } end def print_own_warnings(app_warnings) puts "" puts "" puts <<-WARNINGS #{'-' * 30} app warnings: #{'-' * 30} #{app_warnings.join("\n")} #{'-' * 75} WARNINGS end def write_other_warnings_to_tmp(other_warnings) output_dir = File.join(@app_root, "tmp") FileUtils.mkdir_p(output_dir) output_file = File.join(output_dir, "warnings.txt") File.open(output_file, "w") do |file| file.write(other_warnings.join("\n") << "\n") end puts puts "Non-app warnings written to tmp/warnings.txt" puts end def fail_script(app_warnings) abort "Failing build due to app warnings: #{app_warnings.inspect}" end end warning_collector = FailOnWarnings.new warning_collector.collect_warnings RSpec.configure do |config| config.after(:suite) do warning_collector.process_warnings end end simplecov-0.14.1/spec/source_file_line_spec.rb0000644000004100000410000000721013130232776021431 0ustar www-datawww-datarequire "helper" if SimpleCov.usable? describe SimpleCov::SourceFile::Line do context "a source line" do subject do SimpleCov::SourceFile::Line.new("# the ruby source", 5, 3) end it 'returns "# the ruby source" as src' do expect(subject.src).to eq("# the ruby source") end it "returns the same for source as for src" do expect(subject.src).to eq(subject.source) end it "has line number 5" do expect(subject.line_number).to eq(5) end it "has equal line_number, line and number" do expect(subject.line).to eq(subject.line_number) expect(subject.number).to eq(subject.line_number) end context "flagged as skipped!" do before do subject.skipped! end it "is not covered" do expect(subject).not_to be_covered end it "is skipped" do expect(subject).to be_skipped end it "is not missed" do expect(subject).not_to be_missed end it "is not never" do expect(subject).not_to be_never end it "status is skipped" do expect(subject.status).to eq("skipped") end end end context "A source line with coverage" do subject do SimpleCov::SourceFile::Line.new("# the ruby source", 5, 3) end it "has coverage of 3" do expect(subject.coverage).to eq(3) end it "is covered" do expect(subject).to be_covered end it "is not skipped" do expect(subject).not_to be_skipped end it "is not missed" do expect(subject).not_to be_missed end it "is not never" do expect(subject).not_to be_never end it "status is covered" do expect(subject.status).to eq("covered") end end context "A source line without coverage" do subject do SimpleCov::SourceFile::Line.new("# the ruby source", 5, 0) end it "has coverage of 0" do expect(subject.coverage).to be_zero end it "is not covered" do expect(subject).not_to be_covered end it "is not skipped" do expect(subject).not_to be_skipped end it "is missed" do expect(subject).to be_missed end it "is not never" do expect(subject).not_to be_never end it "status is missed" do expect(subject.status).to eq("missed") end end context "A source line with no code" do subject do SimpleCov::SourceFile::Line.new("# the ruby source", 5, nil) end it "has nil coverage" do expect(subject.coverage).to be_nil end it "is not covered" do expect(subject).not_to be_covered end it "is not skipped" do expect(subject).not_to be_skipped end it "is not missed" do expect(subject).not_to be_missed end it "is never" do expect(subject).to be_never end it "status is never" do expect(subject.status).to eq("never") end end it "raises ArgumentError when initialized with invalid src" do expect { SimpleCov::SourceFile::Line.new(:symbol, 5, 3) }.to raise_error(ArgumentError) end it "raises ArgumentError when initialized with invalid line_number" do expect { SimpleCov::SourceFile::Line.new("some source", "five", 3) }.to raise_error(ArgumentError) end it "raises ArgumentError when initialized with invalid coverage" do expect { SimpleCov::SourceFile::Line.new("some source", 5, "three") }.to raise_error(ArgumentError) end end end simplecov-0.14.1/spec/faked_project/0000755000004100000410000000000013130232776017364 5ustar www-datawww-datasimplecov-0.14.1/spec/faked_project/Rakefile0000644000004100000410000000027713130232776021037 0ustar www-datawww-datarequire "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 simplecov-0.14.1/spec/faked_project/Gemfile0000644000004100000410000000016713130232776020663 0ustar www-datawww-datasource "https://rubygems.org" gem "simplecov", :path => "../../../" gem "rake" gem "rspec", ">= 2.6.0" gem "cucumber" simplecov-0.14.1/spec/faked_project/features/0000755000004100000410000000000013130232776021202 5ustar www-datawww-datasimplecov-0.14.1/spec/faked_project/features/step_definitions/0000755000004100000410000000000013130232776024550 5ustar www-datawww-datasimplecov-0.14.1/spec/faked_project/features/step_definitions/my_steps.rb0000644000004100000410000000126713130232776026746 0ustar www-datawww-dataGiven /^I want to keep stuff simple$/ do expect(1).to eq(1) end When /^I write my cukes for the fake project$/ do expect(1).to eq(1) end Then /^I make all necessary tests in a single step$/ do expect(FakedProject.foo).to eq("bar") expect(FrameworkSpecific.cucumber).to eq("Only tested in Cucumber") expect(FakedProject.a_class_method).to eq("this is a mixed-in class method") expect(FakedProject.new.an_instance_method).to eq("this is a mixed-in instance method") expect(FakedProject.new.dynamic).to eq("A dynamically defined instance method") something = SomeClass.new("foo") expect(something.reverse).to eq("oof") expect(something.compare_with("foo")).to be true end simplecov-0.14.1/spec/faked_project/features/test_stuff.feature0000644000004100000410000000025713130232776024751 0ustar www-datawww-dataFeature: Foo Scenario: Test stuff Given I want to keep stuff simple When I write my cukes for the fake project Then I make all necessary tests in a single step simplecov-0.14.1/spec/faked_project/features/support/0000755000004100000410000000000013130232776022716 5ustar www-datawww-datasimplecov-0.14.1/spec/faked_project/features/support/env.rb0000644000004100000410000000055013130232776024033 0ustar www-datawww-datarequire "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 $stderr.puts "No SimpleCov config file found!" end $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "/../../lib")) require "faked_project" simplecov-0.14.1/spec/faked_project/spec/0000755000004100000410000000000013130232776020316 5ustar www-datawww-datasimplecov-0.14.1/spec/faked_project/spec/forking_spec.rb0000644000004100000410000000035113130232776023313 0ustar www-datawww-datarequire "spec_helper" describe "forking" do it do # TODO: The defined?(RUBY_ENGINE) check can be dropped for simplecov 1.0.0 Process.waitpid(Kernel.fork {}) unless defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby" end end simplecov-0.14.1/spec/faked_project/spec/some_class_spec.rb0000644000004100000410000000040113130232776024000 0ustar www-datawww-datarequire "spec_helper" describe SomeClass do subject { SomeClass.new("foo") } it "should be reversible" do expect(subject.reverse).to eq("oof") end it "should compare with 'foo'" do expect(subject.compare_with("foo")).to be true end end simplecov-0.14.1/spec/faked_project/spec/spec_helper.rb0000644000004100000410000000044413130232776023136 0ustar www-datawww-datarequire "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 $stderr.puts "No SimpleCov config file found!" end require "faked_project" simplecov-0.14.1/spec/faked_project/spec/meta_magic_spec.rb0000644000004100000410000000101413130232776023737 0ustar www-datawww-datarequire "spec_helper" describe FakedProject do it "should have added a class method to FakedProject" do expect(FakedProject.a_class_method).to eq("this is a mixed-in class method") end it "should have added a mixed-in instance method to FakedProject" do expect(subject.an_instance_method).to eq("this is a mixed-in instance method") end it "should have added a dyntamically-defined instance method to FakedProject" do expect(subject.dynamic).to eq("A dynamically defined instance method") end end simplecov-0.14.1/spec/faked_project/spec/faked_spec.rb0000644000004100000410000000040513130232776022726 0ustar www-datawww-datarequire "spec_helper" describe FakedProject do it "should return proper foo" do expect(FakedProject.foo).to eq("bar") end it "should test it's framework specific method" do expect(FrameworkSpecific.rspec).to eq("Only tested in RSpec") end end simplecov-0.14.1/spec/faked_project/lib/0000755000004100000410000000000013130232776020132 5ustar www-datawww-datasimplecov-0.14.1/spec/faked_project/lib/faked_project.rb0000644000004100000410000000051213130232776023255 0ustar www-datawww-dataclass FakedProject def self.foo "bar" end end Dir[File.join(File.dirname(__FILE__), "faked_project/*.rb")].reject { |f| /untested/.match(f) }.each do |file| require file # Require all source files in project dynamically so we can inject some stuff depending on test situation end FakedProject.send :include, MetaMagic simplecov-0.14.1/spec/faked_project/lib/faked_project/0000755000004100000410000000000013130232776022732 5ustar www-datawww-datasimplecov-0.14.1/spec/faked_project/lib/faked_project/some_class.rb0000644000004100000410000000054513130232776025413 0ustar www-datawww-dataclass 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 false end private def uncovered "private method" end end simplecov-0.14.1/spec/faked_project/lib/faked_project/framework_specific.rb0000644000004100000410000000056213130232776027124 0ustar www-datawww-data# A pile of methods that only get tested in their frameworks # and thus make this file only 100% covered when all framework test # results are merged module FrameworkSpecific class << self def cucumber "Only tested in Cucumber" end def rspec "Only tested in RSpec" end def test_unit "Only tested in Test/Unit" end end end simplecov-0.14.1/spec/faked_project/lib/faked_project/meta_magic.rb0000644000004100000410000000071513130232776025350 0ustar www-datawww-datamodule MetaMagic module ClassMethods def a_class_method "this is a mixed-in class method" end end module InstanceMethods def an_instance_method "this is a mixed-in instance method" end end def self.included(base) base.send :extend, ClassMethods base.send :include, InstanceMethods base.class_eval do define_method :dynamic do "A dynamically defined instance method" end end end end simplecov-0.14.1/spec/faked_project/lib/faked_project/untested_class.rb0000644000004100000410000000026613130232776026303 0ustar www-datawww-dataclass UntestedClass def initialize(yogurts) @yogurts = yogurts end def power_level @yogurts.map do |yo| yo.experience_points**2 end.reduce(0, &:+) end end simplecov-0.14.1/spec/faked_project/cucumber.yml0000644000004100000410000000113013130232776021707 0ustar www-datawww-data<% 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 %> simplecov-0.14.1/spec/faked_project/test/0000755000004100000410000000000013130232776020343 5ustar www-datawww-datasimplecov-0.14.1/spec/faked_project/test/test_helper.rb0000644000004100000410000000047013130232776023207 0ustar www-datawww-datarequire "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 $stderr.puts "No SimpleCov config file found!" end require "faked_project" require "test/unit" simplecov-0.14.1/spec/faked_project/test/some_class_test.rb0000644000004100000410000000040713130232776024060 0ustar www-datawww-datarequire "test_helper" class SomeClassTest < Test::Unit::TestCase def setup @instance = SomeClass.new("foo") end def test_reverse assert_equal "oof", @instance.reverse end def test_comparison assert @instance.compare_with("foo") end end simplecov-0.14.1/spec/faked_project/test/meta_magic_test.rb0000644000004100000410000000060113130232776024012 0ustar www-datawww-datarequire "test_helper" class MetaMagicTest < Test::Unit::TestCase def test_class_methods assert_equal "this is a mixed-in class method", FakedProject.a_class_method end def test_instance_methods p = FakedProject.new assert_equal "this is a mixed-in instance method", p.an_instance_method assert_equal "A dynamically defined instance method", p.dynamic end end simplecov-0.14.1/spec/faked_project/test/faked_test.rb0000644000004100000410000000036413130232776023004 0ustar www-datawww-datarequire "test_helper" class FakedTest < Test::Unit::TestCase def test_something assert_equal "bar", FakedProject.foo end def test_framework_specific assert_equal "Only tested in Test/Unit", FrameworkSpecific.test_unit end end simplecov-0.14.1/spec/return_codes_spec.rb0000644000004100000410000000165113130232776020622 0ustar www-datawww-datarequire "helper" # Make sure that exit codes of tests are propagated properly # See https://github.com/colszowka/simplecov/issues/5 describe "return codes" do context "inside fixtures/frameworks" do around do |test| Dir.chdir(File.join(File.dirname(__FILE__), "fixtures", "frameworks")) do FileUtils.rm_rf("./coverage") test.call end end it "has return code 0 when running testunit_good.rb" do `ruby testunit_good.rb` expect($?.exitstatus).to be_zero end it "has return code 0 when running rspec_good.rb" do `rspec rspec_good.rb` expect($?.exitstatus).to be_zero end it "has non-0 return code when running testunit_bad.rb" do `ruby testunit_bad.rb` expect($?.exitstatus).not_to be_zero end it "has return code 1 when running rspec_bad.rb" do `rspec rspec_bad.rb` expect($?.exitstatus).not_to be_zero end end end simplecov-0.14.1/.travis.yml0000644000004100000410000000057313130232776015750 0ustar www-datawww-datalanguage: ruby before_install: - gem update --system - gem install bundler bundler_args: --without development --jobs=3 --retry=3 cache: bundler sudo: false rvm: - 1.8.7 - 1.9.3 - 2.0.0 - 2.1.10 - 2.2.6 - 2.3.3 - 2.4.0 - ruby-head - jruby-head - jruby-9.1.8.0 matrix: allow_failures: - rvm: ruby-head - rvm: jruby-head fast_finish: true simplecov-0.14.1/lib/0000755000004100000410000000000013130232776014400 5ustar www-datawww-datasimplecov-0.14.1/lib/simplecov.rb0000644000004100000410000001252413130232776016732 0ustar www-datawww-data# # Code coverage for ruby 1.9. Please check out README for a full introduction. # # Coverage may be inaccurate under JRUBY. if defined?(JRUBY_VERSION) && defined?(JRuby) # @see https://github.com/jruby/jruby/issues/1196 # @see https://github.com/metricfu/metric_fu/pull/226 # @see https://github.com/colszowka/simplecov/issues/420 # @see https://github.com/colszowka/simplecov/issues/86 # @see https://jira.codehaus.org/browse/JRUBY-6106 unless org.jruby.RubyInstanceConfig.FULL_TRACE_ENABLED warn 'Coverage may be inaccurate; set the "--debug" command line option,' \ ' or do JRUBY_OPTS="--debug"' \ ' or set the "debug.fullTrace=true" option in your .jrubyrc' end end module SimpleCov class << self attr_accessor :running attr_accessor :pid # # Sets up SimpleCov to run against your project. # You can optionally specify a profile to use as well as configuration with a block: # SimpleCov.start # OR # SimpleCov.start 'rails' # using rails profile # OR # SimpleCov.start do # add_filter 'test' # end # OR # SimpleCov.start 'rails' do # add_filter 'test' # end # # Please check out the RDoc for SimpleCov::Configuration to find about available config options # def start(profile = nil, &block) if SimpleCov.usable? load_profile(profile) if profile configure(&block) if block_given? @result = nil self.running = true self.pid = Process.pid Coverage.start else warn "WARNING: SimpleCov is activated, but you're not running Ruby 1.9+ - no coverage analysis will happen" warn "Starting with SimpleCov 1.0.0, even no-op compatibility with Ruby <= 1.8 will be entirely dropped." false end end # # Finds files that were to be tracked but were not loaded and initializes # their coverage to zero. # def add_not_loaded_files(result) if tracked_files result = result.dup Dir[tracked_files].each do |file| absolute = File.expand_path(file) result[absolute] ||= [0] * File.foreach(absolute).count end end result 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 # Ensure the variable is defined to avoid ruby warnings @result = nil unless defined?(@result) # Collect our coverage result if running && !result? @result = SimpleCov::Result.new add_not_loaded_files(Coverage.result) end # 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? SimpleCov::ResultMerger.merged_result else @result end ensure self.running = false end # # Returns nil if the result has not been computed # Otherwise, returns the result # def result? defined?(@result) && @result end # # Applies the configured filters to the given array of SimpleCov::SourceFile items # def filtered(files) result = files.clone filters.each do |filter| result = result.reject { |source_file| filter.matches?(source_file) } end SimpleCov::FileList.new result end # # Applies the configured groups to the given array of SimpleCov::SourceFile items # def grouped(files) grouped = {} grouped_files = [] groups.each do |name, filter| grouped[name] = SimpleCov::FileList.new(files.select { |source_file| filter.matches?(source_file) }) grouped_files += grouped[name] end if !groups.empty? && !(other_files = files.reject { |source_file| grouped_files.include?(source_file) }).empty? grouped["Ungrouped"] = SimpleCov::FileList.new(other_files) end grouped end # # Applies the profile of given name on SimpleCov configuration # def load_profile(name) profiles.load(name) end def load_adapter(name) warn "#{Kernel.caller.first}: [DEPRECATION] #load_adapter is deprecated. Use #load_profile instead." load_profile(name) end # # Checks whether we're on a proper version of Ruby (likely 1.9+) which # provides coverage support # def usable? return @usable if defined?(@usable) && !@usable.nil? @usable = begin require "coverage" require "simplecov/jruby_fix" true rescue LoadError false end 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/profiles" require "simplecov/source_file" require "simplecov/file_list" require "simplecov/result" require "simplecov/filter" require "simplecov/formatter" require "simplecov/last_run" require "simplecov/raw_coverage" require "simplecov/result_merger" require "simplecov/command_guesser" require "simplecov/version" # Load default config require "simplecov/defaults" unless ENV["SIMPLECOV_NO_DEFAULTS"] # Load Rails integration (only for Rails 3, see #113) require "simplecov/railtie" if defined? Rails::Railtie simplecov-0.14.1/lib/simplecov/0000755000004100000410000000000013130232776016401 5ustar www-datawww-datasimplecov-0.14.1/lib/simplecov/command_guesser.rb0000644000004100000410000000365313130232776022110 0ustar www-datawww-data# # Helper that tries to find out what test suite is running (for SimpleCov.command_name) # module SimpleCov module CommandGuesser class << self # Storage for the original command line call that invoked the test suite. # This has got to be stored as early as possible because i.e. rake and test/unit 2 # have a habit of tampering with ARGV, which makes i.e. the automatic distinction # between rails unit/functional/integration tests impossible without this cached # item. attr_accessor :original_run_command def guess from_env || from_command_line_options || from_defined_constants end private def from_env # If being run from inside parallel_tests set the command name according to the process number return unless ENV["PARALLEL_TEST_GROUPS"] && ENV["TEST_ENV_NUMBER"] number = ENV["TEST_ENV_NUMBER"] number = "1" if number.empty? "(#{number}/#{ENV['PARALLEL_TEST_GROUPS']})" end def from_command_line_options case original_run_command when /test\/functional\//, /test\/\{.*functional.*\}\// "Functional Tests" when /test\/integration\// "Integration Tests" when /test\// "Unit Tests" when /spec/ "RSpec" when /cucumber/, /features/ "Cucumber Features" end end def from_defined_constants # If the command regexps fail, let's try checking defined constants. if defined?(RSpec) "RSpec" elsif defined?(Test::Unit) "Unit Tests" elsif defined?(MiniTest) "MiniTest" else # TODO: Provide link to docs/wiki article warn "SimpleCov failed to recognize the test framework and/or suite used. Please specify manually using SimpleCov.command_name 'Unit Tests'." "Unknown Test Framework" end end end end end simplecov-0.14.1/lib/simplecov/formatter.rb0000644000004100000410000000031013130232776020723 0ustar www-datawww-datamodule SimpleCov # TODO: Documentation on how to build your own formatters module Formatter end end require "simplecov/formatter/simple_formatter" require "simplecov/formatter/multi_formatter" simplecov-0.14.1/lib/simplecov/result.rb0000644000004100000410000000560713130232776020254 0ustar www-datawww-datarequire "digest/sha1" require "forwardable" module SimpleCov # # A simplecov code coverage result, initialized from the Hash Ruby 1.9's built-in coverage # library generates (Coverage.result). # class Result extend Forwardable # Returns the original Coverage.result used for this instance of SimpleCov::Result attr_reader :original_result # Returns all files that are applicable to this result (sans filters!) as instances of SimpleCov::SourceFile. Aliased as :source_files attr_reader :files alias source_files files # Explicitly set the Time this result has been created attr_writer :created_at # Explicitly set the command name that was used for this coverage result. Defaults to SimpleCov.command_name attr_writer :command_name def_delegators :files, :covered_percent, :covered_percentages, :least_covered_file, :covered_strength, :covered_lines, :missed_lines def_delegator :files, :lines_of_code, :total_lines # Initialize a new SimpleCov::Result from given Coverage.result (a Hash of filenames each containing an array of # coverage data) def initialize(original_result) @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 # Applies the configured SimpleCov.formatter on this result def format! SimpleCov.formatter.new.format(self) end # Defines when this result has been created. Defaults to Time.now def created_at @created_at ||= Time.now end # The command name that launched this result. # Delegated to SimpleCov.command_name if not set manually def command_name @command_name ||= SimpleCov.command_name end # Returns a hash representation of this Result that can be used for marshalling it into JSON def to_hash {command_name => {"coverage" => coverage, "timestamp" => created_at.to_i}} end # Loads a SimpleCov::Result#to_hash dump def self.from_hash(hash) 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 def coverage keys = original_result.keys & filenames Hash[keys.zip(original_result.values_at(*keys))] end # Applies all configured SimpleCov filters on this result's source files def filter! @files = SimpleCov.filtered(files) end end end simplecov-0.14.1/lib/simplecov/configuration.rb0000644000004100000410000002417313130232776021604 0ustar www-datawww-datarequire "fileutils" require "docile" require "simplecov/formatter/multi_formatter" # # 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 module Configuration # rubocop:disable ModuleLength 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) && 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) && dir.nil? @coverage_path = nil # invalidate cache @coverage_dir = (dir || "coverage") end # # Returns the full path to the output directory using SimpleCov.root # and SimpleCov.coverage_dir, so you can adjust this by configuring those # values. Will create the directory if it's missing # def coverage_path @coverage_path ||= begin coverage_path = File.expand_path(coverage_dir, root) FileUtils.mkdir_p coverage_path coverage_path end end # # Coverage results will always include files matched by this glob, whether # or not they were explicitly required. Without this, un-required files # will not be present in the final report. # def track_files(glob) @tracked_files = glob end # # Returns the glob that will be used to include files that were not # explicitly required. # def tracked_files @tracked_files if defined?(@tracked_files) end # # Returns the list of configured filters. Add filters using SimpleCov.add_filter. # def filters @filters ||= [] end # The name of the command (a.k.a. Test Suite) currently running. Used for result # merging and caching. It first tries to make a guess based upon the command line # arguments the current test suite is running on and should automatically detect # unit tests, functional tests, integration tests, rpsec and cucumber and label # them properly. If it fails to recognize the current command, the command name # is set to the shell command that the current suite is running on. # # You can specify it manually with SimpleCov.command_name("test:units") - please # also check out the corresponding section in README.rdoc def command_name(name = nil) @name = name unless name.nil? @name ||= SimpleCov::CommandGuesser.guess @name end # # Gets or sets the configured formatter. # # Configure with: SimpleCov.formatter(SimpleCov::Formatter::SimpleFormatter) # def formatter(formatter = nil) return @formatter if defined?(@formatter) && formatter.nil? @formatter = formatter raise "No formatter configured. Please specify a formatter using SimpleCov.formatter = SimpleCov::Formatter::SimpleFormatter" unless @formatter @formatter end # # Sets the configured formatters. # def formatters=(formatters) @formatter = SimpleCov::Formatter::MultiFormatter.new(formatters) end # # Gets the configured formatters. # def formatters if @formatter.is_a?(SimpleCov::Formatter::MultiFormatter) @formatter.formatters else Array(formatter) end end # # Certain code blocks (i.e. Ruby-implementation specific code) can be excluded from # the coverage metrics by wrapping it inside # :nocov: comment blocks. The nocov token # can be configured to be any other string using this. # # Configure with SimpleCov.nocov_token('skip') or it's alias SimpleCov.skip_token('skip') # def nocov_token(nocov_token = nil) return @nocov_token if defined?(@nocov_token) && nocov_token.nil? @nocov_token = (nocov_token || "nocov") end alias skip_token nocov_token # # Returns the configured groups. Add groups using SimpleCov.add_group # def groups @groups ||= {} end # # Returns the hash of available profiles # def profiles @profiles ||= SimpleCov::Profiles.new end def adapters warn "#{Kernel.caller.first}: [DEPRECATION] #adapters is deprecated. Use #profiles instead." profiles end # # Allows you to configure simplecov in a block instead of prepending SimpleCov to all config methods # you're calling. # # SimpleCov.configure do # add_filter 'foobar' # end # # This is equivalent to SimpleCov.add_filter 'foobar' and thus makes it easier to set a bunch of configure # options at once. # def configure(&block) return false unless SimpleCov.usable? Docile.dsl_eval(self, &block) end # # Gets or sets the behavior to process coverage results. # # By default, it will call SimpleCov.result.format! # # Configure with: # # SimpleCov.at_exit do # puts "Coverage done" # SimpleCov.result.format! # end # def at_exit(&block) return proc {} unless running || block_given? @at_exit = block if block_given? @at_exit ||= proc { 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) && @project_name && new_name.nil? @project_name = new_name if new_name.is_a?(String) @project_name ||= File.basename(root.split("/").last).capitalize.tr("_", " ") end # # Defines whether to use result merging so all your test suites (test:units, test:functionals, cucumber, ...) # are joined and combined into a single coverage report # def use_merging(use = nil) @use_merging = use unless use.nil? @use_merging = true unless defined?(@use_merging) && @use_merging == false end # # Defines the maximum age (in seconds) of a resultset to still be included in merged results. # i.e. If you run cucumber features, then later rake test, if the stored cucumber resultset is # more seconds ago than specified here, it won't be taken into account when merging (and is also # purged from the resultset cache) # # Of course, this only applies when merging is active (e.g. SimpleCov.use_merging is not false!) # # Default is 600 seconds (10 minutes) # # Configure with SimpleCov.merge_timeout(3600) # 1hr # def merge_timeout(seconds = nil) @merge_timeout = seconds if seconds.is_a?(Integer) @merge_timeout ||= 600 end # # Defines the minimum overall coverage required for the testsuite to pass. # SimpleCov will return non-zero if the current coverage is below this threshold. # # Default is 0% (disabled) # def minimum_coverage(coverage = nil) @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 # # Defines the minimum coverage per file required for the testsuite to pass. # SimpleCov will return non-zero if the current coverage of the least covered file # is below this threshold. # # Default is 0% (disabled) # def minimum_coverage_by_file(coverage = nil) @minimum_coverage_by_file ||= (coverage || 0).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 four ways to define a filter: # # * as a String that will then be matched against all source files' file paths, # SimpleCov.add_filter 'app/models' # will reject all your models # * as a block which will be passed the source file in question and should either # return a true or false value, depending on whether the file should be removed # SimpleCov.add_filter do |src_file| # File.basename(src_file.filename) == 'environment.rb' # end # Will exclude environment.rb files from the results # * as an array of strings that are matched against all sorce files' file # paths and then ignored (basically string filter multiple times) # SimpleCov.add_filter ['app/models', 'app/helpers'] # ignores both dirs # * as an instance of a subclass of SimpleCov::Filter. See the documentation there # on how to define your own filter classes # def add_filter(filter_argument = nil, &filter_proc) filters << parse_filter(filter_argument, &filter_proc) end # # Define a group for files. Works similar to add_filter, only that the first # argument is the desired group name and files PASSING the filter end up in the group # (while filters exclude when the filter is applicable). # def add_group(group_name, filter_argument = nil, &filter_proc) groups[group_name] = parse_filter(filter_argument, &filter_proc) end private # # The actual filter processor. Not meant for direct use # def parse_filter(filter_argument = nil, &filter_proc) if filter_argument.is_a?(SimpleCov::Filter) filter_argument elsif filter_argument.is_a?(String) SimpleCov::StringFilter.new(filter_argument) elsif filter_proc SimpleCov::BlockFilter.new(filter_proc) elsif filter_argument.is_a?(Array) SimpleCov::ArrayFilter.new(filter_argument) else raise ArgumentError, "Please specify either a string or a block to filter with" end end end end simplecov-0.14.1/lib/simplecov/railties/0000755000004100000410000000000013130232776020215 5ustar www-datawww-datasimplecov-0.14.1/lib/simplecov/railties/tasks.rake0000644000004100000410000000056113130232776022210 0ustar www-datawww-datarequire "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" simplecov-0.14.1/lib/simplecov/formatter/0000755000004100000410000000000013130232776020404 5ustar www-datawww-datasimplecov-0.14.1/lib/simplecov/formatter/multi_formatter.rb0000644000004100000410000000145413130232776024152 0ustar www-datawww-datamodule SimpleCov module Formatter class MultiFormatter module InstanceMethods 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 end def self.new(formatters = nil) Class.new do define_method :formatters do @formatters ||= Array(formatters) end include InstanceMethods end end def self.[](*args) warn "#{Kernel.caller.first}: [DEPRECATION] ::[] is deprecated. Use ::new instead." new(Array([*args])) end end end end simplecov-0.14.1/lib/simplecov/formatter/simple_formatter.rb0000644000004100000410000000111213130232776024300 0ustar www-datawww-data# # A ridiculously simple formatter for SimpleCov results. # module SimpleCov module Formatter class SimpleFormatter # Takes a SimpleCov::Result and generates a string out of it def format(result) output = "" result.groups.each do |name, files| output << "Group: #{name}\n" output << "=" * 40 output << "\n" files.each do |file| output << "#{file.filename} (coverage: #{file.covered_percent.round(2)}%)\n" end output << "\n" end output end end end end simplecov-0.14.1/lib/simplecov/profiles.rb0000644000004100000410000000153513130232776020555 0ustar www-datawww-data# # Profiles are SimpleCov configuration procs that can be easily # loaded using SimpleCov.start :rails and defined using # SimpleCov.profiles.define :foo do # # SimpleCov configuration here, same as in SimpleCov.configure # end # module SimpleCov class Profiles < Hash # # Define a SimpleCov profile: # SimpleCov.profiles.define 'rails' do # # Same as SimpleCov.configure do .. here # end # def define(name, &blk) name = name.to_sym raise "SimpleCov Profile '#{name}' is already defined" unless self[name].nil? self[name] = blk end # # Applies the profile of given name on SimpleCov.configure # def load(name) name = name.to_sym raise "Could not find SimpleCov Profile called '#{name}'" unless key?(name) SimpleCov.configure(&self[name]) end end end simplecov-0.14.1/lib/simplecov/load_global_config.rb0000644000004100000410000000042213130232776022510 0ustar www-datawww-datarequire "etc" home_dir = (ENV["HOME"] && File.expand_path("~")) || Etc.getpwuid.dir || (ENV["USER"] && File.expand_path("~#{ENV['USER']}")) if home_dir global_config_path = File.join(home_dir, ".simplecov") load global_config_path if File.exist?(global_config_path) end simplecov-0.14.1/lib/simplecov/no_defaults.rb0000644000004100000410000000010613130232776021226 0ustar www-datawww-dataENV["SIMPLECOV_NO_DEFAULTS"] = "yes, no defaults" require "simplecov" simplecov-0.14.1/lib/simplecov/jruby_fix.rb0000644000004100000410000000227113130232776020731 0ustar www-datawww-dataif defined?(JRUBY_VERSION) && JRUBY_VERSION.to_f < 1.7 require "jruby" java_import "org.jruby.ast.NodeType" # Coverage for JRuby < 1.7.0 does not work correctly # # - does not distinguish lines that cannot be executed # - does (partial) coverage for files loaded before `Coverage.start`. # - does not expand a path like `lib/../spec` to `spec`. # # This monkey patches Coverage to address those issues module Coverage class << self alias __broken_result__ result def result # rubocop:disable Metrics/MethodLength fixed = {} __broken_result__.each do |path, executed_lines| next unless File.file? path covered_lines = executed_lines.dup process = lambda do |node| if node.node_type == NodeType::NEWLINENODE pos = node.position covered_lines[pos.line] ||= 0 end node.child_nodes.each(&process) end process[JRuby.parse(File.read(path), path)] if (first = covered_lines.detect { |x| x }) && first > 0 fixed[File.expand_path(path)] = covered_lines end end fixed end end end end simplecov-0.14.1/lib/simplecov/defaults.rb0000644000004100000410000001112013130232776020530 0ustar www-datawww-data# Load default formatter gem require "simplecov-html" require "pathname" SimpleCov.profiles.define "root_filter" do # Exclude all files outside of simplecov root root_filter = nil add_filter do |src| root_filter ||= /\A#{Regexp.escape(SimpleCov.root)}/io !(src.filename =~ root_filter) end end SimpleCov.profiles.define "test_frameworks" do add_filter "/test/" add_filter "/features/" add_filter "/spec/" add_filter "/autotest/" end SimpleCov.profiles.define "bundler_filter" do add_filter "/vendor/bundle/" end SimpleCov.profiles.define "rails" do load_profile "test_frameworks" add_filter "/config/" add_filter "/db/" add_group "Controllers", "app/controllers" add_group "Channels", "app/channels" if defined?(ActionCable) add_group "Models", "app/models" add_group "Mailers", "app/mailers" add_group "Helpers", "app/helpers" add_group "Jobs", %w(app/jobs app/workers) add_group "Libraries", "lib" track_files "{app,lib}/**/*.rb" end # Default configuration SimpleCov.configure do formatter SimpleCov::Formatter::HTMLFormatter load_profile "bundler_filter" # Exclude files outside of SimpleCov.root load_profile "root_filter" end # Gotta stash this a-s-a-p, see the CommandGuesser class and i.e. #110 for further info SimpleCov::CommandGuesser.original_run_command = "#{$PROGRAM_NAME} #{ARGV.join(' ')}" at_exit do # rubocop:disable Metrics/BlockLength # If we are in a different process than called start, don't interfere. next if SimpleCov.pid != Process.pid @exit_status = 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) $!.is_a?(SystemExit) ? $!.status : SimpleCov::ExitCodes::EXCEPTION else # Store the exit status of the test run since it goes away # after calling the at_exit proc... SimpleCov::ExitCodes::SUCCESS end SimpleCov.at_exit.call if SimpleCov.result? # Result has been computed covered_percent = SimpleCov.result.covered_percent.round(2) covered_percentages = SimpleCov.result.covered_percentages.map { |p| p.round(2) } if @exit_status == SimpleCov::ExitCodes::SUCCESS # No other errors if covered_percent < SimpleCov.minimum_coverage # rubocop:disable Metrics/BlockNesting $stderr.printf("Coverage (%.2f%%) is below the expected minimum coverage (%.2f%%).\n", covered_percent, SimpleCov.minimum_coverage) @exit_status = SimpleCov::ExitCodes::MINIMUM_COVERAGE elsif covered_percentages.any? { |p| p < SimpleCov.minimum_coverage_by_file } # rubocop:disable Metrics/BlockNesting $stderr.printf("File (%s) is only (%.2f%%) covered. This is below the expected minimum coverage per file of (%.2f%%).\n", SimpleCov.result.least_covered_file, covered_percentages.min, SimpleCov.minimum_coverage_by_file) @exit_status = SimpleCov::ExitCodes::MINIMUM_COVERAGE elsif (last_run = SimpleCov::LastRun.read) # rubocop:disable Metrics/BlockNesting coverage_diff = last_run["result"]["covered_percent"] - covered_percent if coverage_diff > SimpleCov.maximum_coverage_drop # rubocop:disable Metrics/BlockNesting $stderr.printf("Coverage has dropped by %.2f%% since the last time (maximum allowed: %.2f%%).\n", coverage_diff, SimpleCov.maximum_coverage_drop) @exit_status = SimpleCov::ExitCodes::MAXIMUM_COVERAGE_DROP end end end # Don't overwrite last_run file if refuse_coverage_drop option is enabled and the coverage has dropped unless @exit_status == SimpleCov::ExitCodes::MAXIMUM_COVERAGE_DROP SimpleCov::LastRun.write(:result => {:covered_percent => covered_percent}) end end # Force exit with stored status (see github issue #5) # unless it's nil or 0 (see github issue #281) Kernel.exit @exit_status if @exit_status && @exit_status > 0 end # Autoload config from ~/.simplecov if present require "simplecov/load_global_config" # Autoload config from .simplecov if present # Recurse upwards until we find .simplecov or reach the root directory config_path = Pathname.new(SimpleCov.root) loop do filename = config_path.join(".simplecov") if filename.exist? begin load filename rescue LoadError, StandardError $stderr.puts "Warning: Error occurred while trying to load #{filename}. " \ "Error message: #{$!.message}" end break end config_path, = config_path.split break if config_path.root? end simplecov-0.14.1/lib/simplecov/filter.rb0000644000004100000410000000317613130232776020222 0ustar www-datawww-datamodule 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?(_) raise "The base filter class is not intended for direct use" end def passes?(source_file) warn "#{Kernel.caller.first}: [DEPRECATION] #passes? is deprecated. Use #matches? instead." matches?(source_file) end 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 class ArrayFilter < SimpleCov::Filter # Returns true if any of the file paths passed in the given array matches the string # configured when initializing this Filter with StringFilter.new(['some/path', 'other/path']) def matches?(source_files_list) filter_argument.any? do |arg| source_files_list.filename =~ /#{arg}/ end end end end simplecov-0.14.1/lib/simplecov/result_merger.rb0000644000004100000410000000557513130232776021621 0ustar www-datawww-datarequire "json" # # 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 module ResultMerger class << self # The path to the .resultset.json cache file def resultset_path File.join(SimpleCov.coverage_path, ".resultset.json") end def resultset_writelock File.join(SimpleCov.coverage_path, ".resultset.json.lock") end # Loads the cached resultset from JSON and returns it as a Hash def resultset if stored_data begin JSON.parse(stored_data) rescue {} end 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 return unless File.exist?(resultset_path) data = File.read(resultset_path) return if data.nil? || data.length < 2 data 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 # Merge two or more SimpleCov::Results into a new one with merged # coverage data and the command_name for the result consisting of a join # on all source result's names def merge_results(*results) merged = SimpleCov::RawCoverage.merge_results(*results.map(&:original_result)) result = SimpleCov::Result.new(merged) # Specify the command name result.command_name = results.map(&:command_name).sort.join(", ") result 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 merge_results(*results) end # Saves the given SimpleCov::Result in the resultset cache def store_result(result) File.open(resultset_writelock, "w+") do |f| f.flock(File::LOCK_EX) new_set = resultset command_name, data = result.to_hash.first new_set[command_name] = data File.open(resultset_path, "w+") do |f_| f_.puts JSON.pretty_generate(new_set) end end true end end end end simplecov-0.14.1/lib/simplecov/version.rb0000644000004100000410000000041613130232776020414 0ustar www-datawww-datamodule SimpleCov version = "0.14.1" def version.to_a split(".").map(&:to_i) end def version.major to_a[0] end def version.minor to_a[1] end def version.patch to_a[2] end def version.pre to_a[3] end VERSION = version end simplecov-0.14.1/lib/simplecov/file_list.rb0000644000004100000410000000346613130232776020711 0ustar www-datawww-data# An array of SimpleCov SourceFile instances with additional collection helper # methods for calculating coverage across them etc. module SimpleCov class 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 # Computes the coverage based upon lines covered and lines missed for each file # Returns an array with all coverage percentages def covered_percentages map(&:covered_percent) end # Finds the least covered file and returns that file's name def least_covered_file sort_by(&:covered_percent).first.filename 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 # @return [Float] def covered_percent return 100.0 if empty? || lines_of_code.zero? Float(covered_lines * 100.0 / lines_of_code) end # Computes the strength (hits / line) based upon lines covered and lines missed # @return [Float] def covered_strength return 0.0 if empty? || lines_of_code.zero? Float(map { |f| f.covered_strength * f.lines_of_code }.inject(&:+) / lines_of_code) end end end simplecov-0.14.1/lib/simplecov/source_file.rb0000644000004100000410000001365213130232776021234 0ustar www-datawww-datamodule 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 source src alias line line_number alias number line_number def initialize(src, line_number, coverage) raise ArgumentError, "Only String accepted for source" unless src.is_a?(String) raise ArgumentError, "Only Integer accepted for line_number" unless line_number.is_a?(Integer) raise ArgumentError, "Only Integer and nil accepted for coverage" unless coverage.is_a?(Integer) || coverage.nil? @src = src @line_number = line_number @coverage = coverage @skipped = false end # Returns true if this is a line that should have been covered, but was not def missed? !never? && !skipped? && coverage.zero? end # Returns true if this is a line that has been covered def covered? !never? && !skipped? && coverage > 0 end # Returns true if this line is not relevant for coverage def never? !skipped? && coverage.nil? end # Flags this line as skipped def skipped! @skipped = true end # Returns true if this line was skipped, false otherwise. Lines are skipped if they are wrapped with # # :nocov: comment lines. def skipped? !!skipped end # The status of this line - either covered, missed, skipped or never. Useful i.e. for direct use # as a css class in report generation def status return "skipped" if skipped? return "never" if never? return "missed" if missed? return "covered" if covered? end end # 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 def initialize(filename, coverage) @filename = filename @coverage = coverage end # The source code for this file. Aliased as :source def src # We intentionally read source code lazily to # suppress reading unused source code. @src ||= File.open(filename, "rb", &:readlines) end alias source src # Returns all source lines for this file as instances of SimpleCov::SourceFile::Line, # and thus including coverage data. Aliased as :source_lines def lines @lines ||= build_lines end alias source_lines lines def build_lines coverage_exceeding_source_warn if coverage.size > src.size lines = src.map.with_index(1) do |src, i| SimpleCov::SourceFile::Line.new(src, i, coverage[i - 1]) end process_skipped_lines(lines) end # Warning to identify condition from Issue #56 def coverage_exceeding_source_warn $stderr.puts "Warning: coverage data provided by Coverage [#{coverage.size}] exceeds number of lines in #{filename} [#{src.size}]" end # Access SimpleCov::SourceFile::Line source lines by line number def line(number) lines[number - 1] end # The coverage for this file in percent. 0 if the file has no relevant lines def covered_percent return 100.0 if no_lines? return 0.0 if relevant_lines.zero? Float(covered_lines.size * 100.0 / relevant_lines.to_f) end def covered_strength return 0.0 if relevant_lines.zero? round_float(lines_strength / relevant_lines.to_f, 1) end def no_lines? lines.length.zero? || (lines.length == never_lines.size) end def lines_strength lines.map(&:coverage).compact.reduce(:+) end def relevant_lines lines.size - never_lines.size - skipped_lines.size end # Returns all covered lines as SimpleCov::SourceFile::Line def covered_lines @covered_lines ||= lines.select(&:covered?) end # Returns all lines that should have been, but were not covered # as instances of SimpleCov::SourceFile::Line def missed_lines @missed_lines ||= lines.select(&:missed?) end # Returns all lines that are not relevant for coverage as # SimpleCov::SourceFile::Line instances def never_lines @never_lines ||= lines.select(&:never?) end # Returns all lines that were skipped as SimpleCov::SourceFile::Line instances def skipped_lines @skipped_lines ||= lines.select(&:skipped?) end # Returns the number of relevant lines (covered + missed) def lines_of_code covered_lines.size + missed_lines.size end # Will go through all source files and mark lines that are wrapped within # :nocov: comment blocks # as skipped. def process_skipped_lines(lines) skipping = false lines.each do |line| if line.src =~ /^([\s]*)#([\s]*)(\:#{SimpleCov.nocov_token}\:)/ skipping = !skipping line.skipped! elsif skipping line.skipped! end end end private # ruby 1.9 could use Float#round(places) instead # @return [Float] def round_float(float, places) factor = Float(10 * places) Float((float * factor).round / factor) end end end simplecov-0.14.1/lib/simplecov/raw_coverage.rb0000644000004100000410000000172713130232776021401 0ustar www-datawww-datamodule SimpleCov module RawCoverage module_function # Merges multiple Coverage.result hashes def merge_results(*results) results.reduce({}) do |result, merged| merge_resultsets(result, merged) end end # Merges two Coverage.result hashes def merge_resultsets(result1, result2) (result1.keys | result2.keys).each_with_object({}) do |filename, merged| file1 = result1[filename] file2 = result2[filename] merged[filename] = merge_file_coverage(file1, file2) end end def merge_file_coverage(file1, file2) return (file1 || file2).dup unless file1 && file2 file1.map.with_index do |count1, index| count2 = file2[index] merge_line_coverage(count1, count2) end end def merge_line_coverage(count1, count2) sum = count1.to_i + count2.to_i if sum.zero? && (count1.nil? || count2.nil?) nil else sum end end end end simplecov-0.14.1/lib/simplecov/last_run.rb0000644000004100000410000000076413130232776020564 0ustar www-datawww-datarequire "json" module SimpleCov module LastRun class << self def last_run_path File.join(SimpleCov.coverage_path, ".last_run.json") end def read return nil unless File.exist?(last_run_path) json = File.read(last_run_path) return nil if json.strip.empty? JSON.parse(json) end def write(json) File.open(last_run_path, "w+") do |f| f.puts JSON.pretty_generate(json) end end end end end simplecov-0.14.1/lib/simplecov/exit_codes.rb0000644000004100000410000000020713130232776021053 0ustar www-datawww-datamodule SimpleCov module ExitCodes SUCCESS = 0 EXCEPTION = 1 MINIMUM_COVERAGE = 2 MAXIMUM_COVERAGE_DROP = 3 end end simplecov-0.14.1/lib/simplecov/railtie.rb0000644000004100000410000000020313130232776020352 0ustar www-datawww-datamodule SimpleCov class Railtie < ::Rails::Railtie rake_tasks do load "simplecov/railties/tasks.rake" end end end simplecov-0.14.1/cucumber.yml0000644000004100000410000000113013130232776016155 0ustar www-datawww-data<% 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 %> simplecov-0.14.1/.rubocop.yml0000644000004100000410000000271113130232776016105 0ustar www-datawww-dataAllCops: Exclude: - 'spec/fixtures/iso-8859.rb' - 'tmp/**/*' - 'vendor/bundle/**/*' Bundler/OrderedGems: Enabled: false Lint/AmbiguousRegexpLiteral: Exclude: - 'features/**/*_steps.rb' - 'spec/**/*_steps.rb' - 'tmp/**/*_steps.rb' Metrics/AbcSize: Max: 25 # TODO: Lower to 15 Metrics/BlockLength: Exclude: - 'spec/**/*.rb' Metrics/BlockNesting: Max: 2 Metrics/LineLength: AllowURI: true Enabled: false Metrics/MethodLength: CountComments: false Max: 12 # TODO: Lower to 10 Metrics/ParameterLists: Max: 4 CountKeywordArgs: true Style/AccessModifierIndentation: EnforcedStyle: outdent Style/CollectionMethods: PreferredMethods: map: 'collect' reduce: 'inject' find: 'detect' find_all: 'select' Style/Documentation: Enabled: false Style/DoubleNegation: Enabled: false Style/HashSyntax: EnforcedStyle: hash_rockets Style/RegexpLiteral: Enabled: false Style/SpaceInsideHashLiteralBraces: EnforcedStyle: no_space Style/SpecialGlobalVars: Exclude: - 'spec/deleted_source_spec.rb' - 'spec/return_codes_spec.rb' - 'lib/simplecov/defaults.rb' Style/StringLiterals: EnforcedStyle: double_quotes Style/FileName: Exclude: - 'spec/fixtures/utf-8.rb' Style/TrailingCommaInLiteral: EnforcedStyleForMultiline: comma Style/GuardClause: Enabled: false Style/MutableConstant: Exclude: - 'lib/simplecov/version.rb' # required for older versions of rubygems simplecov-0.14.1/.gitignore0000644000004100000410000000034513130232776015624 0ustar www-datawww-data.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 simplecov-0.14.1/simplecov.gemspec0000644000004100000410000000204613130232776017202 0ustar www-datawww-data$LOAD_PATH.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 = %(Code coverage for Ruby 1.9+ with a powerful configuration library and automatic merging of coverage across test suites) gem.summary = gem.description gem.license = "MIT" gem.required_ruby_version = ">= 1.8.7" gem.add_dependency "json", ">= 1.8", "< 3" gem.add_dependency "simplecov-html", "~> 0.10.0" gem.add_dependency "docile", "~> 1.1.0" gem.add_development_dependency "bundler", "~> 1.9" 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 simplecov-0.14.1/.yardopts0000644000004100000410000000001213130232776015471 0ustar www-datawww-data- **/*.md simplecov-0.14.1/CONTRIBUTING.md0000644000004100000410000000370513130232776016070 0ustar www-datawww-data## Reporting Issues You can report issues at https://github.com/colszowka/simplecov/issues Search existing issues for your problem, chances are someone else already reported it. * Include the SimpleCov version you are running in your report. * If you are not running the latest version (please check), and you cannot update it, please specify in your report why you can't update to the latest version. * Include your `ruby -e "puts RUBY_DESCRIPTION"`. * Please also specify the gem versions of Rails (if applicable). * Include any other coverage gems you may be using and their versions. * Include how you run your tests and which testing framework or frameworks you are running. - If running via rake, please ensure you are requiring SimpleCov at the top of your Rakefile - Otherwise, please ensure you are requiring and starting SimpleCov before requiring any application code. For example, if running via RSpec, this would be at the top of your spec_helper. - Have you tried using a [`.simplecov` file](https://github.com/colszowka/simplecov#using-simplecov-for-centralized-config)? Include as much sample code as you can to help us reproduce the issue. (Inline, repo link, or gist, are fine. A failing test would help the most.) This is extremely important for narrowing down the cause of your problem. Thanks! ## Making Contributions To fetch & test the library for development, do: $ git clone https://github.com/colszowka/simplecov.git $ cd simplecov $ bundle $ bundle exec rake If you want to contribute, please: * Fork the project. * Make your feature addition or bug fix. * Add tests for it. This is important so I don't break it in a future version unintentionally. * **Bonus Points** go out to anyone who also updates `CHANGELOG.md` :) * Send me a pull request on Github. ## Running Individual Tests This project uses Test::Unit. Individual tests can be run like this: ```bash ruby -I test path/to/test.rb ``` simplecov-0.14.1/CHANGELOG.md0000644000004100000410000006351113130232776015451 0ustar www-datawww-data0.14.1 2017-03-18 ([changes](https://github.com/colszowka/simplecov/compare/v0.14.0...v0.14.1)) ======== ## Bugfixes * Files that were skipped as a whole/had no relevant coverage could lead to Float errors. See [#564](https://github.com/colszowka/simplecov/pull/564) (thanks to @stevehanson for the report in [#563](https://github.com/colszowka/simplecov/issues/563)) 0.14.0 2017-03-15 ([changes](https://github.com/colszowka/simplecov/compare/v0.13.0...v0.14.0)) ========== ## Enhancements * Officially support JRuby 9.1+ going forward (should also work with previous releases). See [#547](https://github.com/colszowka/simplecov/pull/547) (ping @PragTob when encountering issues) * Add Channel group to Rails profile, when `ActionCable` is loaded. See [#492](https://github.com/colszowka/simplecov/pull/492) (thanks @BenMorganIO) * Stop `extend`ing instances of `Array` and `Hash` during merging results avoiding problems frozen results while manually merging results. See [#558](https://github.com/colszowka/simplecov/pull/558) (thanks @aroben) ## Bugfixes * Fix parallel_tests when a thread ends up running no tests. See [#533](https://github.com/colszowka/simplecov/pull/533) (thanks @cshaffer) * Skip the `:nocov:` comments along with the code that they skip. See [#551](https://github.com/colszowka/simplecov/pull/551) (thanks @ebiven) * Fix crash when Home environment variable is unset. See [#482](https://github.com/colszowka/simplecov/pull/482) (thanks @waldyr) * Make track_files work again when explicitly setting it to nil. See [#463](https://github.com/colszowka/simplecov/pull/463) (thanks @craiglittle) * Do not overwrite .last_run.json file when refuse_coverage_drop option is enabled and the coverage has dropped (lead to you being able to just rerun tests and everything was _fine_). See [#553](https://github.com/colszowka/simplecov/pull/553) (thanks @Miloshes) 0.13.0 2017-01-25 ([changes](https://github.com/colszowka/simplecov/compare/v0.12.0...v0.13.0)) ========== ## Enhancements * Faster run times when a very large number of files is loaded into SimpleCov. See [#520](https://github.com/colszowka/simplecov/pull/520) (thanks @alyssais) * Only read in source code files that are actually used (faster when files are ignored etc.). See [#540](https://github.com/colszowka/simplecov/pull/540) (thanks @yui-knk) ## Bugfixes * Fix merging of resultsets if a file is missing on one side. See [#513](https://github.com/colszowka/simplecov/pull/513) (thanks @hanazuki) * Fix Ruby 2.4 deprecation warnings by using Integer instead of Fixnum. See [#523](https://github.com/colszowka/simplecov/pull/523) (thanks @nobu) * Force Ruby 2 to json 2. See [dc7417d50](https://github.com/colszowka/simplecov/commit/dc7417d5049b1809cea214314c15dd93a5dd964f) (thanks @amatsuda) * Various other gem dependency fixes for different gems on different ruby versions. (thanks @amatsuda) 0.12.0 2016-07-02 ([changes](https://github.com/colszowka/simplecov/compare/v0.11.2...v0.12.0)) ================= ## Enhancements * Add support for JSON versions 2.x ## Bugfixes * Fix coverage rate of the parallel_tests. See [#441](https://github.com/colszowka/simplecov/pull/441) (thanks @sinsoku) * Fix a regression on old rubies that failed to work with the recently introduced frozen VERSION string. See [#461](https://github.com/colszowka/simplecov/pull/461) (thanks @leafle) 0.11.2 2016-02-03 ([changes](https://github.com/colszowka/simplecov/compare/v0.11.1...v0.11.2)) ================= ## Enhancements * Do not globally pollute Array and Hash with `merge_resultset` utility methods. See [#449](https://github.com/colszowka/simplecov/pull/449) (thanks @amatsuda) * Do not `mkdir_p` the `coverage_path` on every access of the method (See [#453](https://github.com/colszowka/simplecov/pull/453) (thanks @paddor) * Fixes a Ruby warning related to the `track_files` configuration. See [#447](https://github.com/colszowka/simplecov/pull/447) (thanks @craiglittle) * Add a group for background jobs to default Rails profile. See [#442](https://github.com/colszowka/simplecov/pull/442) (thanks @stve) ## Bugfixes * Fix root_filter evaluates SimpleCov.root before initialization. See [#437](https://github.com/colszowka/simplecov/pull/437) (thanks @tmtm) 0.11.1 2015-12-01 ([changes](https://github.com/colszowka/simplecov/compare/v0.11.0...v0.11.1)) ================= ## Enhancements ## Bugfixes * Fixed regression in `MultiFormatter.[]` with multiple arguments. See [#431](https://github.com/colszowka/simplecov/pull/431) (thanks @dillondrobena) 0.11.0 2015-11-29 ([changes](https://github.com/colszowka/simplecov/compare/v0.10.0...v0.11.0)) ================= ## Enhancements * Added `SimpleCov.minimum_coverage_by_file` for per-file coverage thresholds. See [#392](https://github.com/colszowka/simplecov/pull/392) (thanks @ptashman) * Added `track_files` configuration option to specify a glob to always include in coverage results, whether or not those files are required. By default, this is enabled in the Rails profile for common Rails directories. See [#422](https://github.com/colszowka/simplecov/pull/422) (thanks @hugopeixoto) * Speed up `root_filter` by an order of magnitude. See [#396](https://github.com/colszowka/simplecov/pull/396) (thanks @raszi) ## Bugfixes * Fix warning about global variable `$ERROR_INFO`. See [#400](https://github.com/colszowka/simplecov/pull/400) (thanks @amatsuda) * Actually recurse upward looking for `.simplecov`, as claimed by the documentation, rather than only the working directory. See [#423](https://github.com/colszowka/simplecov/pull/423) (thanks @alexdowad) 0.10.0 2015-04-18 ([changes](https://github.com/colszowka/simplecov/compare/v0.9.2...v0.10.0)) ================= ## Enhancements * Add writeup about using with Spring to README. See [#341](https://github.com/colszowka/simplecov/issues/341) (thanks @swrobel and @onebree) * Add support to pass in an Array when creating filter groups (original PR #104) * Filter `/vendor/bundle` by default. See [#331](https://github.com/colszowka/simplecov/pull/331) (thanks @andyw8) * Add some helpful singleton methods to the version string. * Allow array to be passed in a filter. See [375](https://github.com/colszowka/simplecov/pull/375) (thanks @JanStevens) * Enforce consistent code formatting with RuboCop. ## Bugfixes * Fix order dependencies in unit tests. See [#376](https://github.com/colszowka/simplecov/pull/376) (thanks @hugopeixoto) * Only run the at_exit behaviors if the current PID matches the PID that called SimpleCov.start. See [#377](https://github.com/colszowka/simplecov/pull/377) (thanks @coderanger) 0.9.2, 2015-02-18 ([changes](https://github.com/colszowka/simplecov/compare/v0.9.1...v0.9.2)) ================= This is a minor bugfix release for simplecov-html, released as `0.9.0`. Due to the tight version constraint in the gemspec a new release of simplecov had to be shipped to allow using simplecov-html `~> 0.9.0`. * The browser back / forward button should now work again. See [#36](https://github.com/colszowka/simplecov-html/pull/36) and [#35](https://github.com/colszowka/simplecov-html/pull/35). Thanks @whatasunnyday and @justinsteele for submitting PRs to fix this. * Fix "warning: possibly useless use of a variable in void context" See [#31](https://github.com/colszowka/simplecov-html/pull/31). Thanks @cbandy * Always use binary file format. See [#32](https://github.com/colszowka/simplecov-html/pull/32). Thanks @andy128k * Avoid slow file output with JRuby/Windows. See [#16](https://github.com/colszowka/simplecov-html/pull/16). Thanks @pschambacher Other than the release includes a bunch of mostly documentation improvements: * Update Rails path for Rails 4+. See [#336](https://github.com/colszowka/simplecov/pull/336). Thanks @yazinsai * Encourage use of .simplecov to avoid lost files. See [#338](https://github.com/colszowka/simplecov/pull/338). thanks @dankohn * Specified in the gemspec that simplecov needs ruby 1.8.7. See [#343](https://github.com/colszowka/simplecov/pull/343). thanks @iainbeeston * Fix mispointed link in CHANGELOG.md. See [#353](https://github.com/colszowka/simplecov/pull/353). Thanks @dleve123 * Improve command name docs. See [#356](https://github.com/colszowka/simplecov/pull/356). Thanks @gtd 0.9.1, 2014-09-21 ([changes](https://github.com/colszowka/simplecov/compare/v0.9.0...v0.9.1)) ================= ## Bugfixes * In 0.9.0, we introduced a regression that made SimpleCov no-op mode fail on Ruby 1.8, while dropping 1.8 support altogether is announced only for v1.0. This has been fixed. See [#333](https://github.com/colszowka/simplecov/issues/333) (thanks (@sferik) 0.9.0, 2014-07-17 ([changes](https://github.com/colszowka/simplecov/compare/v0.8.2...v0.9.0)) ================= **A warm welcome and big thank you to the new contributors [@xaviershay](https://github.com/xaviershay), [@sferik](https://github.com/sferik) and especially [@bf4](https://github.com/bf4) for tackling a whole lot of issues and pull requests for this release!** ## Enhancements * New interface to specify multiple formatters. See [#317](https://github.com/colszowka/simplecov/pull/317) (thanks @sferik) * Document in the README how to exclude code from coverage reports, and that the feature shouldn't be abused for skipping untested private code. See [#304](https://github.com/colszowka/simplecov/issues/304) * Clarify Ruby version support. See [#279](https://github.com/colszowka/simplecov/pull/279) (thanks @deivid-rodriguez) ## Bugfixes * Ensure calculations return Floats, not Fixnum or Rational. Fixes segfaults with mathn. See [#245](https://github.com/colszowka/simplecov/pull/245) (thanks to @bf4) * Using `Kernel.exit` instead of exit to avoid uncaught throw :IRB_EXIT when exiting irb sessions. See [#287](https://github.com/colszowka/simplecov/pull/287) (thanks @wless1) See [#285](https://github.com/colszowka/simplecov/issues/285) * Does not look for .simplecov in ~/ when $HOME is not set. See [#311](https://github.com/colszowka/simplecov/pull/311) (thanks @lasseebert) * Exit with code only if it's Numeric > 0. See [#302](https://github.com/colszowka/simplecov/pull/302) (thanks @hajder) * Make default filter case insensitive. See [#280](https://github.com/colszowka/simplecov/pull/280) (thanks @ryanatball) * Improve regexp that matches functional tests. See [#276](https://github.com/colszowka/simplecov/pull/276) (thanks @sferik) * Fix TravisCI [#272](https://github.com/colszowka/simplecov/pull/272) [#278](https://github.com/colszowka/simplecov/pull/278), [#302](https://github.com/colszowka/simplecov/pull/302) * Fix global config load. See [#311](https://github.com/colszowka/simplecov/pull/311) (thanks @lasseebert) v0.8.2, 2013-11-20 ([changes](https://github.com/colszowka/simplecov/compare/v0.8.1...v0.8.2)) ================== ## Bugfixes * Replaced the locking behaviour [via lockfile gem](https://github.com/colszowka/simplecov/pull/185) with plain Ruby explicit file locking when merging results. This should make simplecov merging to behave well on Windows again. See [#258](https://github.com/colszowka/simplecov/issues/258) and [#223](https://github.com/colszowka/simplecov/pull/223) (thanks to @tomykaira) v0.8.1, 2013-11-10 ([changes](https://github.com/colszowka/simplecov/compare/v0.8.0...v0.8.1)) ================== ## Bugfixes * Fixed a regression introduced in 0.8.0 - the Forwardable STDLIB module is now required explicitly. See [#256](https://github.com/colszowka/simplecov/pull/256) (thanks to @kylev) v0.8.0, 2013-11-10 ([changes](https://github.com/colszowka/simplecov/compare/v0.7.1...v0.8.0)) ================== **Note: Yanked the same day because of the regression that 0.8.1 fixes, see above** ## TL;DR It's been way too long since the last official release 0.7.1, but this was partly due to it proving itself quite stable in most circumstances. This release brings various further stability improvements to result set merging (especially when working with parallel_tests), the configuration, source file encodings, and command name guessing. The 0.8 line is the last one to cooperate with Ruby < 1.9. Starting with 0.9, SimpleCov will assume to be running in Ruby 1.9+, and will not try to detect or bail silently on older Ruby versions. An appropriate deprecation warning has been added. ## Features * Configuration blocks now have access to variables and methods outside of the block's scope. See [#238](https://github.com/colszowka/simplecov/pull/238) (thanks to @ms-tg) * You can now have a global `~/.simplecov` configuration file. See [#195](https://github.com/colszowka/simplecov/pull/195) (thanks to @spagalloco) * simplecov-html now uses the MIT-licensed colorbox plugin. Some adjustments when viewing source files, including retaining the currently open file on refresh have been added. See [simplecov-html #15](https://github.com/colszowka/simplecov-html/pull/15) (thanks to @chetan) * Adds support for Rails 4 command guessing, removes default group `vendor/plugins`. See [#181](https://github.com/colszowka/simplecov/pull/181) and [#203](https://github.com/colszowka/simplecov/pull/203) (thanks to @semanticart and @phallstrom) * You can now load simplecov without the default settings by doing `require 'simplecov/no_defaults'` or setting `ENV['SIMPLECOV_NO_DEFAULTS']`. Check `simplecov/defaults` to see what preconfigurations are getting dropped by using this. See [#209](https://github.com/colszowka/simplecov/pull/209) (thanks to @ileitch) * The result set merging now uses the `lockfile` gem to avoid race conditions. See [#185](https://github.com/colszowka/simplecov/pull/185) (thanks to @jshraibman-mdsol). * Automatically detect the usage of parallel_tests and adjust the command name with the test env number accordingly, See [#64](https://github.com/colszowka/simplecov/issues/64) and [#185](https://github.com/colszowka/simplecov/pull/185) (thanks to @jshraibman-mdsol). ## Enhancements * Rename adapters to "profiles" given that they are bundles of settings. The old adapter methods are deprecated, but remain available for now. See [#207](https://github.com/colszowka/simplecov/pull/207) (thanks to @mikerobe) * Tweaks to the automatic test suite naming. In particular, `rspec/features` should now be correctly attributed to RSpec, not Cucumber. See [#212](https://github.com/colszowka/simplecov/pull/212) (thanks to @ersatzryan and @betelgeuse) * MiniTest should now be identified correctly by the command name guesser. See [#244](https://github.com/colszowka/simplecov/pull/244) (thanks to @envygeeks) * Makes SimpleCov resilient to inclusion of mathn library. See [#175](https://github.com/colszowka/simplecov/pull/175) and [#140](https://github.com/colszowka/simplecov/issues/140) (thanks to @scotje) * Allow coverage_dir to be an absolute path. * See [#190](https://github.com/colszowka/simplecov/pull/190) (thanks to @jshraibman-mdsol) * The internal cucumber test suite now uses Capybara 2. See [#206](https://github.com/colszowka/simplecov/pull/206) (thanks to @infertux) * Work-arounds for the Coverage library shipped in JRuby 1.6 to behave in line with MRI. See [#174](https://github.com/colszowka/simplecov/pull/174) (thanks to @grddev) * Fix warning: instance variable @exit_status not initialized. See [#242](https://github.com/colszowka/simplecov/pull/242) and [#213](https://github.com/colszowka/simplecov/pull/213) (thanks to @sferik and @infertux) ## Bugfixes * Correct result calculations for people using :nocov: tags. See [#215](https://github.com/colszowka/simplecov/pull/215) (thanks to @aokolish) * Average hits per line for groups of files is now computed correctly. See [#192](http://github.com/colszowka/simplecov/pull/192) and [#179](http://github.com/colszowka/simplecov/issues/179) (thanks to @graysonwright) * Compatability with BINARY internal encoding. See [#194](https://github.com/colszowka/simplecov/pull/194) and [#127](https://github.com/colszowka/simplecov/issues/127) (thanks to @justfalter) * Special characters in `SimpleCov.root` are now correctly escaped before being used as a RegExp. See [#204](https://github.com/colszowka/simplecov/issues/204) and [#237](https://github.com/colszowka/simplecov/pull/237) (thanks to @rli9) 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 them simplecov-0.14.1/README.md0000644000004100000410000005720113130232776015116 0ustar www-datawww-dataSimpleCov [![Build Status](https://travis-ci.org/colszowka/simplecov.svg)][Continuous Integration] [![Dependency Status](https://gemnasium.com/colszowka/simplecov.svg)][Dependencies] [![Code Climate](https://codeclimate.com/github/colszowka/simplecov.svg)](https://codeclimate.com/github/colszowka/simplecov) [![Inline docs](http://inch-ci.org/github/colszowka/simplecov.svg)](http://inch-ci.org/github/colszowka/simplecov) ========= **Code coverage for Ruby** * [Source Code] * [API documentation] * [Changelog] * [Rubygem] * [Continuous Integration] [Coverage]: http://www.ruby-doc.org/stdlib-2.1.0/libdoc/coverage/rdoc/Coverage.html "API doc for Ruby'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" SimpleCov is a code coverage analysis tool for Ruby. It uses [Ruby's built-in Coverage][Coverage] library to gather code coverage data, but makes processing its results much easier by providing a clean API to filter, group, merge, format, and display those results, giving you a complete code coverage suite that can be set up with just a couple lines of code. In most cases, you'll want overall coverage results for your projects, including all types of tests, Cucumber features, etc. SimpleCov automatically takes care of this by caching and merging results when generating reports, so your report actually includes coverage across your test suites and thereby gives you a better picture of blank spots. The official formatter of SimpleCov is packaged as a separate gem called [simplecov-html], but will be installed and configured automatically when you launch SimpleCov. If you're curious, you can find it [on Github, too][simplecov-html]. ## Contact *Code and Bug Reports* * [Issue Tracker](https://github.com/colszowka/simplecov/issues) * See [CONTRIBUTING](https://github.com/colszowka/simplecov/blob/master/CONTRIBUTING.md) for how to contribute along with some common problems to check out before creating an issue. *Questions, Problems, Suggestions, etc.* * [Mailing List]: https://groups.google.com/forum/#!forum/simplecov "Open mailing list for discussion and announcements on Google Groups" Getting started --------------- 1. Add SimpleCov to your `Gemfile` and `bundle install`: ```ruby gem 'simplecov', :require => false, :group => :test ``` 2. Load and launch SimpleCov **at the very top** of your `test/test_helper.rb` (*or `spec_helper.rb`, cucumber `env.rb`, or whatever your preferred test framework uses*): ```ruby require 'simplecov' SimpleCov.start # Previous content of test helper now starts here ``` **Note:** If SimpleCov starts after your application code is already loaded (via `require`), it won't be able to track your files and their coverage! The `SimpleCov.start` **must** be issued **before any of your application code is required!** SimpleCov must be running in the process that you want the code coverage analysis to happen on. When testing a server process (e.g. a JSON API endpoint) via a separate test process (e.g. when using Selenium) where you want to see all code executed by the `rails server`, and not just code executed in your actual test files, you'll want to add something like this to the top of `script/rails` (or `bin/rails` for Rails 4), but below the "shebang" line (`#! /usr/bin/env ruby`): ```ruby 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 built-in configurations (see below for information on profiles) that 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: ```ruby require 'simplecov' SimpleCov.start 'rails' ``` ## Example output **Coverage results report, fully browsable locally with sorting and much more:** ![SimpleCov coverage report](https://cloud.githubusercontent.com/assets/137793/17071162/db6f253e-502d-11e6-9d84-e40c3d75f333.png) **Source file coverage details view:** ![SimpleCov source file detail view](https://cloud.githubusercontent.com/assets/137793/17071163/db6f9f0a-502d-11e6-816c-edb2c66fad8d.png) ## Use it with any framework! Similarly to the usage with Test::Unit described above, the only thing you have to do is to add the SimpleCov config to the very top of your Cucumber/RSpec/whatever setup file. Add the setup code to the **top** of `features/support/env.rb` (for Cucumber) or `spec/spec_helper.rb` (for RSpec). Other test frameworks should work accordingly, whatever their setup file may be: ```ruby require 'simplecov' SimpleCov.start 'rails' ``` You could even track what kind of code your UI testers are touching if you want to go overboard with things. SimpleCov does not care what kind of framework it is running in; it just looks at what code is being executed and generates a report about it. ### Notes on specific frameworks and test utilities For some frameworks and testing tools there are quirks and problems you might want to know about if you want to use SimpleCov with them. Here's an overview of the known ones:
FrameworkNotesIssue
parallel_tests As of 0.8.0, SimpleCov should correctly recognize parallel_tests and supplement your test suite names with their corresponding test env numbers. SimpleCov locks the resultset cache while merging, ensuring no race conditions occur when results are merged. #64 & #185
RubyMine The RubyMine IDE has built-in support for SimpleCov's coverage reports, though you might need to explicitly set the output root using `SimpleCov.root('foo/bar/baz')` #95
Spork Because of how Spork works internally (using preforking), there used to be trouble when using SimpleCov with it, but that has apparently been resolved with a specific configuration strategy. See this comment. #42
Spring See section below. #381
Test/Unit Test Unit 2 used to mess with ARGV, leading to a failure to detect the test process name in SimpleCov. test-unit releases 2.4.3+ (Dec 11th, 2011) should have this problem resolved. #45 & test-unit/test-unit#12
## Configuring SimpleCov [Configuration] settings can be applied in three formats, which are completely equivalent: * The most common way is to configure it directly in your start block: ```ruby SimpleCov.start do some_config_option 'foo' end ``` * You can also set all configuration options directly: ```ruby SimpleCov.some_config_option 'foo' ``` * If you do not want to start coverage immediately after launch or want to add additional configuration later on in a concise way, use: ```ruby SimpleCov.configure do some_config_option 'foo' end ``` Please check out the [Configuration] API documentation to find out what you can customize. ## Using .simplecov for centralized config If you use SimpleCov to merge multiple test suite results (e.g. Test/Unit and Cucumber) into a single report, you'd normally have to set up all your config options twice, once in `test_helper.rb` and once in `env.rb`. To avoid this, you can place a file called `.simplecov` in your project root. You can then just leave the `require 'simplecov'` in each test setup helper and move the `SimpleCov.start` code with all your custom config options into `.simplecov`: ```ruby # test/test_helper.rb require 'simplecov' # features/support/env.rb require 'simplecov' # .simplecov SimpleCov.start 'rails' do # any custom configs like groups and filters can be here at a central place end ``` Using `.simplecov` rather than separately requiring SimpleCov multiple times is recommended if you are merging multiple test frameworks like Cucumber and RSpec that rely on each other, as invoking SimpleCov multiple times can cause coverage information to be lost. ## Filters Filters can be used to remove selected files from your coverage data. By default, a filter is applied that removes all files OUTSIDE of your project's root directory - otherwise you'd end up with billions of coverage reports for source files in the gems you are using. You can define your own to remove things like configuration files, tests or whatever you don't need in your coverage report. ### Defining custom filters You can currently define a filter using either a String (that will then be Regexp-matched against each source file's path), a block or by passing in your own Filter class. #### String filter ```ruby SimpleCov.start do add_filter "/test/" end ``` This simple string filter will remove all files that match "/test/" in their path. #### Block filter ```ruby SimpleCov.start do add_filter do |source_file| source_file.lines.count < 5 end end ``` Block filters receive a SimpleCov::SourceFile instance and expect your block to return either true (if the file is to be removed from the result) or false (if the result should be kept). Please check out the RDoc for SimpleCov::SourceFile to learn about the methods available to you. In the above example, the filter will remove all files that have less than 5 lines of code. #### Custom filter class ```ruby class LineFilter < SimpleCov::Filter def matches?(source_file) source_file.lines.count < filter_argument end end SimpleCov.add_filter LineFilter.new(5) ``` Defining your own filters is pretty easy: Just inherit from SimpleCov::Filter and define a method 'matches?(source_file)'. When running the filter, a true return value from this method will result in the removal of the given source_file. The filter_argument method is being set in the SimpleCov::Filter initialize method and thus is set to 5 in this example. #### Ignoring/skipping code You can exclude code from the coverage report by wrapping it in `# :nocov:`. ```ruby # :nocov: def skip_this_method never_reached end # :nocov: ``` The name of the token can be changed to your liking. [Learn more about the nocov feature.][nocov] [nocov]: https://github.com/colszowka/simplecov/blob/master/features/config_nocov_token.feature **Note:** You shouldn't have to use the nocov token to skip private methods that are being included in your coverage. If you appropriately test the public interface of your classes and objects you should automatically get full coverage of your private methods. ## Default root filter and coverage for things outside of it By default, SimpleCov filters everything outside of the `SimpleCov.root` directory. However, sometimes you may want to include coverage reports for things you include as a gem, for example a Rails Engine. Here's an example by [@lsaffie](https://github.com/lsaffie) from [#221](https://github.com/colszowka/simplecov/issues/221) that shows how you can achieve just that: ```ruby SimpleCov.start :rails do filters.clear # This will remove the :root_filter and :bundler_filter that come via simplecov's defaults add_filter do |src| !(src.filename =~ /^#{SimpleCov.root}/) unless src.filename =~ /my_engine/ end end ``` ## Groups You can separate your source files into groups. For example, in a Rails app, you'll want to have separate listings for Models, Controllers, Helpers, and Libs. Group definition works similarly to Filters (and also accepts custom filter classes), but source files end up in a group when the filter passes (returns true), as opposed to filtering results, which exclude files from results when the filter results in a true value. Add your groups with: ```ruby SimpleCov.start do add_group "Models", "app/models" add_group "Controllers", "app/controllers" add_group "Long files" do |src_file| src_file.lines.count > 100 end add_group "Multiple Files", ["app/models", "app/controllers"] # You can also pass in an array add_group "Short files", LineFilter.new(5) # Using the LineFilter class defined in Filters section above end ``` ## Merging results You normally want to have your coverage analyzed across ALL of your test suites, right? Simplecov automatically caches coverage results in your (coverage_path)/.resultset.json. 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 as to what the name of the currently running test suite is. You can do so by specifying `SimpleCov.command_name` in one test file that is part of your specific suite. To customize the suite names on a Rails app (yeah, sorry for being Rails-biased, but everyone knows what the structure of those projects is. You can apply this accordingly to the RSpecs in your Outlook-WebDAV-Calendar-Sync gem), you could do something like this: ```ruby # test/unit/some_test.rb SimpleCov.command_name 'test:units' # test/functionals/some_controller_test.rb SimpleCov.command_name "test:functionals" # test/integration/some_integration_test.rb SimpleCov.command_name "test:integration" # features/support/env.rb SimpleCov.command_name "features" ``` Note that this only has to be invoked ONCE PER TEST SUITE, so even if you have 200 unit test files, specifying it in `some_test.rb` is enough. Last but not least **if multiple suites resolve to the same `command_name`** be aware that the coverage results **will clobber each other instead of being merged**. SimpleCov is smart enough to detect unique names for the most common setups, but if you have more than one test suite that doesn't follow a common pattern then you will want to manually ensure that each suite gets a unique `command_name`. If you are running tests in parallel each process has the potential to clobber results from the other test processes. If you are relying on the default `command_name` then SimpleCov will attempt to detect and avoid parallel test suite `command_name` collisions based on the presence of `ENV['PARALLEL_TEST_GROUPS']` and `ENV['TEST_ENV_NUMBER']`. If your parallel test runner does not set one or both of these then *you must* set a `command_name` and ensure that it is unique per process (eg. `command_name "Unit Tests PID #{$$}"`). If you are using parallel_tests, you must incorporate `TEST_ENV_NUMBER` into the command name yourself, in order for SimpleCov to merge the results correctly. For example: ```ruby # spec/spec_helper.rb SimpleCov.command_name "features" + (ENV['TEST_ENV_NUMBER'] || '') ``` [simplecov-html] prints the used test suites in the footer of the generated coverage report. ### 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 (on a ~10 min Rails test suite, the speed drop was only a couple seconds for me), and therefore it's SimpleCov's policy to just generate coverage every time you run your tests because it doesn't do your test speed any harm and you're always equipped with the latest and greatest coverage results. Because of this, SimpleCov has no explicit built-in mechanism to run coverage only on demand. However, you can still accomplish this very easily by introducing an ENV variable conditional into your SimpleCov setup block, like this: ```ruby SimpleCov.start if ENV["COVERAGE"] ``` Then, SimpleCov will only run if you execute your tests like this: ```shell COVERAGE=true rake test ``` ## Profiles By default, SimpleCov's only config assumption is that you only want coverage reports for files inside your project root. To save yourself from repetitive configuration, you can use predefined blocks of configuration, called 'profiles', or define your own. You can then pass the name of the profile to be used as the first argument to SimpleCov.start. For example, simplecov comes bundled with a 'rails' profile. It looks somewhat like this: ```ruby SimpleCov.profiles.define 'rails' do add_filter '/test/' add_filter '/config/' add_group 'Controllers', 'app/controllers' add_group 'Models', 'app/models' add_group 'Helpers', 'app/helpers' add_group 'Libraries', 'lib' end ``` As you can see, it's just a SimpleCov.configure block. In your test_helper.rb, launch SimpleCov with: ```ruby SimpleCov.start 'rails' ``` or ```ruby SimpleCov.start 'rails' do # additional config here end ``` ### Custom profiles You can load additional profiles with the SimpleCov.load_profile('xyz') method. This allows you to build upon an existing profile and customize it so you can reuse it in unit tests and Cucumber features. For example: ```ruby # lib/simplecov_custom_profile.rb require 'simplecov' SimpleCov.profiles.define 'myprofile' do load_profile 'rails' add_filter 'vendor' # Don't include vendored stuff end # features/support/env.rb require 'simplecov_custom_profile' SimpleCov.start 'myprofile' # test/test_helper.rb require 'simplecov_custom_profile' SimpleCov.start 'myprofile' ``` ## Customizing exit behaviour You can define what SimpleCov should do when your test suite finishes by customizing the at_exit hook: ```ruby SimpleCov.at_exit do SimpleCov.result.format! end ``` Above is the default behaviour. Do whatever you like instead! ### Minimum coverage You can define the minimum coverage percentage expected. SimpleCov will return non-zero if unmet. ```ruby SimpleCov.minimum_coverage 90 ``` ### Minimum coverage by file You can define the minimum coverage by file percentage expected. SimpleCov will return non-zero if unmet. This is useful to help ensure coverage is relatively consistent, rather than being skewed by particularly good or bad areas of the code. ```ruby SimpleCov.minimum_coverage_by_file 80 ``` ### Maximum coverage drop You can define the maximum coverage drop percentage at once. SimpleCov will return non-zero if exceeded. ```ruby SimpleCov.maximum_coverage_drop 5 ``` ### Refuse dropping coverage You can also entirely refuse dropping coverage between test runs: ```ruby SimpleCov.refuse_coverage_drop ``` ## Using your own formatter You can use your own formatter with: ```ruby 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 As of SimpleCov 0.9, you can specify multiple result formats: ```ruby SimpleCov.formatters = [ SimpleCov::Formatter::HTMLFormatter, SimpleCov::Formatter::CSVFormatter, ] ``` ## Available formatters, editor integrations and hosted services * [Open Source formatter and integration plugins for SimpleCov](doc/alternate-formatters.md) * [Editor Integration](doc/editor-integration.md) * [Hosted (commercial) services](doc/commercial-services.md) ## Ruby version compatibility Only Ruby 1.9+ ships with the coverage library that SimpleCov depends upon and that's what SimpleCov supports. Additionally JRuby 9.1+ is supported as well, while JRuby 1.7 and 9.0 should work they're not "officially" supported. SimpleCov is also built against Ruby 1.8 in [Continuous Integration], but this happens only to ensure that SimpleCov does not make your test suite crash right now. SimpleCov is built in [Continuous Integration] on Ruby 1.9.3, 2.0.0, 2.1, 2.2, 2.3, 2.4 as well as JRuby 9.1. ## Want to find dead code in production? Try [Coverband](https://github.com/danmayer/coverband). ## Want to use Spring with SimpleCov? If you're using [Spring](https://github.com/rails/spring) to speed up test suite runs and want to run SimpleCov along with them, you'll find that it often misreports coverage with the default config due to some sort of eager loading issue. Don't despair! 1. Change the following settings in `test.rb`. ```ruby # For Rails 4 or earlier, use the following configuration: # Disable Rails's static asset server (Apache or nginx will already do this) config.serve_static_files = false config.eager_load = false # For Rails 5, use the following configuration: # Disable Rails's static asset server (Apache or nginx will already do this) config.public_file_server.enabled = false config.eager_load = false ``` 2. Add your SimpleCov config, as you normally would, to your `spec_helper.rb` (or `rails_helper.rb` for RSpec 3). If you have a `config/spring.rb` file (or anything similar), add it to the start of such file. Here's a simple version of what the config should look like: ```ruby if ENV['RAILS_ENV'] == 'test' require 'simplecov' SimpleCov.start end ``` 3. Run `spring rspec ` as normal. Remember to run `spring stop` after making important changes to your app or its specs! ## 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-2015 Christoph Olszowka. See MIT-LICENSE for details.