|
9 | 9 | let(:constant_name) { '::TestPackage::TestClass' } |
10 | 10 | let(:package) { instance_double('Packwerk::Package', name: 'packs/test_package') } |
11 | 11 | let(:violations) { instance_double('QueryPackwerk::Violations') } |
| 12 | + let(:anonymous_source_counts) { { '::TestPackage::TestClass' => { 'example usage' => 1, 'another example' => 2 } } } |
12 | 13 | let(:anonymous_sources_with_locations) { { '::TestPackage::TestClass' => { 'example usage' => ['app/models/test.rb:1'] } } } |
13 | 14 |
|
14 | 15 | before do |
|
93 | 94 | allow(violations).to receive(:anonymous_sources_with_locations).and_return(anonymous_sources_with_locations) |
94 | 95 | end |
95 | 96 |
|
96 | | - context 'without constant name' do |
97 | | - let(:constant_name) { '' } |
98 | | - |
99 | | - it 'returns the violations list view' do |
100 | | - expect(described_class.package_todos(package_path: package_path)).to eq(<<~STRING) |
101 | | - app/models/test.rb |
102 | | - 1: example usage |
103 | | - STRING |
104 | | - end |
| 97 | + it 'returns the violations details view' do |
| 98 | + expect(described_class.package_todos(package_path: package_path, constant_name: constant_name)).to eq(<<~STRING) |
| 99 | + app/models/test.rb |
| 100 | + 1: example usage |
| 101 | + STRING |
105 | 102 | end |
106 | 103 |
|
107 | | - context 'with constant name' do |
108 | | - it 'returns the violations details view' do |
109 | | - expect(described_class.package_todos(package_path: package_path, constant_name: constant_name)).to eq(<<~STRING) |
110 | | - app/models/test.rb |
111 | | - 1: example usage |
| 104 | + context 'when no violations found' do |
| 105 | + it 'returns the no violations view' do |
| 106 | + allow(violations).to receive(:anonymous_sources_with_locations).and_return({}) |
| 107 | + expect(described_class.package_todos(package_path: package_path, constant_name: constant_name).strip).to eq(<<~STRING.strip) |
| 108 | + No violations found in "packs/test_package" for "::TestPackage::TestClass". |
| 109 | + Ensure that constant_name is given in the format of "::ConstantName" or "::ConstantName::NestedConstant". |
112 | 110 | STRING |
113 | 111 | end |
| 112 | + end |
114 | 113 |
|
115 | | - context 'when no violations found' do |
116 | | - let(:anonymous_sources_with_locations) { {} } |
| 114 | + context 'without constant name' do |
| 115 | + let(:constant_name) { '' } |
117 | 116 |
|
118 | | - it 'returns the no violations view' do |
119 | | - expect(described_class.package_todos(package_path: package_path, constant_name: constant_name).strip).to eq(<<~STRING.strip) |
120 | | - No violations found in "packs/test_package" for "::TestPackage::TestClass". |
121 | | - Ensure that constant_name is given in the format of "::ConstantName" or "::ConstantName::NestedConstant". |
122 | | - STRING |
123 | | - end |
| 117 | + it 'returns the violations list view' do |
| 118 | + allow(violations).to receive(:anonymous_source_counts).and_return(anonymous_source_counts) |
| 119 | + expect(described_class.package_todos(package_path: package_path)).to eq(<<~STRING) |
| 120 | + ::TestPackage::TestClass (3 violations) |
| 121 | + STRING |
124 | 122 | end |
125 | 123 | end |
126 | 124 |
|
|
141 | 139 | before do |
142 | 140 | allow(Chatwerk::Helpers).to receive(:all_packages).and_return([package]) |
143 | 141 | allow(package).to receive(:violations).and_return(violations) |
144 | | - allow(violations).to receive(:anonymous_sources_with_locations).and_return(anonymous_sources_with_locations) |
145 | 142 | end |
146 | 143 |
|
147 | | - context 'without constant name' do |
148 | | - let(:constant_name) { '' } |
149 | | - |
150 | | - it 'returns the violations list view' do |
151 | | - expect(described_class.package_violations(package_path: package_path)).to eq(<<~STRING) |
152 | | - app/models/test.rb |
153 | | - 1: example usage |
154 | | - STRING |
155 | | - end |
| 144 | + it 'returns the violations details view' do |
| 145 | + allow(violations).to receive(:anonymous_sources_with_locations).and_return(anonymous_sources_with_locations) |
| 146 | + expect(described_class.package_violations(package_path: package_path, constant_name: constant_name)).to eq(<<~STRING) |
| 147 | + app/models/test.rb |
| 148 | + 1: example usage |
| 149 | + STRING |
156 | 150 | end |
157 | 151 |
|
158 | | - context 'with constant name' do |
159 | | - it 'returns the violations details view' do |
| 152 | + context 'when no violations found' do |
| 153 | + it 'returns the no violations view' do |
| 154 | + allow(violations).to receive(:anonymous_sources_with_locations).and_return({}) |
160 | 155 | expect(described_class.package_violations(package_path: package_path, constant_name: constant_name)).to eq(<<~STRING) |
161 | | - app/models/test.rb |
162 | | - 1: example usage |
| 156 | + No violations found in "packs/test_package" for "::TestPackage::TestClass". |
| 157 | + Ensure that constant_name is given in the format of "::ConstantName" or "::ConstantName::NestedConstant". |
163 | 158 | STRING |
164 | 159 | end |
| 160 | + end |
165 | 161 |
|
166 | | - context 'when no violations found' do |
167 | | - let(:anonymous_sources_with_locations) { {} } |
| 162 | + context 'without constant name' do |
| 163 | + let(:constant_name) { '' } |
168 | 164 |
|
169 | | - it 'returns the no violations view' do |
170 | | - expect(described_class.package_violations(package_path: package_path, constant_name: constant_name)).to eq(<<~STRING) |
171 | | - No violations found in "packs/test_package" for "::TestPackage::TestClass". |
172 | | - Ensure that constant_name is given in the format of "::ConstantName" or "::ConstantName::NestedConstant". |
173 | | - STRING |
174 | | - end |
| 165 | + it 'returns the violations list view' do |
| 166 | + allow(violations).to receive(:anonymous_source_counts).and_return(anonymous_source_counts) |
| 167 | + expect(described_class.package_violations(package_path: package_path)).to eq(<<~STRING) |
| 168 | + ::TestPackage::TestClass (3 violations) |
| 169 | + STRING |
175 | 170 | end |
176 | 171 | end |
177 | 172 |
|
|
0 commit comments