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,15 @@
|
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", ".."))
|
|
2
|
+
require "lib/simplecov"
|
|
3
|
+
SimpleCov.start { command_name "Test" }
|
|
4
|
+
|
|
5
|
+
dir = File.expand_path(File.dirname(__FILE__))
|
|
6
|
+
file = File.join(dir, "generated_buddha.rb")
|
|
7
|
+
code = %{
|
|
8
|
+
def kill_the_buddha(z)
|
|
9
|
+
z**z
|
|
10
|
+
end
|
|
11
|
+
}
|
|
12
|
+
File.open(file, "w") { |f| f.print code }
|
|
13
|
+
load file
|
|
14
|
+
File.unlink file
|
|
15
|
+
raise unless kill_the_buddha(3) == 27
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "..", ".."))
|
|
2
|
+
require "lib/simplecov"
|
|
3
|
+
require "rspec"
|
|
4
|
+
SimpleCov.start
|
|
5
|
+
describe "exit status" do
|
|
6
|
+
it "should exit with a non-zero exit status when assertion fails" do
|
|
7
|
+
expect(1).to eq(2)
|
|
8
|
+
end
|
|
9
|
+
end
|
data/spec/helper.rb
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
require "rspec"
|
|
2
|
+
# loaded before simplecov to also capture parse time warnings
|
|
3
|
+
require "support/fail_rspec_on_ruby_warning"
|
|
4
|
+
require "simplecov"
|
|
5
|
+
|
|
6
|
+
SimpleCov.coverage_dir("tmp/coverage")
|
|
7
|
+
|
|
8
|
+
def source_fixture(filename)
|
|
9
|
+
File.expand_path(File.join(File.dirname(__FILE__), "fixtures", filename))
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# Taken from http://stackoverflow.com/questions/4459330/how-do-i-temporarily-redirect-stderr-in-ruby
|
|
13
|
+
require "stringio"
|
|
14
|
+
|
|
15
|
+
def capture_stderr
|
|
16
|
+
# The output stream must be an IO-like object. In this case we capture it in
|
|
17
|
+
# an in-memory IO object so we can return the string value. You can assign any
|
|
18
|
+
# IO object here.
|
|
19
|
+
previous_stderr = $stderr
|
|
20
|
+
$stderr = StringIO.new
|
|
21
|
+
yield
|
|
22
|
+
$stderr.string
|
|
23
|
+
ensure
|
|
24
|
+
# Restore the previous value of stderr (typically equal to STDERR).
|
|
25
|
+
$stderr = previous_stderr
|
|
26
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
require "helper"
|
|
2
|
+
|
|
3
|
+
if SimpleCov.usable?
|
|
4
|
+
describe SimpleCov::LastRun do
|
|
5
|
+
subject { SimpleCov::LastRun }
|
|
6
|
+
|
|
7
|
+
it "defines a last_run_path" do
|
|
8
|
+
expect(subject.last_run_path).to include "tmp/coverage/.last_run.json"
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it "writes json to its last_run_path that can be parsed again" do
|
|
12
|
+
structure = [{"key" => "value"}]
|
|
13
|
+
subject.write(structure)
|
|
14
|
+
file_contents = File.read(subject.last_run_path)
|
|
15
|
+
expect(JSON.parse(file_contents)).to eq structure
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
context "reading" do
|
|
19
|
+
context "but the last_run file does not exist" do
|
|
20
|
+
before { File.delete(subject.last_run_path) if File.exist?(subject.last_run_path) }
|
|
21
|
+
|
|
22
|
+
it "returns nil" do
|
|
23
|
+
expect(subject.read).to be_nil
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
context "a non empty result" do
|
|
28
|
+
before { subject.write([]) }
|
|
29
|
+
|
|
30
|
+
it "reads json from its last_run_path" do
|
|
31
|
+
expect(subject.read).to eq([])
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
context "an empty result" do
|
|
36
|
+
before do
|
|
37
|
+
File.open(subject.last_run_path, "w+") do |f|
|
|
38
|
+
f.puts ""
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
it "returns nil" do
|
|
43
|
+
expect(subject.read).to be_nil
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
require "helper"
|
|
2
|
+
|
|
3
|
+
require "simplecov/formatter/multi_formatter"
|
|
4
|
+
|
|
5
|
+
describe SimpleCov::Formatter::MultiFormatter do
|
|
6
|
+
describe ".[]" do
|
|
7
|
+
# Regression test for https://github.com/colszowka/simplecov/issues/428
|
|
8
|
+
it "constructs a formatter with multiple children" do
|
|
9
|
+
# Silence deprecation warnings.
|
|
10
|
+
allow(described_class).to receive(:warn)
|
|
11
|
+
|
|
12
|
+
children = [
|
|
13
|
+
SimpleCov::Formatter::SimpleFormatter,
|
|
14
|
+
SimpleCov::Formatter::SimpleFormatter,
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
expect(described_class[*children].new.formatters).to eq(children)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
require "helper"
|
|
2
|
+
|
|
3
|
+
if SimpleCov.usable?
|
|
4
|
+
describe SimpleCov::RawCoverage do
|
|
5
|
+
describe "with two faked coverage resultsets" do
|
|
6
|
+
before do
|
|
7
|
+
@resultset1 = {
|
|
8
|
+
source_fixture("sample.rb") => [nil, 1, 1, 1, nil, nil, 1, 1, nil, nil],
|
|
9
|
+
source_fixture("app/models/user.rb") => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil],
|
|
10
|
+
source_fixture("app/controllers/sample_controller.rb") => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil],
|
|
11
|
+
source_fixture("resultset1.rb") => [1, 1, 1, 1],
|
|
12
|
+
source_fixture("parallel_tests.rb") => [nil, 0, nil, 0],
|
|
13
|
+
source_fixture("conditionally_loaded_1.rb") => [nil, 0, 1], # loaded only in the first resultset
|
|
14
|
+
source_fixture("three.rb") => [nil, 1, 1],
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
@resultset2 = {
|
|
18
|
+
source_fixture("sample.rb") => [1, nil, 1, 1, nil, nil, 1, 1, nil, nil],
|
|
19
|
+
source_fixture("app/models/user.rb") => [nil, 1, 5, 1, nil, nil, 1, 0, nil, nil],
|
|
20
|
+
source_fixture("app/controllers/sample_controller.rb") => [nil, 3, 1, nil, nil, nil, 1, 0, nil, nil],
|
|
21
|
+
source_fixture("resultset2.rb") => [nil, 1, 1, nil],
|
|
22
|
+
source_fixture("parallel_tests.rb") => [nil, nil, 0, 0],
|
|
23
|
+
source_fixture("conditionally_loaded_2.rb") => [nil, 0, 1], # loaded only in the second resultset
|
|
24
|
+
source_fixture("three.rb") => [nil, 1, 4],
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
@resultset3 = {
|
|
28
|
+
source_fixture("three.rb") => [nil, 1, 2],
|
|
29
|
+
}
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
context "a merge" do
|
|
33
|
+
subject do
|
|
34
|
+
SimpleCov::RawCoverage.merge_results(@resultset1, @resultset2, @resultset3)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
it "has proper results for sample.rb" do
|
|
38
|
+
expect(subject[source_fixture("sample.rb")]).to eq([1, 1, 2, 2, nil, nil, 2, 2, nil, nil])
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
it "has proper results for user.rb" do
|
|
42
|
+
expect(subject[source_fixture("app/models/user.rb")]).to eq([nil, 2, 6, 2, nil, nil, 2, 0, nil, nil])
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
it "has proper results for sample_controller.rb" do
|
|
46
|
+
expect(subject[source_fixture("app/controllers/sample_controller.rb")]).to eq([nil, 4, 2, 1, nil, nil, 2, 0, nil, nil])
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
it "has proper results for resultset1.rb" do
|
|
50
|
+
expect(subject[source_fixture("resultset1.rb")]).to eq([1, 1, 1, 1])
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it "has proper results for resultset2.rb" do
|
|
54
|
+
expect(subject[source_fixture("resultset2.rb")]).to eq([nil, 1, 1, nil])
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it "has proper results for parallel_tests.rb" do
|
|
58
|
+
expect(subject[source_fixture("parallel_tests.rb")]).to eq([nil, nil, nil, 0])
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it "has proper results for conditionally_loaded_1.rb" do
|
|
62
|
+
expect(subject[source_fixture("conditionally_loaded_1.rb")]).to eq([nil, 0, 1])
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
it "has proper results for conditionally_loaded_2.rb" do
|
|
66
|
+
expect(subject[source_fixture("conditionally_loaded_2.rb")]).to eq([nil, 0, 1])
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
it "has proper results for three.rb" do
|
|
70
|
+
expect(subject[source_fixture("three.rb")]).to eq([nil, 3, 7])
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
it "merges frozen resultsets" do
|
|
76
|
+
resultset1 = {
|
|
77
|
+
source_fixture("sample.rb").freeze => [nil, 1, 1, 1, nil, nil, 1, 1, nil, nil].freeze,
|
|
78
|
+
source_fixture("app/models/user.rb").freeze => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil].freeze,
|
|
79
|
+
}.freeze
|
|
80
|
+
|
|
81
|
+
resultset2 = {
|
|
82
|
+
source_fixture("sample.rb").freeze => [1, nil, 1, 1, nil, nil, 1, 1, nil, nil].freeze,
|
|
83
|
+
}.freeze
|
|
84
|
+
|
|
85
|
+
merged_result = SimpleCov::RawCoverage.merge_results(resultset1, resultset2)
|
|
86
|
+
expect(merged_result.keys).to eq(resultset1.keys)
|
|
87
|
+
expect(merged_result.values.map(&:frozen?)).to eq([false, false])
|
|
88
|
+
expect(merged_result[source_fixture("sample.rb")]).to eq([1, 1, 2, 2, nil, nil, 2, 2, nil, nil])
|
|
89
|
+
expect(merged_result[source_fixture("app/models/user.rb")]).to eq([nil, 1, 1, 1, nil, nil, 1, 0, nil, nil])
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
require "helper"
|
|
2
|
+
|
|
3
|
+
if SimpleCov.usable?
|
|
4
|
+
describe SimpleCov::ResultMerger do
|
|
5
|
+
describe "with two faked coverage resultsets" do
|
|
6
|
+
before do
|
|
7
|
+
@resultset1 = {
|
|
8
|
+
source_fixture("sample.rb") => [nil, 1, 1, 1, nil, nil, 1, 1, nil, nil],
|
|
9
|
+
source_fixture("app/models/user.rb") => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil],
|
|
10
|
+
source_fixture("app/controllers/sample_controller.rb") => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil],
|
|
11
|
+
source_fixture("resultset1.rb") => [1, 1, 1, 1],
|
|
12
|
+
source_fixture("parallel_tests.rb") => [nil, 0, nil, 0],
|
|
13
|
+
source_fixture("conditionally_loaded_1.rb") => [nil, 0, 1], # loaded only in the first resultset
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
@resultset2 = {
|
|
17
|
+
source_fixture("sample.rb") => [1, nil, 1, 1, nil, nil, 1, 1, nil, nil],
|
|
18
|
+
source_fixture("app/models/user.rb") => [nil, 1, 5, 1, nil, nil, 1, 0, nil, nil],
|
|
19
|
+
source_fixture("app/controllers/sample_controller.rb") => [nil, 3, 1, nil, nil, nil, 1, 0, nil, nil],
|
|
20
|
+
source_fixture("resultset2.rb") => [nil, 1, 1, nil],
|
|
21
|
+
source_fixture("parallel_tests.rb") => [nil, nil, 0, 0],
|
|
22
|
+
source_fixture("conditionally_loaded_2.rb") => [nil, 0, 1], # loaded only in the second resultset
|
|
23
|
+
}
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# See Github issue #6
|
|
27
|
+
it "returns an empty hash when the resultset cache file is empty" do
|
|
28
|
+
File.open(SimpleCov::ResultMerger.resultset_path, "w+") { |f| f.puts "" }
|
|
29
|
+
expect(SimpleCov::ResultMerger.resultset).to be_empty
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# See Github issue #6
|
|
33
|
+
it "returns an empty hash when the resultset cache file is not present" do
|
|
34
|
+
system "rm #{SimpleCov::ResultMerger.resultset_path}" if File.exist?(SimpleCov::ResultMerger.resultset_path)
|
|
35
|
+
expect(SimpleCov::ResultMerger.resultset).to be_empty
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
context "and results generated from those" do
|
|
39
|
+
before do
|
|
40
|
+
system "rm #{SimpleCov::ResultMerger.resultset_path}" if File.exist?(SimpleCov::ResultMerger.resultset_path)
|
|
41
|
+
@result1 = SimpleCov::Result.new(@resultset1)
|
|
42
|
+
@result1.command_name = "result1"
|
|
43
|
+
@result2 = SimpleCov::Result.new(@resultset2)
|
|
44
|
+
@result2.command_name = "result2"
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
context "with stored results" do
|
|
48
|
+
before do
|
|
49
|
+
SimpleCov::ResultMerger.store_result(@result1)
|
|
50
|
+
SimpleCov::ResultMerger.store_result(@result2)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
it "has stored data in resultset_path JSON file" do
|
|
54
|
+
expect(File.readlines(SimpleCov::ResultMerger.resultset_path).length).to be > 50
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it "returns a hash containing keys ['result1' and 'result2'] for resultset" do
|
|
58
|
+
expect(SimpleCov::ResultMerger.resultset.keys.sort).to eq %w[result1 result2]
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it "returns proper values for merged_result" do
|
|
62
|
+
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])
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
context "with second result way above the merge_timeout" do
|
|
66
|
+
before do
|
|
67
|
+
@result2.created_at = Time.now - 172_800 # two days ago
|
|
68
|
+
SimpleCov::ResultMerger.store_result(@result2)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
it "has only one result in SimpleCov::ResultMerger.results" do
|
|
72
|
+
expect(SimpleCov::ResultMerger.results.length).to eq(1)
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
describe ".store_result" do
|
|
79
|
+
it "refreshes the resultset" do
|
|
80
|
+
set = SimpleCov::ResultMerger.resultset
|
|
81
|
+
SimpleCov::ResultMerger.store_result({})
|
|
82
|
+
new_set = SimpleCov::ResultMerger.resultset
|
|
83
|
+
expect(new_set).not_to equal(set)
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
describe ".resultset" do
|
|
88
|
+
it "caches by default" do
|
|
89
|
+
set = SimpleCov::ResultMerger.resultset
|
|
90
|
+
new_set = SimpleCov::ResultMerger.resultset
|
|
91
|
+
expect(new_set).to equal(set)
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
data/spec/result_spec.rb
ADDED
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
require "helper"
|
|
2
|
+
|
|
3
|
+
if SimpleCov.usable?
|
|
4
|
+
describe "result" do
|
|
5
|
+
context "with a (mocked) Coverage.result" do
|
|
6
|
+
before do
|
|
7
|
+
@prev_filters = SimpleCov.filters
|
|
8
|
+
SimpleCov.filters = []
|
|
9
|
+
@prev_groups = SimpleCov.groups
|
|
10
|
+
SimpleCov.groups = {}
|
|
11
|
+
@prev_formatter = SimpleCov.formatter
|
|
12
|
+
SimpleCov.formatter = nil
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
after do
|
|
16
|
+
SimpleCov.filters = @prev_filters
|
|
17
|
+
SimpleCov.groups = @prev_groups
|
|
18
|
+
SimpleCov.formatter = @prev_formatter
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
let(:original_result) do
|
|
22
|
+
{
|
|
23
|
+
source_fixture("sample.rb") => [nil, 1, 1, 1, nil, nil, 1, 1, nil, nil],
|
|
24
|
+
source_fixture("app/models/user.rb") => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil],
|
|
25
|
+
source_fixture("app/controllers/sample_controller.rb") => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil],
|
|
26
|
+
}
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
context "a simple cov result initialized from that" do
|
|
30
|
+
subject { SimpleCov::Result.new(original_result) }
|
|
31
|
+
|
|
32
|
+
it "has 3 filenames" do
|
|
33
|
+
expect(subject.filenames.count).to eq(3)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
it "has 3 source files" do
|
|
37
|
+
expect(subject.source_files.count).to eq(3)
|
|
38
|
+
subject.source_files.each do |source_file|
|
|
39
|
+
expect(source_file).to be_a SimpleCov::SourceFile
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it "returns an instance of SimpleCov::FileList for source_files and files" do
|
|
44
|
+
expect(subject.files).to be_a SimpleCov::FileList
|
|
45
|
+
expect(subject.source_files).to be_a SimpleCov::FileList
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
it "has files equal to source_files" do
|
|
49
|
+
expect(subject.files).to eq(subject.source_files)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
it "has accurate covered percent" do
|
|
53
|
+
# in our fixture, there are 13 covered line (result in 1) in all 15 relevant line (result in non-nil)
|
|
54
|
+
expect(subject.covered_percent).to eq(86.66666666666667)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
it "has accurate covered percentages" do
|
|
58
|
+
expect(subject.covered_percentages).to eq([80.0, 80.0, 100.0])
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
it "has accurate least covered file" do
|
|
62
|
+
expect(subject.least_covered_file).to match(/sample_controller.rb/)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
[:covered_percent, :covered_percentages, :least_covered_file, :covered_strength, :covered_lines, :missed_lines, :total_lines].each do |msg|
|
|
66
|
+
it "responds to #{msg}" do
|
|
67
|
+
expect(subject).to respond_to(msg)
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
context "dumped with to_hash" do
|
|
72
|
+
it "is a hash" do
|
|
73
|
+
expect(subject.to_hash).to be_a Hash
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
context "loaded back with from_hash" do
|
|
77
|
+
let(:dumped_result) do
|
|
78
|
+
SimpleCov::Result.from_hash(subject.to_hash)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
it "has 3 source files" do
|
|
82
|
+
expect(dumped_result.source_files.count).to eq(subject.source_files.count)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
it "has the same covered_percent" do
|
|
86
|
+
expect(dumped_result.covered_percent).to eq(subject.covered_percent)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
it "has the same covered_percentages" do
|
|
90
|
+
expect(dumped_result.covered_percentages).to eq(subject.covered_percentages)
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
it "has the same timestamp" do
|
|
94
|
+
expect(dumped_result.created_at.to_i).to eq(subject.created_at.to_i)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
it "has the same command_name" do
|
|
98
|
+
expect(dumped_result.command_name).to eq(subject.command_name)
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
it "has the same original_result" do
|
|
102
|
+
expect(dumped_result.original_result).to eq(subject.original_result)
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
context "with some filters set up" do
|
|
109
|
+
before do
|
|
110
|
+
SimpleCov.add_filter "sample.rb"
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
it "has 2 files in a new simple cov result" do
|
|
114
|
+
expect(SimpleCov::Result.new(original_result).source_files.length).to eq(2)
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
it "has 80 covered percent" do
|
|
118
|
+
expect(SimpleCov::Result.new(original_result).covered_percent).to eq(80)
|
|
119
|
+
end
|
|
120
|
+
|
|
121
|
+
it "has [80.0, 80.0] covered percentages" do
|
|
122
|
+
expect(SimpleCov::Result.new(original_result).covered_percentages).to eq([80.0, 80.0])
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
context "with groups set up for all files" do
|
|
127
|
+
before do
|
|
128
|
+
SimpleCov.add_group "Models", "app/models"
|
|
129
|
+
SimpleCov.add_group "Controllers", ["app/controllers"]
|
|
130
|
+
SimpleCov.add_group "Other" do |src_file|
|
|
131
|
+
File.basename(src_file.filename) == "sample.rb"
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
subject do
|
|
136
|
+
SimpleCov::Result.new(original_result)
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
it "has 3 groups" do
|
|
140
|
+
expect(subject.groups.length).to eq(3)
|
|
141
|
+
end
|
|
142
|
+
|
|
143
|
+
it "has user.rb in 'Models' group" do
|
|
144
|
+
expect(File.basename(subject.groups["Models"].first.filename)).to eq("user.rb")
|
|
145
|
+
end
|
|
146
|
+
|
|
147
|
+
it "has sample_controller.rb in 'Controllers' group" do
|
|
148
|
+
expect(File.basename(subject.groups["Controllers"].first.filename)).to eq("sample_controller.rb")
|
|
149
|
+
end
|
|
150
|
+
|
|
151
|
+
context "and simple formatter being used" do
|
|
152
|
+
before do
|
|
153
|
+
SimpleCov.formatter = SimpleCov::Formatter::SimpleFormatter
|
|
154
|
+
end
|
|
155
|
+
|
|
156
|
+
it "returns a formatted string with result.format!" do
|
|
157
|
+
expect(subject.format!).to be_a String
|
|
158
|
+
end
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
context "and multi formatter being used" do
|
|
162
|
+
before do
|
|
163
|
+
SimpleCov.formatters = [
|
|
164
|
+
SimpleCov::Formatter::SimpleFormatter,
|
|
165
|
+
SimpleCov::Formatter::SimpleFormatter,
|
|
166
|
+
]
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
it "returns an array containing formatted string with result.format!" do
|
|
170
|
+
formatted = subject.format!
|
|
171
|
+
expect(formatted.count).to eq(2)
|
|
172
|
+
expect(formatted.first).to be_a String
|
|
173
|
+
end
|
|
174
|
+
end
|
|
175
|
+
end
|
|
176
|
+
|
|
177
|
+
context "with groups set up that do not match all files" do
|
|
178
|
+
before do
|
|
179
|
+
SimpleCov.configure do
|
|
180
|
+
add_group "Models", "app/models"
|
|
181
|
+
add_group "Controllers", "app/controllers"
|
|
182
|
+
end
|
|
183
|
+
end
|
|
184
|
+
|
|
185
|
+
subject { SimpleCov::Result.new(original_result) }
|
|
186
|
+
|
|
187
|
+
it "has 3 groups" do
|
|
188
|
+
expect(subject.groups.length).to eq(3)
|
|
189
|
+
end
|
|
190
|
+
|
|
191
|
+
it "has 1 item per group" do
|
|
192
|
+
subject.groups.each_value do |files|
|
|
193
|
+
expect(files.length).to eq(1)
|
|
194
|
+
end
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
it 'has sample.rb in "Ungrouped" group' do
|
|
198
|
+
expect(File.basename(subject.groups["Ungrouped"].first.filename)).to eq("sample.rb")
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
it "returns all groups as instances of SimpleCov::FileList" do
|
|
202
|
+
subject.groups.each_value do |files|
|
|
203
|
+
expect(files).to be_a SimpleCov::FileList
|
|
204
|
+
end
|
|
205
|
+
end
|
|
206
|
+
end
|
|
207
|
+
end
|
|
208
|
+
end
|
|
209
|
+
end
|