|
6 | 6 | describe Undercover::FilterSet do |
7 | 7 | let(:allow_filters) { ['*.rb'] } |
8 | 8 | let(:reject_filters) { ['*_spec.rb'] } |
9 | | - let(:simplecov_ignored_files) { ['app/lib/filtered_file.rb'] } |
| 9 | + let(:simplecov_filters) { [{file: 'app/lib/filtered_file.rb'}] } |
10 | 10 |
|
11 | | - subject(:filter_set) { described_class.new(allow_filters, reject_filters, simplecov_ignored_files) } |
| 11 | + subject(:filter_set) { described_class.new(allow_filters, reject_filters, simplecov_filters) } |
12 | 12 |
|
13 | 13 | describe '#include?' do |
14 | 14 | context 'when file is in SimpleCov ignored files' do |
|
32 | 32 | end |
33 | 33 |
|
34 | 34 | context 'with empty SimpleCov ignored files' do |
35 | | - let(:simplecov_ignored_files) { [] } |
| 35 | + let(:simplecov_filters) { [] } |
36 | 36 |
|
37 | 37 | it 'behaves like the original FilterSet' do |
38 | 38 | expect(filter_set.include?('app/models/user.rb')).to be true |
|
44 | 44 | context 'with complex glob patterns' do |
45 | 45 | let(:allow_filters) { ['*.rb', '*.rake', 'Rakefile'] } |
46 | 46 | let(:reject_filters) { ['test/*', 'spec/*'] } |
47 | | - let(:simplecov_ignored_files) { ['lib/migrations/20230101_create_users.rb'] } |
| 47 | + let(:simplecov_filters) { [{file: 'lib/migrations/20230101_create_users.rb'}] } |
48 | 48 |
|
49 | 49 | it 'correctly applies all filters' do |
50 | 50 | expect(filter_set.include?('app/models/user.rb')).to be true |
|
54 | 54 | expect(filter_set.include?('lib/migrations/20230101_create_users.rb')).to be false |
55 | 55 | end |
56 | 56 | end |
| 57 | + |
| 58 | + context 'with string and regex filters' do |
| 59 | + let(:simplecov_filters) do |
| 60 | + [ |
| 61 | + {string: 'spec/'}, |
| 62 | + {regex: '\/test\/'}, |
| 63 | + {file: 'custom_ignored.rb'}, |
| 64 | + ] |
| 65 | + end |
| 66 | + |
| 67 | + it 'correctly evaluates string filters' do |
| 68 | + expect(filter_set.include?('spec/user_spec.rb')).to be false |
| 69 | + expect(filter_set.include?('app/spec/helper.rb')).to be false |
| 70 | + end |
| 71 | + |
| 72 | + it 'correctly evaluates regex filters' do |
| 73 | + expect(filter_set.include?('app/test/unit_test.rb')).to be false |
| 74 | + expect(filter_set.include?('lib/test/integration_test.rb')).to be false |
| 75 | + end |
| 76 | + |
| 77 | + it 'correctly evaluates file filters' do |
| 78 | + expect(filter_set.include?('custom_ignored.rb')).to be false |
| 79 | + end |
| 80 | + |
| 81 | + it 'allows files not matching any filter' do |
| 82 | + expect(filter_set.include?('app/models/user.rb')).to be true |
| 83 | + end |
| 84 | + |
| 85 | + it 'handles file filter that does not match' do |
| 86 | + expect(filter_set.include?('different_file.rb')).to be true |
| 87 | + end |
| 88 | + |
| 89 | + it 'handles file filter that returns false when filepath does not match exactly' do |
| 90 | + file_filter_set = described_class.new(['*.rb'], [], [{file: 'exact_match.rb'}]) |
| 91 | + expect(file_filter_set.include?('different_file.rb')).to be true |
| 92 | + expect(file_filter_set.include?('exact_match.rb')).to be false |
| 93 | + end |
| 94 | + |
| 95 | + it 'explicitly tests file filter branch where comparison returns false' do |
| 96 | + test_filter_set = described_class.new(['*.rb'], [], [{file: 'specific_file.rb'}]) |
| 97 | + expect(test_filter_set.include?('other_file.rb')).to be true |
| 98 | + end |
| 99 | + |
| 100 | + it 'tests the false branch of file filter comparison within any loop' do |
| 101 | + multi_filter_set = described_class.new(['*.rb'], [], [ |
| 102 | + {file: 'will_not_match.rb'}, |
| 103 | + {string: 'also_will_not_match'}, |
| 104 | + ]) |
| 105 | + expect(multi_filter_set.include?('some_other_file.rb')).to be true |
| 106 | + end |
| 107 | + |
| 108 | + it 'specifically tests file filter false return in isolation' do |
| 109 | + isolated_filter_set = described_class.new(['*.rb'], [], [{file: 'exact_name.rb'}]) |
| 110 | + expect(isolated_filter_set.include?('totally_different.rb')).to be true |
| 111 | + expect(isolated_filter_set.include?('exact_name.rb')).to be false |
| 112 | + end |
| 113 | + |
| 114 | + it 'forces file filter false evaluation by using non-matching filename' do |
| 115 | + force_false_set = described_class.new(['*.rb'], [], [{file: 'specific_file.rb'}]) |
| 116 | + expect(force_false_set.include?('different_file.rb')).to be true |
| 117 | + end |
| 118 | + |
| 119 | + it 'tests the elsif branch condition itself with falsy file value' do |
| 120 | + falsy_filter_set = described_class.new(['*.rb'], [], [ |
| 121 | + {file: nil}, |
| 122 | + {file: ''}, |
| 123 | + {string: 'will_not_match'}, |
| 124 | + ]) |
| 125 | + expect(falsy_filter_set.include?('any_file.rb')).to be true |
| 126 | + end |
| 127 | + end |
57 | 128 | end |
58 | 129 | end |
0 commit comments