Hello community, here is the log from the commit of package rubygem-simplecov for openSUSE:Factory checked in at 2017-08-16 16:18:46 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/rubygem-simplecov (Old) and /work/SRC/openSUSE:Factory/.rubygem-simplecov.new (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "rubygem-simplecov" Wed Aug 16 16:18:46 2017 rev:17 rq:516945 version:0.15.0 Changes: -------- --- /work/SRC/openSUSE:Factory/rubygem-simplecov/rubygem-simplecov.changes 2017-04-12 18:22:43.526730595 +0200 +++ /work/SRC/openSUSE:Factory/.rubygem-simplecov.new/rubygem-simplecov.changes 2017-08-16 16:18:54.541627859 +0200 @@ -1,0 +2,17 @@ +Mon Aug 14 06:38:14 UTC 2017 - [email protected] + +- updated to version 0.15.0 + +## Enhancements + +* Ability to use regex filters for removing files from the output. See [#589](https://github.com/colszowka/simplecov/pull/589) (thanks @jsteel) + +## Bugfixes + +* Fix merging race condition when running tests in parallel and merging them. See [#570](https://github.com/colszowka/simplecov/pull/570) (thanks @jenseng) +* Fix relevant lines for unloaded files - comments, skipped code etc. are correctly classigied as irrelevant. See [#605](https://github.com/colszowka/simplecov/pull/605) (thanks @odlp) +* Allow using simplecov with frozen-string-literals enabled. See [#590](https://github.com/colszowka/simplecov/pull/590) (thanks @pat) +* Make sure Array Filter can use all other filter types. See [#589](https://github.com/colszowka/simplecov/pull/589) (thanks @jsteel) +* Make sure file names use `Simplecov.root` as base avoiding using full absolute project paths. See [#589](https://github.com/colszowka/simplecov/pull/589) (thanks @jsteel) + +------------------------------------------------------------------- Old: ---- simplecov-0.14.1.gem New: ---- simplecov-0.15.0.gem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ rubygem-simplecov.spec ++++++ --- /var/tmp/diff_new_pack.zVycMc/_old 2017-08-16 16:18:55.429503229 +0200 +++ /var/tmp/diff_new_pack.zVycMc/_new 2017-08-16 16:18:55.441501545 +0200 @@ -24,7 +24,7 @@ # Name: rubygem-simplecov -Version: 0.14.1 +Version: 0.15.0 Release: 0 %define mod_name simplecov %define mod_full_name %{mod_name}-%{version} @@ -33,7 +33,7 @@ BuildRequires: %{rubygem gem2rpm} BuildRequires: ruby-macros >= 5 Url: http://github.com/colszowka/simplecov -Source: http://rubygems.org/gems/%{mod_full_name}.gem +Source: https://rubygems.org/gems/%{mod_full_name}.gem Source1: gem2rpm.yml Summary: Code coverage for Ruby 1.9+ with a powerful configuration library License: MIT ++++++ simplecov-0.14.1.gem -> simplecov-0.15.0.gem ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/.rubocop.yml new/.rubocop.yml --- old/.rubocop.yml 2017-03-18 22:34:52.000000000 +0100 +++ new/.rubocop.yml 2017-08-14 07:32:08.000000000 +0200 @@ -3,6 +3,7 @@ - 'spec/fixtures/iso-8859.rb' - 'tmp/**/*' - 'vendor/bundle/**/*' + TargetRubyVersion: 1.9 Bundler/OrderedGems: Enabled: false @@ -35,7 +36,7 @@ Max: 4 CountKeywordArgs: true -Style/AccessModifierIndentation: +Layout/AccessModifierIndentation: EnforcedStyle: outdent Style/CollectionMethods: @@ -54,10 +55,13 @@ Style/HashSyntax: EnforcedStyle: hash_rockets +Layout/IndentHeredoc: + Enabled: false + Style/RegexpLiteral: Enabled: false -Style/SpaceInsideHashLiteralBraces: +Layout/SpaceInsideHashLiteralBraces: EnforcedStyle: no_space Style/SpecialGlobalVars: diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/.travis.yml new/.travis.yml --- old/.travis.yml 2017-03-18 22:34:52.000000000 +0100 +++ new/.travis.yml 2017-08-14 07:32:08.000000000 +0200 @@ -15,12 +15,12 @@ - 1.9.3 - 2.0.0 - 2.1.10 - - 2.2.6 - - 2.3.3 - - 2.4.0 + - 2.2.7 + - 2.3.4 + - 2.4.1 + - jruby-9.1.12.0 - ruby-head - jruby-head - - jruby-9.1.8.0 matrix: allow_failures: diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/CHANGELOG.md new/CHANGELOG.md --- old/CHANGELOG.md 2017-03-18 22:34:52.000000000 +0100 +++ new/CHANGELOG.md 2017-08-14 07:32:08.000000000 +0200 @@ -1,3 +1,18 @@ +0.15.0 (2017-08-14) ([changes](https://github.com/colszowka/simplecov/compare/v0.14.1...v0.15.0)) +======= + +## Enhancements + +* Ability to use regex filters for removing files from the output. See [#589](https://github.com/colszowka/simplecov/pull/589) (thanks @jsteel) + +## Bugfixes + +* Fix merging race condition when running tests in parallel and merging them. See [#570](https://github.com/colszowka/simplecov/pull/570) (thanks @jenseng) +* Fix relevant lines for unloaded files - comments, skipped code etc. are correctly classigied as irrelevant. See [#605](https://github.com/colszowka/simplecov/pull/605) (thanks @odlp) +* Allow using simplecov with frozen-string-literals enabled. See [#590](https://github.com/colszowka/simplecov/pull/590) (thanks @pat) +* Make sure Array Filter can use all other filter types. See [#589](https://github.com/colszowka/simplecov/pull/589) (thanks @jsteel) +* Make sure file names use `Simplecov.root` as base avoiding using full absolute project paths. See [#589](https://github.com/colszowka/simplecov/pull/589) (thanks @jsteel) + 0.14.1 2017-03-18 ([changes](https://github.com/colszowka/simplecov/compare/v0.14.0...v0.14.1)) ======== diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/Gemfile new/Gemfile --- old/Gemfile 2017-03-18 22:34:52.000000000 +0100 +++ new/Gemfile 2017-08-14 07:32:08.000000000 +0200 @@ -23,13 +23,13 @@ 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 "aruba", "~> 0.14" 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 "rubocop", "0.49.1" unless RUBY_VERSION.start_with?("1.") gem "test-unit" end gem "json", RUBY_VERSION.start_with?("1.") ? "~> 1.8" : "~> 2.0" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/MIT-LICENSE new/MIT-LICENSE --- old/MIT-LICENSE 2017-03-18 22:34:52.000000000 +0100 +++ new/MIT-LICENSE 2017-08-14 07:32:08.000000000 +0200 @@ -1,4 +1,4 @@ -Copyright (c) 2010-2015 Christoph Olszowka +Copyright (c) 2010-2017 Christoph Olszowka Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/README.md new/README.md --- old/README.md 2017-03-18 22:34:52.000000000 +0100 +++ new/README.md 2017-08-14 07:32:08.000000000 +0200 @@ -40,7 +40,7 @@ *Questions, Problems, Suggestions, etc.* -* [Mailing List]: https://groups.google.com/forum/#!forum/simplecov "Open mailing list for discussion and announcements on Google Groups" +* [Mailing List](https://groups.google.com/forum/#!forum/simplecov) "Open mailing list for discussion and announcements on Google Groups" Getting started --------------- @@ -135,6 +135,17 @@ <tr><th>Framework</th><th>Notes</th><th>Issue</th></tr> <tr> <th> + bootsnap + </th> + <td> + <a href="#want-to-use-bootsnap-with-simplecov">See section below.</a> + </td> + <td> + <a href="https://github.com/Shopify/bootsnap/issues/35">Shopify/bootsnap#35</a> + </td> + </tr> + <tr> + <th> parallel_tests </th> <td> @@ -262,7 +273,7 @@ ### 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), +You can currently define a filter using either a String or Regexp (that will then be Regexp-matched against each source file's path), a block or by passing in your own Filter class. #### String filter @@ -275,6 +286,16 @@ This simple string filter will remove all files that match "/test/" in their path. +#### Regex filter + +```ruby +SimpleCov.start do + add_filter %r{^/test/} +end +``` + +This simple regex filter will remove all files that start with /test/ in their path. + #### Block filter ```ruby @@ -305,6 +326,17 @@ the filter, a true return value from this method will result in the removal of the given source_file. The filter_argument method is being set in the SimpleCov::Filter initialize method and thus is set to 5 in this example. +#### Array filter + +```ruby +SimpleCov.start do + proc = Proc.new { |source_file| false } + add_filter ["string", /regex/, proc, LineFilter.new(5)] +end +``` + +You can pass in an array containing any of the other filter types. + #### Ignoring/skipping code You can exclude code from the coverage report by wrapping it in `# :nocov:`. @@ -570,10 +602,10 @@ As of SimpleCov 0.9, you can specify multiple result formats: ```ruby -SimpleCov.formatters = [ +SimpleCov.formatters = SimpleCov::Formatter::MultiFormatter.new([ SimpleCov::Formatter::HTMLFormatter, SimpleCov::Formatter::CSVFormatter, -] +]) ``` ## Available formatters, editor integrations and hosted services @@ -624,6 +656,20 @@ ``` 3. Run `spring rspec <path>` as normal. Remember to run `spring stop` after making important changes to your app or its specs! + +## Want to use bootsnap with SimpleCov? + +As mentioned in [this issue](https://github.com/Shopify/bootsnap/issues/35) iseq +loading/dumping doesn't work with coverage. Hence you need to deactivate it when +you run coverage so for instance when you use the environment `COVERAGE=true` to +decide that you want to gather coverage you can do: + +```ruby +Bootsnap.setup( + compile_cache_iseq: !ENV["COVERAGE"], # Compile Ruby code into ISeq cache, breaks coverage reporting. + # all those other options +) +``` ## Contributing @@ -635,4 +681,4 @@ ## Copyright -Copyright (c) 2010-2015 Christoph Olszowka. See MIT-LICENSE for details. +Copyright (c) 2010-2017 Christoph Olszowka. See MIT-LICENSE for details. Binary files old/checksums.yaml.gz and new/checksums.yaml.gz differ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/doc/editor-integration.md new/doc/editor-integration.md --- old/doc/editor-integration.md 2017-03-18 22:34:52.000000000 +0100 +++ new/doc/editor-integration.md 2017-08-14 07:32:08.000000000 +0200 @@ -7,7 +7,12 @@ Adds an overview of your current test coverage to Atom. +#### [Sublime Editor: SimpleCov](https://packagecontrol.io/packages/SimpleCov) +*by sentience* + +Adds in editor live coverage highlighting, status bar coverage information, and summary coverage information. + #### [cadre](https://github.com/nyarly/cadre) *by Judson Lester* -Includes a formatter for Simplecov that emits a Vim script to mark up code files with coverage information. \ No newline at end of file +Includes a formatter for Simplecov that emits a Vim script to mark up code files with coverage information. diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/features/config_tracked_files.feature new/features/config_tracked_files.feature --- old/features/config_tracked_files.feature 2017-03-18 22:34:52.000000000 +0100 +++ new/features/config_tracked_files.feature 2017-08-14 07:32:08.000000000 +0200 @@ -16,7 +16,7 @@ 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 | + | All Files | 77.94% | 7 | And I should see the source files: | name | coverage | diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/features/config_tracked_files_relevant_lines.feature new/features/config_tracked_files_relevant_lines.feature --- old/features/config_tracked_files_relevant_lines.feature 1970-01-01 01:00:00.000000000 +0100 +++ new/features/config_tracked_files_relevant_lines.feature 2017-08-14 07:32:08.000000000 +0200 @@ -0,0 +1,31 @@ +@rspec +Feature: + + Using the setting `tracked_files` should classify whether lines + are relevant or not (such as whitespace or comments). + + Scenario: + Given SimpleCov for RSpec is configured with: + """ + require 'simplecov' + SimpleCov.start do + track_files "lib/**/*.rb" + end + """ + Given a file named "lib/not_loaded.rb" with: + """ + # A comment line. Plus a whitespace line below: + + # :nocov: + def ignore_me + end + # :nocov: + + def this_is_relevant + puts "still relevant" + end + """ + + When I open the coverage report generated with `bundle exec rspec spec` + Then I follow "lib/not_loaded.rb" + Then I should see "3 relevant lines" within ".highlighted" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/features/step_definitions/transformers.rb new/features/step_definitions/transformers.rb --- old/features/step_definitions/transformers.rb 2017-03-18 22:34:52.000000000 +0100 +++ new/features/step_definitions/transformers.rb 2017-08-14 07:32:08.000000000 +0200 @@ -8,6 +8,6 @@ # Transform "bundle exec rspec spec" do |_| files = nil # Avoid shadowing - in_current_directory { files = Dir["spec/**/*_spec.rb"] } + cd(".") { files = Dir["spec/**/*_spec.rb"] } "bundle exec rspec #{files.sort.join(' ')}" end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/features/support/aruba_freedom_patch.rb new/features/support/aruba_freedom_patch.rb --- old/features/support/aruba_freedom_patch.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/features/support/aruba_freedom_patch.rb 2017-08-14 07:32:08.000000000 +0200 @@ -0,0 +1,53 @@ +# Freedom patch because of not working absolute directories, see: https://github.com/cucumber/aruba/issues/478 +# code taken directly from aruba 0.14.2 - roughly here: https://github.com/cucumber/aruba/blob/master/lib/aruba/api/core.rb#L122-L159 +# rubocop:disable all +module Aruba + module Api + module Core + def expand_path(file_name, dir_string = nil) + # only line added, don't ask why but I couldn't get alias_method to work... + return file_name if absolute?(file_name) + check_for_deprecated_variables if Aruba::VERSION < '1' + + message = %(Filename "#{file_name}" needs to be a string. It cannot be nil or empty either. Please use `expand_path('.')` if you want the current directory to be expanded.) + + fail ArgumentError, message unless file_name.is_a?(String) && !file_name.empty? + + aruba.logger.warn %(`aruba`'s working directory does not exist. Maybe you forgot to run `setup_aruba` before using it's API. This warning will be an error from 1.0.0) unless Aruba.platform.directory? File.join(aruba.config.root_directory, aruba.config.working_directory) + + if RUBY_VERSION < '1.9' + prefix = file_name.chars.to_a[0].to_s + rest = if file_name.chars.to_a[2..-1].nil? + nil + else + file_name.chars.to_a[2..-1].join + end + else + prefix = file_name[0] + rest = file_name[2..-1] + end + + if aruba.config.fixtures_path_prefix == prefix + path = File.join(*[aruba.fixtures_directory, rest].compact) + + fail ArgumentError, %(Fixture "#{rest}" does not exist in fixtures directory "#{aruba.fixtures_directory}". This was the one we found first on your system from all possible candidates: #{aruba.config.fixtures_directories.map { |p| format('"%s"', p) }.join(', ')}.) unless Aruba.platform.exist? path + + path + elsif '~' == prefix + path = with_environment do + ArubaPath.new(File.expand_path(file_name)) + end + + fail ArgumentError, 'Expanding "~/" to "/" is not allowed' if path.to_s == '/' + fail ArgumentError, %(Expanding "~/" to a relative path "#{path}" is not allowed) unless path.absolute? + + path.to_s + else + directory = File.join(aruba.root_directory, aruba.current_directory) + ArubaPath.new(File.join(*[directory, dir_string, file_name].compact)).expand_path.to_s + end + end + end + end +end +# rubocop:enable all diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/features/support/env.rb new/features/support/env.rb --- old/features/support/env.rb 2017-03-18 22:34:52.000000000 +0100 +++ new/features/support/env.rb 2017-08-14 07:32:08.000000000 +0200 @@ -6,7 +6,8 @@ require "bundler" Bundler.setup require "aruba/cucumber" -require "aruba/jruby" if RUBY_ENGINE == "jruby" +require "aruba/config/jruby" if RUBY_ENGINE == "jruby" +require_relative "aruba_freedom_patch" require "capybara/cucumber" require "phantomjs/poltergeist" @@ -34,7 +35,7 @@ this_dir = File.dirname(__FILE__) # Clean up and create blank state for fake project - in_current_directory do + cd(".") do FileUtils.rm_rf "project" FileUtils.cp_r File.join(this_dir, "../../spec/faked_project/"), "project" end @@ -44,7 +45,6 @@ # Workaround for https://github.com/cucumber/aruba/pull/125 Aruba.configure do |config| - config.before_cmd do - set_env("JRUBY_OPTS", "--dev --debug") - end + config.exit_timeout = RUBY_ENGINE == "jruby" ? 60 : 20 + config.command_runtime_environment = {"JRUBY_OPTS" => "--dev --debug"} end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/simplecov/configuration.rb new/lib/simplecov/configuration.rb --- old/lib/simplecov/configuration.rb 2017-03-18 22:34:52.000000000 +0100 +++ new/lib/simplecov/configuration.rb 2017-08-14 07:32:08.000000000 +0200 @@ -291,16 +291,12 @@ # 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) + filter = filter_argument || filter_proc + + if filter + SimpleCov::Filter.build_filter(filter) else - raise ArgumentError, "Please specify either a string or a block to filter with" + raise ArgumentError, "Please specify either a filter or a block to filter with" end end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/simplecov/defaults.rb new/lib/simplecov/defaults.rb --- old/lib/simplecov/defaults.rb 2017-03-18 22:34:52.000000000 +0100 +++ new/lib/simplecov/defaults.rb 2017-08-14 07:32:08.000000000 +0200 @@ -7,7 +7,7 @@ root_filter = nil add_filter do |src| root_filter ||= /\A#{Regexp.escape(SimpleCov.root)}/io - !(src.filename =~ root_filter) + src.filename !~ root_filter end end @@ -25,15 +25,15 @@ SimpleCov.profiles.define "rails" do load_profile "test_frameworks" - add_filter "/config/" - add_filter "/db/" + add_filter %r{^/config/} + add_filter %r{/^/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 "Jobs", %w[app/jobs app/workers] add_group "Libraries", "lib" track_files "{app,lib}/**/*.rb" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/simplecov/file_list.rb new/lib/simplecov/file_list.rb --- old/lib/simplecov/file_list.rb 2017-03-18 22:34:52.000000000 +0100 +++ new/lib/simplecov/file_list.rb 2017-08-14 07:32:08.000000000 +0200 @@ -5,25 +5,25 @@ # Returns the count of lines that have coverage def covered_lines return 0.0 if empty? - map { |f| f.covered_lines.count }.inject(&:+) + 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(&:+) + 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(&:+) + 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(&:+) + map { |f| f.skipped_lines.count }.inject(:+) end # Computes the coverage based upon lines covered and lines missed for each file @@ -53,7 +53,7 @@ # @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) + Float(map { |f| f.covered_strength * f.lines_of_code }.inject(:+) / lines_of_code) end end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/simplecov/filter.rb new/lib/simplecov/filter.rb --- old/lib/simplecov/filter.rb 2017-03-18 22:34:52.000000000 +0100 +++ new/lib/simplecov/filter.rb 2017-08-14 07:32:08.000000000 +0200 @@ -24,13 +24,40 @@ warn "#{Kernel.caller.first}: [DEPRECATION] #passes? is deprecated. Use #matches? instead." matches?(source_file) end + + def self.build_filter(filter_argument) + return filter_argument if filter_argument.is_a?(SimpleCov::Filter) + class_for_argument(filter_argument).new(filter_argument) + end + + def self.class_for_argument(filter_argument) + if filter_argument.is_a?(String) + SimpleCov::StringFilter + elsif filter_argument.is_a?(Regexp) + SimpleCov::RegexFilter + elsif filter_argument.is_a?(Array) + SimpleCov::ArrayFilter + elsif filter_argument.is_a?(Proc) + SimpleCov::BlockFilter + else + raise ArgumentError, "You have provided an unrecognized filter type" + end + end end class StringFilter < SimpleCov::Filter # Returns true when the given source file's filename matches the # string configured when initializing this Filter with StringFilter.new('somestring) def matches?(source_file) - (source_file.filename =~ /#{filter_argument}/) + (source_file.project_filename =~ /#{filter_argument}/) + end + end + + class RegexFilter < SimpleCov::Filter + # Returns true when the given source file's filename matches the + # regex configured when initializing this Filter with RegexFilter.new(/someregex/) + def matches?(source_file) + (source_file.project_filename =~ filter_argument) end end @@ -43,11 +70,19 @@ 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 initialize(filter_argument) + filter_objects = filter_argument.map do |arg| + Filter.build_filter(arg) + end + + super(filter_objects) + end + + # Returns true if any of the filters in the array match the given source file. + # Configure this Filter like StringFilter.new(['some/path', /^some_regex/, Proc.new {|src_file| ... }]) def matches?(source_files_list) filter_argument.any? do |arg| - source_files_list.filename =~ /#{arg}/ + arg.matches?(source_files_list) end end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/simplecov/formatter/simple_formatter.rb new/lib/simplecov/formatter/simple_formatter.rb --- old/lib/simplecov/formatter/simple_formatter.rb 2017-03-18 22:34:52.000000000 +0100 +++ new/lib/simplecov/formatter/simple_formatter.rb 2017-08-14 07:32:08.000000000 +0200 @@ -6,7 +6,7 @@ class SimpleFormatter # Takes a SimpleCov::Result and generates a string out of it def format(result) - output = "" + output = "".dup result.groups.each do |name, files| output << "Group: #{name}\n" output << "=" * 40 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/simplecov/lines_classifier.rb new/lib/simplecov/lines_classifier.rb --- old/lib/simplecov/lines_classifier.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/lib/simplecov/lines_classifier.rb 2017-08-14 07:32:08.000000000 +0200 @@ -0,0 +1,32 @@ +module SimpleCov + # Classifies whether lines are relevant for code coverage analysis. + # Comments & whitespace lines, and :nocov: token blocks, are considered not relevant. + + class LinesClassifier + RELEVANT = 0 + NOT_RELEVANT = nil + + WHITESPACE_LINE = /^\s*$/ + COMMENT_LINE = /^\s*#/ + WHITESPACE_OR_COMMENT_LINE = Regexp.union(WHITESPACE_LINE, COMMENT_LINE) + + def self.no_cov_line + /^(\s*)#(\s*)(\:#{SimpleCov.nocov_token}\:)/ + end + + def classify(lines) + skipping = false + + lines.map do |line| + if line =~ self.class.no_cov_line + skipping = !skipping + NOT_RELEVANT + elsif skipping || line =~ WHITESPACE_OR_COMMENT_LINE + NOT_RELEVANT + else + RELEVANT + end + end + end + end +end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/simplecov/result_merger.rb new/lib/simplecov/result_merger.rb --- old/lib/simplecov/result_merger.rb 2017-03-18 22:34:52.000000000 +0100 +++ new/lib/simplecov/result_merger.rb 2017-08-14 07:32:08.000000000 +0200 @@ -17,25 +17,31 @@ File.join(SimpleCov.coverage_path, ".resultset.json.lock") end - # Loads the cached resultset from JSON and returns it as a Hash + # Loads the cached resultset from JSON and returns it as a Hash, + # caching it for subsequent accesses. def resultset - if stored_data - begin - JSON.parse(stored_data) - rescue + @resultset ||= begin + data = stored_data + if data + begin + JSON.parse(data) || {} + rescue + {} + end + else {} 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 + synchronize_resultset do + return unless File.exist?(resultset_path) + data = File.read(resultset_path) + return if data.nil? || data.length < 2 + data + end end # Gets the resultset hash and re-creates all included instances @@ -76,8 +82,9 @@ # 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) + synchronize_resultset do + # Ensure we have the latest, in case it was already cached + clear_resultset new_set = resultset command_name, data = result.to_hash.first new_set[command_name] = data @@ -87,6 +94,28 @@ end true end + + # Ensure only one process is reading or writing the resultset at any + # given time + def synchronize_resultset + # make it reentrant + return yield if defined?(@resultset_locked) && @resultset_locked + + begin + @resultset_locked = true + File.open(resultset_writelock, "w+") do |f| + f.flock(File::LOCK_EX) + yield + end + ensure + @resultset_locked = false + end + end + + # Clear out the previously cached .resultset + def clear_resultset + @resultset = nil + end end end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/simplecov/source_file.rb new/lib/simplecov/source_file.rb --- old/lib/simplecov/source_file.rb 2017-03-18 22:34:52.000000000 +0100 +++ new/lib/simplecov/source_file.rb 2017-08-14 07:32:08.000000000 +0200 @@ -80,6 +80,11 @@ @coverage = coverage end + # The path to this source file relative to the projects directory + def project_filename + @filename.sub(/^#{SimpleCov.root}/, "") + end + # The source code for this file. Aliased as :source def src # We intentionally read source code lazily to @@ -175,7 +180,7 @@ skipping = false lines.each do |line| - if line.src =~ /^([\s]*)#([\s]*)(\:#{SimpleCov.nocov_token}\:)/ + if line.src =~ SimpleCov::LinesClassifier.no_cov_line skipping = !skipping line.skipped! elsif skipping diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/simplecov/version.rb new/lib/simplecov/version.rb --- old/lib/simplecov/version.rb 2017-03-18 22:34:52.000000000 +0100 +++ new/lib/simplecov/version.rb 2017-08-14 07:32:08.000000000 +0200 @@ -1,25 +1,3 @@ module 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 + VERSION = "0.15.0".freeze end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/simplecov.rb new/lib/simplecov.rb --- old/lib/simplecov.rb 2017-03-18 22:34:52.000000000 +0100 +++ new/lib/simplecov.rb 2017-08-14 07:32:08.000000000 +0200 @@ -55,7 +55,7 @@ # # Finds files that were to be tracked but were not loaded and initializes - # their coverage to zero. + # the line-by-line coverage to zero (if relevant) or nil (comments / whitespace etc). # def add_not_loaded_files(result) if tracked_files @@ -63,7 +63,7 @@ Dir[tracked_files].each do |file| absolute = File.expand_path(file) - result[absolute] ||= [0] * File.foreach(absolute).count + result[absolute] ||= LinesClassifier.new.classify(File.foreach(absolute)) end end @@ -75,23 +75,21 @@ # 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) + return @result if result? # Collect our coverage result - if running && !result? + if running @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 + # first (if there is one), then merge the results and return those if use_merging SimpleCov::ResultMerger.store_result(@result) if result? - - SimpleCov::ResultMerger.merged_result - else - @result + @result = SimpleCov::ResultMerger.merged_result end + + @result ensure self.running = false end @@ -158,6 +156,13 @@ false end end + + # + # Clear out the previously cached .result. Primarily useful in testing + # + def clear_result + @result = nil + end end end @@ -172,6 +177,7 @@ require "simplecov/filter" require "simplecov/formatter" require "simplecov/last_run" +require "simplecov/lines_classifier" require "simplecov/raw_coverage" require "simplecov/result_merger" require "simplecov/command_guesser" diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/metadata new/metadata --- old/metadata 2017-03-18 22:34:52.000000000 +0100 +++ new/metadata 2017-08-14 07:32:08.000000000 +0200 @@ -1,17 +1,16 @@ --- !ruby/object:Gem::Specification name: simplecov version: !ruby/object:Gem::Version - version: 0.14.1 + version: 0.15.0 platform: ruby authors: - Christoph Olszowka -autorequire: +autorequire: bindir: bin cert_chain: [] -date: 2017-03-18 00:00:00.000000000 Z +date: 2017-08-14 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency - name: json requirement: !ruby/object:Gem::Requirement requirements: - - ">=" @@ -20,8 +19,9 @@ - - "<" - !ruby/object:Gem::Version version: '3' - type: :runtime + name: json prerelease: false + type: :runtime version_requirements: !ruby/object:Gem::Requirement requirements: - - ">=" @@ -31,42 +31,42 @@ - !ruby/object:Gem::Version version: '3' - !ruby/object:Gem::Dependency - name: simplecov-html requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: 0.10.0 - type: :runtime + name: simplecov-html prerelease: false + type: :runtime version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: 0.10.0 - !ruby/object:Gem::Dependency - name: docile requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: 1.1.0 - type: :runtime + name: docile prerelease: false + type: :runtime version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: 1.1.0 - !ruby/object:Gem::Dependency - name: bundler requirement: !ruby/object:Gem::Requirement requirements: - - "~>" - !ruby/object:Gem::Version version: '1.9' - type: :development + name: bundler prerelease: false + type: :development version_requirements: !ruby/object:Gem::Requirement requirements: - - "~>" @@ -106,6 +106,7 @@ - features/config_project_name.feature - features/config_styles.feature - features/config_tracked_files.feature +- features/config_tracked_files_relevant_lines.feature - features/cucumber_basic.feature - features/maximum_coverage_drop.feature - features/merging_test_unit_and_rspec.feature @@ -122,6 +123,7 @@ - features/step_definitions/simplecov_steps.rb - features/step_definitions/transformers.rb - features/step_definitions/web_steps.rb +- features/support/aruba_freedom_patch.rb - features/support/env.rb - features/test_unit_basic.feature - features/test_unit_groups_and_filters_basic.feature @@ -141,6 +143,7 @@ - lib/simplecov/formatter/simple_formatter.rb - lib/simplecov/jruby_fix.rb - lib/simplecov/last_run.rb +- lib/simplecov/lines_classifier.rb - lib/simplecov/load_global_config.rb - lib/simplecov/no_defaults.rb - lib/simplecov/profiles.rb @@ -196,11 +199,13 @@ - spec/fixtures/utf-8.rb - spec/helper.rb - spec/last_run_spec.rb +- spec/lines_classifier_spec.rb - spec/multi_formatter_spec.rb - spec/raw_coverage_spec.rb - spec/result_merger_spec.rb - spec/result_spec.rb - spec/return_codes_spec.rb +- spec/simplecov_spec.rb - spec/source_file_line_spec.rb - spec/source_file_spec.rb - spec/support/fail_rspec_on_ruby_warning.rb @@ -208,7 +213,7 @@ licenses: - MIT metadata: {} -post_install_message: +post_install_message: rdoc_options: [] require_paths: - lib @@ -223,9 +228,9 @@ - !ruby/object:Gem::Version version: '0' requirements: [] -rubyforge_project: -rubygems_version: 2.6.10 -signing_key: +rubyforge_project: +rubygems_version: 2.6.11 +signing_key: specification_version: 4 summary: Code coverage for Ruby 1.9+ with a powerful configuration library and automatic merging of coverage across test suites diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/spec/filters_spec.rb new/spec/filters_spec.rb --- old/spec/filters_spec.rb 2017-03-18 22:34:52.000000000 +0100 +++ new/spec/filters_spec.rb 2017-08-14 07:32:08.000000000 +0200 @@ -26,6 +26,27 @@ expect(SimpleCov::StringFilter.new("sample.rb")).to be_matches subject end + it "doesn't match a parent directory with a new SimpleCov::StringFilter" do + parent_dir_name = File.basename(File.expand_path("..", File.dirname(__FILE__))) + expect(SimpleCov::StringFilter.new(parent_dir_name)).not_to be_matches subject + end + + it "matches a new SimpleCov::StringFilter '/fixtures/'" do + expect(SimpleCov::StringFilter.new("sample.rb")).to be_matches subject + end + + it "matches a new SimpleCov::RegexFilter /\/fixtures\//" do + expect(SimpleCov::RegexFilter.new(/\/fixtures\//)).to be_matches subject + end + + it "doesn't match a new SimpleCov::RegexFilter /^\/fixtures\//" do + expect(SimpleCov::RegexFilter.new(/^\/fixtures\//)).not_to be_matches subject + end + + it "matches a new SimpleCov::RegexFilter /^\/spec\//" do + expect(SimpleCov::RegexFilter.new(/^\/spec\//)).to be_matches subject + end + it "doesn't match a new SimpleCov::BlockFilter that is not applicable" do expect(SimpleCov::BlockFilter.new(proc { |s| File.basename(s.filename) == "foo.rb" })).not_to be_matches subject end @@ -46,6 +67,45 @@ expect(SimpleCov::ArrayFilter.new(["sample.rb", "other_file.rb"])).to be_matches subject end + it "doesn't match a parent directory with a new SimpleCov::ArrayFilter" do + parent_dir_name = File.basename(File.expand_path("..", File.dirname(__FILE__))) + expect(SimpleCov::ArrayFilter.new([parent_dir_name])).not_to be_matches subject + end + + it "matches a new SimpleCov::ArrayFilter when /sample.rb/ is passed as array" do + expect(SimpleCov::ArrayFilter.new([/sample.rb/])).to be_matches subject + end + + it "doesn't match a new SimpleCov::ArrayFilter when a file path different than /sample.rb/ is passed as array" do + expect(SimpleCov::ArrayFilter.new([/other_file.rb/])).not_to be_matches subject + end + + it "matches a new SimpleCov::ArrayFilter when a block is passed as array and returns true" do + expect(SimpleCov::ArrayFilter.new([proc { true }])).to be_matches subject + end + + it "doesn't match a new SimpleCov::ArrayFilter when a block that returns false is passed as array" do + expect(SimpleCov::ArrayFilter.new([proc { false }])).not_to be_matches subject + end + + it "matches a new SimpleCov::ArrayFilter when a custom class that returns true is passed as array" do + filter = Class.new(SimpleCov::Filter) do + def matches?(_) + true + end + end.new(nil) + expect(SimpleCov::ArrayFilter.new([filter])).to be_matches subject + end + + it "doesn't match a new SimpleCov::ArrayFilter when a custom class that returns false is passed as array" do + filter = Class.new(SimpleCov::Filter) do + def matches?(_) + false + end + end.new(nil) + expect(SimpleCov::ArrayFilter.new([filter])).not_to be_matches subject + end + context "with no filters set up and a basic source file in an array" do before do @prev_filters = SimpleCov.filters @@ -94,5 +154,19 @@ expect(SimpleCov.filtered(subject)).to be_a SimpleCov::FileList end end + + describe ".class_for_argument" do + it "returns SimpleCov::StringFilter for a string" do + expect(SimpleCov::Filter.class_for_argument("filestring")).to eq(SimpleCov::StringFilter) + end + + it "returns SimpleCov::RegexFilter for a string" do + expect(SimpleCov::Filter.class_for_argument(/regex/)).to eq(SimpleCov::RegexFilter) + end + + it "returns SimpleCov::RegexFilter for a string" do + expect(SimpleCov::Filter.class_for_argument(%w[file1 file2])).to eq(SimpleCov::ArrayFilter) + end + end end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/spec/lines_classifier_spec.rb new/spec/lines_classifier_spec.rb --- old/spec/lines_classifier_spec.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/spec/lines_classifier_spec.rb 2017-08-14 07:32:08.000000000 +0200 @@ -0,0 +1,103 @@ +require "helper" +require "simplecov/lines_classifier" + +describe SimpleCov::LinesClassifier do + describe "#classify" do + describe "relevant lines" do + it "determines code as relevant" do + classified_lines = subject.classify [ + "module Foo", + " class Baz", + " def Bar", + " puts 'hi'", + " end", + " end", + "end", + ] + + expect(classified_lines.length).to eq 7 + expect(classified_lines).to all be_relevant + end + end + + describe "not-relevant lines" do + it "determines whitespace is not-relevant" do + classified_lines = subject.classify [ + "", + " ", + "\t\t", + ] + + expect(classified_lines.length).to eq 3 + expect(classified_lines).to all be_irrelevant + end + + describe "comments" do + it "determines comments are not-relevant" do + classified_lines = subject.classify [ + "#Comment", + " # Leading space comment", + "\t# Leading tab comment", + ] + + expect(classified_lines.length).to eq 3 + expect(classified_lines).to all be_irrelevant + end + + it "doesn't mistake interpolation as a comment" do + classified_lines = subject.classify [ + 'puts "#{var}"', + ] + + expect(classified_lines.length).to eq 1 + expect(classified_lines).to all be_relevant + end + end + + describe ":nocov: blocks" do + it "determines :nocov: blocks are not-relevant" do + classified_lines = subject.classify [ + "# :nocov:", + "def hi", + "end", + "# :nocov:", + ] + + expect(classified_lines.length).to eq 4 + expect(classified_lines).to all be_irrelevant + end + + it "determines all lines after a non-closing :nocov: as not-relevant" do + classified_lines = subject.classify [ + "# :nocov:", + "puts 'Not relevant'", + "# :nocov:", + "puts 'Relevant again'", + "puts 'Still relevant'", + "# :nocov:", + "puts 'Not relevant till the end'", + "puts 'Ditto'", + ] + + expect(classified_lines.length).to eq 8 + + expect(classified_lines[0..2]).to all be_irrelevant + expect(classified_lines[3..4]).to all be_relevant + expect(classified_lines[5..7]).to all be_irrelevant + end + end + end + end + + RSpec::Matchers.define :be_relevant do + match do |actual| + actual == SimpleCov::LinesClassifier::RELEVANT + end + end + + RSpec::Matchers.define :be_irrelevant do + match do |actual| + actual == SimpleCov::LinesClassifier::NOT_RELEVANT + end + end +end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/spec/result_merger_spec.rb new/spec/result_merger_spec.rb --- old/spec/result_merger_spec.rb 2017-03-18 22:34:52.000000000 +0100 +++ new/spec/result_merger_spec.rb 2017-08-14 07:32:08.000000000 +0200 @@ -1,10 +1,16 @@ require "helper" +require "tempfile" +require "timeout" if SimpleCov.usable? describe SimpleCov::ResultMerger do + before do + SimpleCov::ResultMerger.clear_resultset + File.delete(SimpleCov::ResultMerger.resultset_path) if File.exist?(SimpleCov::ResultMerger.resultset_path) + end + 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], @@ -56,7 +62,7 @@ end it "returns a hash containing keys ['result1' and 'result2'] for resultset" do - expect(SimpleCov::ResultMerger.resultset.keys.sort).to eq %w(result1 result2) + expect(SimpleCov::ResultMerger.resultset.keys.sort).to eq %w[result1 result2] end it "returns proper values for merged_result" do @@ -73,15 +79,92 @@ expect(SimpleCov::ResultMerger.results.length).to eq(1) end end + end + end + end - context "with merging disabled" do - before { SimpleCov.use_merging false } + describe ".store_result" do + it "refreshes the resultset" do + set = SimpleCov::ResultMerger.resultset + SimpleCov::ResultMerger.store_result({}) + new_set = SimpleCov::ResultMerger.resultset + expect(new_set).not_to be(set) + end + + it "persists to disk" do + SimpleCov::ResultMerger.store_result("a" => [1]) + SimpleCov::ResultMerger.clear_resultset + new_set = SimpleCov::ResultMerger.resultset + expect(new_set).to eq("a" => [1]) + end + + it "synchronizes writes" do + expect(SimpleCov::ResultMerger).to receive(:synchronize_resultset) + SimpleCov::ResultMerger.store_result({}) + end + end - it "returns nil for SimpleCov.result" do - expect(SimpleCov.result).to be_nil + describe ".resultset" do + it "caches" do + set = SimpleCov::ResultMerger.resultset + new_set = SimpleCov::ResultMerger.resultset + expect(new_set).to be(set) + end + + it "synchronizes reads" do + expect(SimpleCov::ResultMerger).to receive(:synchronize_resultset) + SimpleCov::ResultMerger.resultset + end + end + + describe ".synchronize_resultset" do + it "is reentrant (i.e. doesn't block its own process)" do + # without @resultset_locked, this spec would fail and + # `.store_result` wouldn't work + expect do + Timeout.timeout(1) do + SimpleCov::ResultMerger.synchronize_resultset do + SimpleCov::ResultMerger.synchronize_resultset do + end end end + end.not_to raise_error + end + + it "blocks other processes" do + file = Tempfile.new("foo") + + other_process = open("|ruby -e " + Shellwords.escape(<<-CODE) + " 2>/dev/null") + require "simplecov" + SimpleCov.coverage_dir(#{SimpleCov.coverage_dir.inspect}) + + # ensure the parent process has enough time to get a + # lock before we do + sleep 0.5 + + $stdout.sync = true + puts "running" # see `sleep`s in parent process + + SimpleCov::ResultMerger.synchronize_resultset do + File.open(#{file.path.inspect}, "a") { |f| f.write("process 2\n") } + end + CODE + + SimpleCov::ResultMerger.synchronize_resultset do + # wait until the child process is going, and then wait some more + # so we can be sure it blocks on the lock we already have. + sleep 0.1 until other_process.gets == "running\n" + sleep 1 + + # despite the sleeps, this will be written first since we got + # the first lock + File.open(file.path, "a") { |f| f.write("process 1\n") } end + + # wait for it to finish + other_process.gets + + expect(file.read).to eq("process 1\nprocess 2\n") end end end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/spec/simplecov_spec.rb new/spec/simplecov_spec.rb --- old/spec/simplecov_spec.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/spec/simplecov_spec.rb 2017-08-14 07:32:08.000000000 +0200 @@ -0,0 +1,109 @@ +require "helper" + +if SimpleCov.usable? + describe SimpleCov do + describe ".result" do + before do + SimpleCov.clear_result + allow(Coverage).to receive(:result).once.and_return({}) + end + + context "with merging disabled" do + before do + allow(SimpleCov).to receive(:use_merging).once.and_return(false) + end + + context "when not running" do + before do + allow(SimpleCov).to receive(:running).and_return(false) + end + + it "returns nil" do + expect(SimpleCov.result).to be_nil + end + end + + context "when running" do + before do + allow(SimpleCov).to receive(:running).and_return(true, false) + end + + it "uses the result from Coverage" do + expect(Coverage).to receive(:result).once.and_return(__FILE__ => [0, 1]) + expect(SimpleCov.result.filenames).to eq [__FILE__] + end + + it "adds not-loaded-files" do + expect(SimpleCov).to receive(:add_not_loaded_files).once.and_return({}) + SimpleCov.result + end + + it "doesn't store the current coverage" do + expect(SimpleCov::ResultMerger).not_to receive(:store_result) + SimpleCov.result + end + + it "doesn't merge the result" do + expect(SimpleCov::ResultMerger).not_to receive(:merged_result) + SimpleCov.result + end + + it "caches its result" do + result = SimpleCov.result + expect(SimpleCov.result).to be(result) + end + end + end + + context "with merging enabled" do + let(:the_merged_result) { double } + + before do + allow(SimpleCov).to receive(:use_merging).once.and_return(true) + allow(SimpleCov::ResultMerger).to receive(:store_result).once + allow(SimpleCov::ResultMerger).to receive(:merged_result).once.and_return(the_merged_result) + end + + context "when not running" do + before do + allow(SimpleCov).to receive(:running).and_return(false) + end + + it "merges the result" do + expect(SimpleCov.result).to be(the_merged_result) + end + end + + context "when running" do + before do + allow(SimpleCov).to receive(:running).and_return(true, false) + end + + it "uses the result from Coverage" do + expect(Coverage).to receive(:result).once.and_return({}) + SimpleCov.result + end + + it "adds not-loaded-files" do + expect(SimpleCov).to receive(:add_not_loaded_files).once.and_return({}) + SimpleCov.result + end + + it "stores the current coverage" do + expect(SimpleCov::ResultMerger).to receive(:store_result).once + SimpleCov.result + end + + it "merges the result" do + expect(SimpleCov.result).to be(the_merged_result) + end + + it "caches its result" do + result = SimpleCov.result + expect(SimpleCov.result).to be(result) + end + end + end + end + end +end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/spec/source_file_spec.rb new/spec/source_file_spec.rb --- old/spec/source_file_spec.rb 2017-03-18 22:34:52.000000000 +0100 +++ new/spec/source_file_spec.rb 2017-08-14 07:32:08.000000000 +0200 @@ -16,6 +16,10 @@ expect(subject.src).to eq(subject.source) end + it "has a project filename which removes the project directory" do + expect(subject.project_filename).to eq("/spec/fixtures/sample.rb") + end + it "has source_lines equal to lines" do expect(subject.lines).to eq(subject.source_lines) end
