/
useless_results_remover_spec.rb
56 lines (46 loc) · 1.66 KB
/
useless_results_remover_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# frozen_string_literal: true
require "helper"
describe SimpleCov::UselessResultsRemover do
let(:gem_file_path) { "usr/bin/lib/2.5.0/gems/sample-gem/sample.rb" }
let(:source_path) { source_fixture("app/models/user.rb") }
let(:result_set) do
{
gem_file_path => {
"lines" => [nil, 1, 1, 1, nil, nil, 1, 1, nil, nil],
"branches" => {[:if, 3, 8, 6, 8, 36] => {[:then, 4, 8, 6, 8, 12] => 47, [:else, 5, 8, 6, 8, 36] => 24}}
},
source_path => {
"lines" => [nil, 1, 1, 1, nil, nil, 1, 0, nil, nil],
"branches" => {[:if, 3, 8, 6, 8, 36] => {[:then, 4, 8, 6, 8, 12] => 47, [:else, 5, 8, 6, 8, 36] => 24}}
}
}
end
subject do
SimpleCov::UselessResultsRemover.call(result_set)
end
it "Result ignore gem file path from result set" do
expect(result_set[gem_file_path]).to be_kind_of(Hash)
expect(subject).not_to have_key(gem_file_path)
end
it "still retains the app path" do
expect(subject).to have_key(source_path)
expect(subject[source_path]["lines"]).to be_kind_of(Array)
end
context "when changing coverage root" do
around do |example|
begin
previous_root_regx = SimpleCov::UselessResultsRemover.instance_variable_get(:@root_regx)
SimpleCov::UselessResultsRemover.instance_variable_set(:@root_regx, nil)
previous_root = SimpleCov.root
SimpleCov.root "lib"
example.run
ensure
SimpleCov.root previous_root
SimpleCov::UselessResultsRemover.instance_variable_set(:@root_regx, previous_root_regx)
end
end
it "ignores stuff outside of the new coverage root" do
expect(subject).to be_empty
end
end
end