simplecov-patched 0.14.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +31 -0
- data/.rspec +3 -0
- data/.rubocop.yml +88 -0
- data/.travis.yml +29 -0
- data/.yardopts +1 -0
- data/CHANGELOG.md +435 -0
- data/CONTRIBUTING.md +48 -0
- data/Gemfile +38 -0
- data/MIT-LICENSE +20 -0
- data/README.md +646 -0
- data/Rakefile +41 -0
- data/cucumber.yml +13 -0
- data/doc/alternate-formatters.md +36 -0
- data/doc/commercial-services.md +20 -0
- data/doc/editor-integration.md +13 -0
- data/features/config_autoload.feature +46 -0
- data/features/config_command_name.feature +45 -0
- data/features/config_coverage_dir.feature +33 -0
- data/features/config_deactivate_merging.feature +42 -0
- data/features/config_formatters.feature +77 -0
- data/features/config_merge_timeout.feature +39 -0
- data/features/config_nocov_token.feature +79 -0
- data/features/config_profiles.feature +44 -0
- data/features/config_project_name.feature +27 -0
- data/features/config_styles.feature +121 -0
- data/features/config_tracked_files.feature +29 -0
- data/features/cucumber_basic.feature +29 -0
- data/features/maximum_coverage_drop.feature +89 -0
- data/features/merging_test_unit_and_rspec.feature +44 -0
- data/features/minimum_coverage.feature +59 -0
- data/features/refuse_coverage_drop.feature +95 -0
- data/features/rspec_basic.feature +32 -0
- data/features/rspec_fails_on_initialization.feature +14 -0
- data/features/rspec_groups_and_filters_basic.feature +29 -0
- data/features/rspec_groups_and_filters_complex.feature +37 -0
- data/features/rspec_groups_using_filter_class.feature +41 -0
- data/features/rspec_without_simplecov.feature +20 -0
- data/features/skipping_code_blocks_manually.feature +70 -0
- data/features/step_definitions/html_steps.rb +44 -0
- data/features/step_definitions/simplecov_steps.rb +68 -0
- data/features/step_definitions/transformers.rb +13 -0
- data/features/step_definitions/web_steps.rb +64 -0
- data/features/support/env.rb +50 -0
- data/features/test_unit_basic.feature +34 -0
- data/features/test_unit_groups_and_filters_basic.feature +29 -0
- data/features/test_unit_groups_and_filters_complex.feature +35 -0
- data/features/test_unit_groups_using_filter_class.feature +40 -0
- data/features/test_unit_without_simplecov.feature +20 -0
- data/features/unicode_compatiblity.feature +67 -0
- data/lib/simplecov.rb +189 -0
- data/lib/simplecov/command_guesser.rb +59 -0
- data/lib/simplecov/configuration.rb +307 -0
- data/lib/simplecov/defaults.rb +121 -0
- data/lib/simplecov/exit_codes.rb +8 -0
- data/lib/simplecov/file_list.rb +59 -0
- data/lib/simplecov/filter.rb +54 -0
- data/lib/simplecov/formatter.rb +8 -0
- data/lib/simplecov/formatter/multi_formatter.rb +32 -0
- data/lib/simplecov/formatter/simple_formatter.rb +23 -0
- data/lib/simplecov/jruby_fix.rb +42 -0
- data/lib/simplecov/last_run.rb +24 -0
- data/lib/simplecov/load_global_config.rb +6 -0
- data/lib/simplecov/no_defaults.rb +2 -0
- data/lib/simplecov/profiles.rb +31 -0
- data/lib/simplecov/railtie.rb +7 -0
- data/lib/simplecov/railties/tasks.rake +11 -0
- data/lib/simplecov/raw_coverage.rb +39 -0
- data/lib/simplecov/result.rb +86 -0
- data/lib/simplecov/result_merger.rb +95 -0
- data/lib/simplecov/source_file.rb +196 -0
- data/lib/simplecov/version.rb +25 -0
- data/spec/1_8_fallbacks_spec.rb +31 -0
- data/spec/command_guesser_spec.rb +48 -0
- data/spec/config_loader_spec.rb +14 -0
- data/spec/configuration_spec.rb +35 -0
- data/spec/deleted_source_spec.rb +12 -0
- data/spec/faked_project/Gemfile +6 -0
- data/spec/faked_project/Rakefile +8 -0
- data/spec/faked_project/cucumber.yml +13 -0
- data/spec/faked_project/features/step_definitions/my_steps.rb +22 -0
- data/spec/faked_project/features/support/env.rb +12 -0
- data/spec/faked_project/features/test_stuff.feature +6 -0
- data/spec/faked_project/lib/faked_project.rb +11 -0
- data/spec/faked_project/lib/faked_project/framework_specific.rb +18 -0
- data/spec/faked_project/lib/faked_project/meta_magic.rb +24 -0
- data/spec/faked_project/lib/faked_project/some_class.rb +28 -0
- data/spec/faked_project/lib/faked_project/untested_class.rb +11 -0
- data/spec/faked_project/spec/faked_spec.rb +11 -0
- data/spec/faked_project/spec/forking_spec.rb +8 -0
- data/spec/faked_project/spec/meta_magic_spec.rb +15 -0
- data/spec/faked_project/spec/some_class_spec.rb +13 -0
- data/spec/faked_project/spec/spec_helper.rb +11 -0
- data/spec/faked_project/test/faked_test.rb +11 -0
- data/spec/faked_project/test/meta_magic_test.rb +13 -0
- data/spec/faked_project/test/some_class_test.rb +15 -0
- data/spec/faked_project/test/test_helper.rb +12 -0
- data/spec/file_list_spec.rb +50 -0
- data/spec/filters_spec.rb +98 -0
- data/spec/fixtures/app/controllers/sample_controller.rb +10 -0
- data/spec/fixtures/app/models/user.rb +10 -0
- data/spec/fixtures/deleted_source_sample.rb +15 -0
- data/spec/fixtures/frameworks/rspec_bad.rb +9 -0
- data/spec/fixtures/frameworks/rspec_good.rb +9 -0
- data/spec/fixtures/frameworks/testunit_bad.rb +9 -0
- data/spec/fixtures/frameworks/testunit_good.rb +9 -0
- data/spec/fixtures/iso-8859.rb +3 -0
- data/spec/fixtures/never.rb +2 -0
- data/spec/fixtures/resultset1.rb +4 -0
- data/spec/fixtures/resultset2.rb +4 -0
- data/spec/fixtures/sample.rb +16 -0
- data/spec/fixtures/skipped.rb +4 -0
- data/spec/fixtures/skipped_and_executed.rb +8 -0
- data/spec/fixtures/utf-8.rb +3 -0
- data/spec/helper.rb +26 -0
- data/spec/last_run_spec.rb +48 -0
- data/spec/multi_formatter_spec.rb +20 -0
- data/spec/raw_coverage_spec.rb +92 -0
- data/spec/result_merger_spec.rb +96 -0
- data/spec/result_spec.rb +209 -0
- data/spec/return_codes_spec.rb +34 -0
- data/spec/simplecov_spec.rb +110 -0
- data/spec/source_file_line_spec.rb +155 -0
- data/spec/source_file_spec.rb +141 -0
- data/spec/support/fail_rspec_on_ruby_warning.rb +75 -0
- metadata +320 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Enforce the alphabetical execution of specs because rspec 2+ executes them
|
|
3
|
+
# randomly with `rspec spec` while we need them in an accurate order for coverage
|
|
4
|
+
# reports that include the spec files.
|
|
5
|
+
#
|
|
6
|
+
# This is due to the fact that coverage will not include the first loaded spec/test file.
|
|
7
|
+
# To get predictable coverage results, we need to know which one that is...
|
|
8
|
+
#
|
|
9
|
+
Transform "bundle exec rspec spec" do |_|
|
|
10
|
+
files = nil # Avoid shadowing
|
|
11
|
+
in_current_directory { files = Dir["spec/**/*_spec.rb"] }
|
|
12
|
+
"bundle exec rspec #{files.sort.join(' ')}"
|
|
13
|
+
end
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
module WithinHelpers
|
|
2
|
+
def with_scope(locator)
|
|
3
|
+
locator ? within(locator) { yield } : yield
|
|
4
|
+
end
|
|
5
|
+
end
|
|
6
|
+
World(WithinHelpers)
|
|
7
|
+
|
|
8
|
+
When /^I open the coverage report$/ do
|
|
9
|
+
visit "/"
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
Given /^(?:|I )am on (.+)$/ do |path|
|
|
13
|
+
visit path
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
When /^(?:|I )go to (.+)$/ do |path|
|
|
17
|
+
visit path
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
When /^(?:|I )press "([^"]*)"(?: within "([^"]*)")?$/ do |button, selector|
|
|
21
|
+
with_scope(selector) do
|
|
22
|
+
click_button(button)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
When /^(?:|I )follow "([^"]*)"(?: within "([^"]*)")?$/ do |link, selector|
|
|
27
|
+
with_scope(selector) do
|
|
28
|
+
click_link(link)
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
Then /^(?:|I )should see "([^"]*)"(?: within "([^"]*)")?$/ do |text, selector|
|
|
33
|
+
with_scope(selector) do
|
|
34
|
+
expect(page).to have_content(text)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
Then /^(?:|I )should see \/([^\/]*)\/(?: within "([^"]*)")?$/ do |regexp, selector|
|
|
39
|
+
regexp = Regexp.new(regexp)
|
|
40
|
+
with_scope(selector) do
|
|
41
|
+
expect(page).to have_xpath("//*", :text => regexp)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
Then /^(?:|I )should not see "([^"]*)"(?: within "([^"]*)")?$/ do |text, selector|
|
|
46
|
+
with_scope(selector) do
|
|
47
|
+
expect(page).to have_no_content(text)
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
Then /^(?:|I )should not see \/([^\/]*)\/(?: within "([^"]*)")?$/ do |regexp, selector|
|
|
52
|
+
regexp = Regexp.new(regexp)
|
|
53
|
+
with_scope(selector) do
|
|
54
|
+
expect(page).to have_no_xpath("//*", :text => regexp)
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
Then /^show me the page$/ do
|
|
59
|
+
save_and_open_page # rubocop:disable Lint/Debugger
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
Then /^print the page$/ do
|
|
63
|
+
puts page.body
|
|
64
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
if RUBY_VERSION < "1.9"
|
|
2
|
+
$stderr.puts "Sorry, Cucumber features are only meant to run on Ruby 1.9+ :("
|
|
3
|
+
exit 0
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
require "bundler"
|
|
7
|
+
Bundler.setup
|
|
8
|
+
require "aruba/cucumber"
|
|
9
|
+
require "aruba/jruby" if RUBY_ENGINE == "jruby"
|
|
10
|
+
require "capybara/cucumber"
|
|
11
|
+
require "phantomjs/poltergeist"
|
|
12
|
+
|
|
13
|
+
# Fake rack app for capybara that just returns the latest coverage report from aruba temp project dir
|
|
14
|
+
Capybara.app = lambda { |env|
|
|
15
|
+
request_path = env["REQUEST_PATH"] || "/"
|
|
16
|
+
request_path = "/index.html" if request_path == "/"
|
|
17
|
+
[
|
|
18
|
+
200,
|
|
19
|
+
{"Content-Type" => "text/html"},
|
|
20
|
+
[File.read(File.join(File.dirname(__FILE__), "../../tmp/aruba/project/coverage", request_path))],
|
|
21
|
+
]
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
Capybara.default_driver = Capybara.javascript_driver = :poltergeist
|
|
25
|
+
|
|
26
|
+
Capybara.configure do |config|
|
|
27
|
+
config.ignore_hidden_elements = false
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
Before do
|
|
31
|
+
# JRuby takes it's time... See https://github.com/cucumber/aruba/issues/134
|
|
32
|
+
@aruba_timeout_seconds = RUBY_ENGINE == "jruby" ? 60 : 20
|
|
33
|
+
|
|
34
|
+
this_dir = File.dirname(__FILE__)
|
|
35
|
+
|
|
36
|
+
# Clean up and create blank state for fake project
|
|
37
|
+
in_current_directory do
|
|
38
|
+
FileUtils.rm_rf "project"
|
|
39
|
+
FileUtils.cp_r File.join(this_dir, "../../spec/faked_project/"), "project"
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
step 'I cd to "project"'
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# Workaround for https://github.com/cucumber/aruba/pull/125
|
|
46
|
+
Aruba.configure do |config|
|
|
47
|
+
config.before_cmd do
|
|
48
|
+
set_env("JRUBY_OPTS", "--dev --debug")
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
@test_unit
|
|
2
|
+
Feature:
|
|
3
|
+
|
|
4
|
+
Simply adding the basic simplecov lines to a project should get
|
|
5
|
+
the user a coverage report after running `rake test`
|
|
6
|
+
|
|
7
|
+
Scenario:
|
|
8
|
+
Given SimpleCov for Test/Unit is configured with:
|
|
9
|
+
"""
|
|
10
|
+
require 'simplecov'
|
|
11
|
+
SimpleCov.start
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
When I open the coverage report generated with `bundle exec rake test`
|
|
15
|
+
Then I should see the groups:
|
|
16
|
+
| name | coverage | files |
|
|
17
|
+
| All Files | 91.38% | 6 |
|
|
18
|
+
|
|
19
|
+
And I should see the source files:
|
|
20
|
+
| name | coverage |
|
|
21
|
+
| lib/faked_project.rb | 100.0 % |
|
|
22
|
+
| lib/faked_project/some_class.rb | 80.0 % |
|
|
23
|
+
| lib/faked_project/framework_specific.rb | 75.0 % |
|
|
24
|
+
| lib/faked_project/meta_magic.rb | 100.0 % |
|
|
25
|
+
| test/meta_magic_test.rb | 100.0 % |
|
|
26
|
+
| test/some_class_test.rb | 100.0 % |
|
|
27
|
+
|
|
28
|
+
# Note: faked_test.rb is not appearing here since that's the first unit test file
|
|
29
|
+
# loaded by Rake, and only there test_helper is required, which then loads simplecov
|
|
30
|
+
# and triggers tracking of all other loaded files! Solution for this would be to
|
|
31
|
+
# configure simplecov in this first test instead of test_helper.
|
|
32
|
+
|
|
33
|
+
And the report should be based upon:
|
|
34
|
+
| Unit Tests |
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
@test_unit
|
|
2
|
+
Feature:
|
|
3
|
+
|
|
4
|
+
Defining some groups and filters should give a corresponding
|
|
5
|
+
coverage report that respects those settings after running tests
|
|
6
|
+
|
|
7
|
+
Scenario:
|
|
8
|
+
Given SimpleCov for Test/Unit is configured with:
|
|
9
|
+
"""
|
|
10
|
+
require 'simplecov'
|
|
11
|
+
SimpleCov.start do
|
|
12
|
+
add_group 'Libs', 'lib/faked_project/'
|
|
13
|
+
add_filter '/test/'
|
|
14
|
+
end
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
When I open the coverage report generated with `bundle exec rake test`
|
|
18
|
+
Then I should see the groups:
|
|
19
|
+
| name | coverage | files |
|
|
20
|
+
| All Files | 88.1% | 4 |
|
|
21
|
+
| Libs | 86.11% | 3 |
|
|
22
|
+
| Ungrouped | 100.0% | 1 |
|
|
23
|
+
|
|
24
|
+
And I should see the source files:
|
|
25
|
+
| name | coverage |
|
|
26
|
+
| lib/faked_project.rb | 100.0 % |
|
|
27
|
+
| lib/faked_project/some_class.rb | 80.0 % |
|
|
28
|
+
| lib/faked_project/framework_specific.rb | 75.0 % |
|
|
29
|
+
| lib/faked_project/meta_magic.rb | 100.0 % |
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
@test_unit
|
|
2
|
+
Feature: Sophisticated grouping and filtering on Test/Unit
|
|
3
|
+
|
|
4
|
+
Defining groups and filters can be done by passing blocks or strings.
|
|
5
|
+
Blocks get each SimpleCov::SourceFile instance passed an can use arbitrary
|
|
6
|
+
and potentially weird conditions to remove files from the report or add them
|
|
7
|
+
to specific groups.
|
|
8
|
+
|
|
9
|
+
Scenario:
|
|
10
|
+
Given SimpleCov for Test/Unit is configured with:
|
|
11
|
+
"""
|
|
12
|
+
require 'simplecov'
|
|
13
|
+
SimpleCov.start do
|
|
14
|
+
add_group 'By block' do |src_file|
|
|
15
|
+
src_file.filename =~ /MaGiC/i
|
|
16
|
+
end
|
|
17
|
+
add_group 'By string', 'project/meta_magic'
|
|
18
|
+
|
|
19
|
+
add_filter 'faked_project.rb'
|
|
20
|
+
# Remove all files that include "describe" in their source
|
|
21
|
+
add_filter {|src_file| src_file.lines.any? {|line| line.src =~ /TestCase/ } }
|
|
22
|
+
add_filter {|src_file| src_file.covered_percent < 100 }
|
|
23
|
+
end
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
When I open the coverage report generated with `bundle exec rake test`
|
|
27
|
+
Then I should see the groups:
|
|
28
|
+
| name | coverage | files |
|
|
29
|
+
| All Files | 100.0% | 1 |
|
|
30
|
+
| By block | 100.0% | 1 |
|
|
31
|
+
| By string | 100.0% | 1 |
|
|
32
|
+
|
|
33
|
+
And I should see the source files:
|
|
34
|
+
| name | coverage |
|
|
35
|
+
| lib/faked_project/meta_magic.rb | 100.0 % |
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
@test_unit
|
|
2
|
+
Feature: Grouping on Test/Unit using a custom filter class
|
|
3
|
+
|
|
4
|
+
Next to passing a block or a string to define a group, you can also pass
|
|
5
|
+
a filter class. The filter class inherits from SimpleCov::Filter and
|
|
6
|
+
must implement the matches? method, which is used to determine whether
|
|
7
|
+
or not a file should be added to the group.
|
|
8
|
+
|
|
9
|
+
Scenario:
|
|
10
|
+
Given SimpleCov for Test/Unit is configured with:
|
|
11
|
+
"""
|
|
12
|
+
require 'simplecov'
|
|
13
|
+
class CoverageFilter < SimpleCov::Filter
|
|
14
|
+
def matches?(source_file)
|
|
15
|
+
source_file.covered_percent < filter_argument
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
SimpleCov.start do
|
|
19
|
+
add_group 'By filter class', CoverageFilter.new(90)
|
|
20
|
+
add_group 'By string', 'project/meta_magic'
|
|
21
|
+
end
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
When I open the coverage report generated with `bundle exec rake test`
|
|
25
|
+
Then I should see the groups:
|
|
26
|
+
| name | coverage | files |
|
|
27
|
+
| All Files | 91.38% | 6 |
|
|
28
|
+
| By filter class | 78.26% | 2 |
|
|
29
|
+
| By string | 100.0% | 1 |
|
|
30
|
+
| Ungrouped | 100.0% | 3 |
|
|
31
|
+
|
|
32
|
+
And I should see the source files:
|
|
33
|
+
| name | coverage |
|
|
34
|
+
| lib/faked_project/framework_specific.rb | 75.0 % |
|
|
35
|
+
| lib/faked_project/some_class.rb | 80.0 % |
|
|
36
|
+
| lib/faked_project.rb | 100.0 % |
|
|
37
|
+
| lib/faked_project/meta_magic.rb | 100.0 % |
|
|
38
|
+
| test/meta_magic_test.rb | 100.0 % |
|
|
39
|
+
| test/some_class_test.rb | 100.0 % |
|
|
40
|
+
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
@test_unit
|
|
2
|
+
Feature:
|
|
3
|
+
|
|
4
|
+
Running unit tests without simplecov configuration
|
|
5
|
+
|
|
6
|
+
Scenario: No config at all
|
|
7
|
+
When I successfully run `bundle exec rake test`
|
|
8
|
+
Then no coverage report should have been generated
|
|
9
|
+
|
|
10
|
+
Scenario: Configured, but not started
|
|
11
|
+
Given SimpleCov for Test/Unit is configured with:
|
|
12
|
+
"""
|
|
13
|
+
require 'simplecov'
|
|
14
|
+
SimpleCov.configure do
|
|
15
|
+
add_filter 'somefilter'
|
|
16
|
+
end
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
When I successfully run `bundle exec rake test`
|
|
20
|
+
Then no coverage report should have been generated
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
@test_unit @unicode
|
|
2
|
+
Feature:
|
|
3
|
+
|
|
4
|
+
Files with unicode in their source should be no problem at all for
|
|
5
|
+
generating a proper coverage report.
|
|
6
|
+
|
|
7
|
+
Background:
|
|
8
|
+
Given SimpleCov for Test/Unit is configured with:
|
|
9
|
+
"""
|
|
10
|
+
require 'simplecov'
|
|
11
|
+
SimpleCov.start 'test_frameworks'
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
Scenario: Snowman inside method string
|
|
15
|
+
Given a file named "lib/faked_project/unicode.rb" with:
|
|
16
|
+
"""
|
|
17
|
+
# encoding: UTF-8
|
|
18
|
+
class SourceCodeWithUnicode
|
|
19
|
+
def self.yell!
|
|
20
|
+
puts "☃"
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
When I open the coverage report generated with `bundle exec rake test`
|
|
26
|
+
Then I should see the groups:
|
|
27
|
+
| name | coverage | files |
|
|
28
|
+
| All Files | 86.67% | 5 |
|
|
29
|
+
|
|
30
|
+
And I should see the source files:
|
|
31
|
+
| name | coverage |
|
|
32
|
+
| lib/faked_project.rb | 100.0 % |
|
|
33
|
+
| lib/faked_project/some_class.rb | 80.0 % |
|
|
34
|
+
| lib/faked_project/framework_specific.rb | 75.0 % |
|
|
35
|
+
| lib/faked_project/meta_magic.rb | 100.0 % |
|
|
36
|
+
| lib/faked_project/unicode.rb | 66.67 % |
|
|
37
|
+
|
|
38
|
+
And the report should be based upon:
|
|
39
|
+
| Unit Tests |
|
|
40
|
+
|
|
41
|
+
Scenario: Author name in comment
|
|
42
|
+
Given a file named "lib/faked_project/unicode.rb" with:
|
|
43
|
+
"""
|
|
44
|
+
# encoding: UTF-8
|
|
45
|
+
# author: Javiér Hernández
|
|
46
|
+
class SomeClassWrittenByAForeigner
|
|
47
|
+
def self.yell!
|
|
48
|
+
foo
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
"""
|
|
52
|
+
|
|
53
|
+
When I open the coverage report generated with `bundle exec rake test`
|
|
54
|
+
Then I should see the groups:
|
|
55
|
+
| name | coverage | files |
|
|
56
|
+
| All Files | 86.67% | 5 |
|
|
57
|
+
|
|
58
|
+
And I should see the source files:
|
|
59
|
+
| name | coverage |
|
|
60
|
+
| lib/faked_project.rb | 100.0 % |
|
|
61
|
+
| lib/faked_project/some_class.rb | 80.0 % |
|
|
62
|
+
| lib/faked_project/framework_specific.rb | 75.0 % |
|
|
63
|
+
| lib/faked_project/meta_magic.rb | 100.0 % |
|
|
64
|
+
| lib/faked_project/unicode.rb | 66.67 % |
|
|
65
|
+
|
|
66
|
+
And the report should be based upon:
|
|
67
|
+
| Unit Tests |
|
data/lib/simplecov.rb
ADDED
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
#
|
|
2
|
+
# Code coverage for ruby 1.9. Please check out README for a full introduction.
|
|
3
|
+
#
|
|
4
|
+
# Coverage may be inaccurate under JRUBY.
|
|
5
|
+
if defined?(JRUBY_VERSION) && defined?(JRuby)
|
|
6
|
+
|
|
7
|
+
# @see https://github.com/jruby/jruby/issues/1196
|
|
8
|
+
# @see https://github.com/metricfu/metric_fu/pull/226
|
|
9
|
+
# @see https://github.com/colszowka/simplecov/issues/420
|
|
10
|
+
# @see https://github.com/colszowka/simplecov/issues/86
|
|
11
|
+
# @see https://jira.codehaus.org/browse/JRUBY-6106
|
|
12
|
+
|
|
13
|
+
unless org.jruby.RubyInstanceConfig.FULL_TRACE_ENABLED
|
|
14
|
+
warn 'Coverage may be inaccurate; set the "--debug" command line option,' \
|
|
15
|
+
' or do JRUBY_OPTS="--debug"' \
|
|
16
|
+
' or set the "debug.fullTrace=true" option in your .jrubyrc'
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
module SimpleCov
|
|
20
|
+
class << self
|
|
21
|
+
attr_accessor :running
|
|
22
|
+
attr_accessor :pid
|
|
23
|
+
|
|
24
|
+
#
|
|
25
|
+
# Sets up SimpleCov to run against your project.
|
|
26
|
+
# You can optionally specify a profile to use as well as configuration with a block:
|
|
27
|
+
# SimpleCov.start
|
|
28
|
+
# OR
|
|
29
|
+
# SimpleCov.start 'rails' # using rails profile
|
|
30
|
+
# OR
|
|
31
|
+
# SimpleCov.start do
|
|
32
|
+
# add_filter 'test'
|
|
33
|
+
# end
|
|
34
|
+
# OR
|
|
35
|
+
# SimpleCov.start 'rails' do
|
|
36
|
+
# add_filter 'test'
|
|
37
|
+
# end
|
|
38
|
+
#
|
|
39
|
+
# Please check out the RDoc for SimpleCov::Configuration to find about available config options
|
|
40
|
+
#
|
|
41
|
+
def start(profile = nil, &block)
|
|
42
|
+
if SimpleCov.usable?
|
|
43
|
+
load_profile(profile) if profile
|
|
44
|
+
configure(&block) if block_given?
|
|
45
|
+
@result = nil
|
|
46
|
+
self.running = true
|
|
47
|
+
self.pid = Process.pid
|
|
48
|
+
Coverage.start
|
|
49
|
+
else
|
|
50
|
+
warn "WARNING: SimpleCov is activated, but you're not running Ruby 1.9+ - no coverage analysis will happen"
|
|
51
|
+
warn "Starting with SimpleCov 1.0.0, even no-op compatibility with Ruby <= 1.8 will be entirely dropped."
|
|
52
|
+
false
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
#
|
|
57
|
+
# Finds files that were to be tracked but were not loaded and initializes
|
|
58
|
+
# their coverage to zero.
|
|
59
|
+
#
|
|
60
|
+
def add_not_loaded_files(result)
|
|
61
|
+
if tracked_files
|
|
62
|
+
result = result.dup
|
|
63
|
+
Dir[tracked_files].each do |file|
|
|
64
|
+
absolute = File.expand_path(file)
|
|
65
|
+
|
|
66
|
+
result[absolute] ||= [0] * File.foreach(absolute).count
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
result
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
#
|
|
74
|
+
# Returns the result for the current coverage run, merging it across test suites
|
|
75
|
+
# from cache using SimpleCov::ResultMerger if use_merging is activated (default)
|
|
76
|
+
#
|
|
77
|
+
def result
|
|
78
|
+
return @result if result?
|
|
79
|
+
|
|
80
|
+
# Collect our coverage result
|
|
81
|
+
if running
|
|
82
|
+
@result = SimpleCov::Result.new add_not_loaded_files(Coverage.result)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# If we're using merging of results, store the current result
|
|
86
|
+
# first (if there is one), then merge the results and return those
|
|
87
|
+
if use_merging
|
|
88
|
+
SimpleCov::ResultMerger.store_result(@result) if result?
|
|
89
|
+
@result = SimpleCov::ResultMerger.merged_result
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
@result
|
|
93
|
+
ensure
|
|
94
|
+
self.running = false
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
#
|
|
98
|
+
# Returns nil if the result has not been computed
|
|
99
|
+
# Otherwise, returns the result
|
|
100
|
+
#
|
|
101
|
+
def result?
|
|
102
|
+
defined?(@result) && @result
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
#
|
|
106
|
+
# Applies the configured filters to the given array of SimpleCov::SourceFile items
|
|
107
|
+
#
|
|
108
|
+
def filtered(files)
|
|
109
|
+
result = files.clone
|
|
110
|
+
filters.each do |filter|
|
|
111
|
+
result = result.reject { |source_file| filter.matches?(source_file) }
|
|
112
|
+
end
|
|
113
|
+
SimpleCov::FileList.new result
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
#
|
|
117
|
+
# Applies the configured groups to the given array of SimpleCov::SourceFile items
|
|
118
|
+
#
|
|
119
|
+
def grouped(files)
|
|
120
|
+
grouped = {}
|
|
121
|
+
grouped_files = []
|
|
122
|
+
groups.each do |name, filter|
|
|
123
|
+
grouped[name] = SimpleCov::FileList.new(files.select { |source_file| filter.matches?(source_file) })
|
|
124
|
+
grouped_files += grouped[name]
|
|
125
|
+
end
|
|
126
|
+
if !groups.empty? && !(other_files = files.reject { |source_file| grouped_files.include?(source_file) }).empty?
|
|
127
|
+
grouped["Ungrouped"] = SimpleCov::FileList.new(other_files)
|
|
128
|
+
end
|
|
129
|
+
grouped
|
|
130
|
+
end
|
|
131
|
+
|
|
132
|
+
#
|
|
133
|
+
# Applies the profile of given name on SimpleCov configuration
|
|
134
|
+
#
|
|
135
|
+
def load_profile(name)
|
|
136
|
+
profiles.load(name)
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def load_adapter(name)
|
|
140
|
+
warn "#{Kernel.caller.first}: [DEPRECATION] #load_adapter is deprecated. Use #load_profile instead."
|
|
141
|
+
load_profile(name)
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
#
|
|
145
|
+
# Checks whether we're on a proper version of Ruby (likely 1.9+) which
|
|
146
|
+
# provides coverage support
|
|
147
|
+
#
|
|
148
|
+
def usable?
|
|
149
|
+
return @usable if defined?(@usable) && !@usable.nil?
|
|
150
|
+
|
|
151
|
+
@usable = begin
|
|
152
|
+
require "coverage"
|
|
153
|
+
require "simplecov/jruby_fix"
|
|
154
|
+
true
|
|
155
|
+
rescue LoadError
|
|
156
|
+
false
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
|
|
160
|
+
#
|
|
161
|
+
# Clear out the previously cached .result. Primarily useful in testing
|
|
162
|
+
#
|
|
163
|
+
def clear_result!
|
|
164
|
+
@result = nil
|
|
165
|
+
end
|
|
166
|
+
end
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__)))
|
|
170
|
+
require "simplecov/configuration"
|
|
171
|
+
SimpleCov.send :extend, SimpleCov::Configuration
|
|
172
|
+
require "simplecov/exit_codes"
|
|
173
|
+
require "simplecov/profiles"
|
|
174
|
+
require "simplecov/source_file"
|
|
175
|
+
require "simplecov/file_list"
|
|
176
|
+
require "simplecov/result"
|
|
177
|
+
require "simplecov/filter"
|
|
178
|
+
require "simplecov/formatter"
|
|
179
|
+
require "simplecov/last_run"
|
|
180
|
+
require "simplecov/raw_coverage"
|
|
181
|
+
require "simplecov/result_merger"
|
|
182
|
+
require "simplecov/command_guesser"
|
|
183
|
+
require "simplecov/version"
|
|
184
|
+
|
|
185
|
+
# Load default config
|
|
186
|
+
require "simplecov/defaults" unless ENV["SIMPLECOV_NO_DEFAULTS"]
|
|
187
|
+
|
|
188
|
+
# Load Rails integration (only for Rails 3, see #113)
|
|
189
|
+
require "simplecov/railtie" if defined? Rails::Railtie
|