@@ -187,44 +187,93 @@ def self.from_remediation_amount(amount)
187
187
expect ( issues . length ) . to eq ( 0 )
188
188
end
189
189
190
- it "respects the per-check mass thresholds" do
191
- create_source_file ( "foo.rb" , <<-EORUBY )
192
- def identical
193
- puts "identical \# {thing.bar} \# {other.fun} \# {moo ? "moo" : "cluck"}"
194
- puts "identical \# {thing.bar} \# {other.fun} \# {moo ? "moo" : "cluck"}"
195
- puts "identical \# {thing.bar} \# {other.fun} \# {moo ? "moo" : "cluck"}"
196
- end
197
- describe 'similar1' do
198
- before { subject.type = 'js' }
199
- it 'returns true' do
200
- expect(subject.ruby?).to be true
190
+ context "per-check mass thresholds" do
191
+ before do
192
+ create_source_file ( "foo.rb" , <<-EORUBY )
193
+ # identical mass of 15
194
+ def identical
195
+ puts "identical \# {thing.bar} \# {other.fun} \# {moo ? "moo" : "cluck"}"
196
+ puts "identical \# {thing.bar} \# {other.fun} \# {moo ? "moo" : "cluck"}"
201
197
end
202
- end
203
- describe 'similar2' do
204
- before { subject.type = 'js' }
205
- it 'returns true' do
206
- expect(subject.js?).to be true
198
+
199
+ # similar mass of 10
200
+ def similar1
201
+ foo.select { |f| if f.baz?; 10; end }
207
202
end
203
+
204
+ def similar2
205
+ foo.select { |f| if f.bar?; 15; end }
206
+ end
207
+ EORUBY
208
+ end
209
+
210
+ it "reports identical issues when only that threshold exceeded" do
211
+ config = CC ::Engine ::Analyzers ::EngineConfig . new ( {
212
+ "config" => {
213
+ "languages" => %w[ ruby ] ,
214
+ "checks" => {
215
+ "identical-code" => { "config" => { "threshold" => 5 } } ,
216
+ "similar-code" => { "config" => { "threshold" => 20 } } ,
217
+ } ,
218
+ } ,
219
+ } )
220
+
221
+ issues = run_engine ( config ) . strip . split ( "\0 " )
222
+ expect ( issues . length ) . to eq ( 2 )
223
+
224
+ issues . each do |issue |
225
+ expect ( JSON . parse ( issue ) [ "check_name" ] ) . to eq ( "identical-code" )
208
226
end
209
- EORUBY
227
+ end
210
228
211
- config = CC ::Engine ::Analyzers ::EngineConfig . new ( {
212
- "config" => {
213
- "languages" => %w[ ruby ] ,
214
- "checks" => {
215
- "identical-code" => { "config" => { "threshold" => 5 } } ,
216
- "similar-code" => { "config" => { "threshold" => 20 } } ,
229
+ it "reports similar issues when only that threshold exceeded" do
230
+ config = CC ::Engine ::Analyzers ::EngineConfig . new ( {
231
+ "config" => {
232
+ "languages" => %w[ ruby ] ,
233
+ "checks" => {
234
+ "identical-code" => { "config" => { "threshold" => 20 } } ,
235
+ "similar-code" => { "config" => { "threshold" => 5 } } ,
236
+ } ,
217
237
} ,
218
- } ,
219
- } )
220
- output = run_engine ( config ) . strip . split ( "\0 " ) . first . strip
221
- json = JSON . parse ( output )
238
+ } )
222
239
223
- expect ( json [ "check_name" ] ) . to eq "identical-code"
224
- expect ( json [ "location" ] ) . to eq ( {
225
- "path" => "foo.rb" ,
226
- "lines" => { "begin" => 2 , "end" => 2 } ,
227
- } )
240
+ issues = run_engine ( config ) . strip . split ( "\0 " )
241
+ expect ( issues . length ) . to eq ( 2 )
242
+
243
+ issues . each do |issue |
244
+ expect ( JSON . parse ( issue ) [ "check_name" ] ) . to eq ( "similar-code" )
245
+ end
246
+ end
247
+
248
+ it "reports similar and identical issues when both thresholds exceeded" do
249
+ config = CC ::Engine ::Analyzers ::EngineConfig . new ( {
250
+ "config" => {
251
+ "languages" => %w[ ruby ] ,
252
+ "checks" => {
253
+ "identical-code" => { "config" => { "threshold" => 5 } } ,
254
+ "similar-code" => { "config" => { "threshold" => 5 } } ,
255
+ } ,
256
+ } ,
257
+ } )
258
+
259
+ issues = run_engine ( config ) . strip . split ( "\0 " )
260
+ expect ( issues . length ) . to eq ( 4 )
261
+ end
262
+
263
+ it "reports no issues when neither threshold exceeded" do
264
+ config = CC ::Engine ::Analyzers ::EngineConfig . new ( {
265
+ "config" => {
266
+ "languages" => %w[ ruby ] ,
267
+ "checks" => {
268
+ "identical-code" => { "config" => { "threshold" => 20 } } ,
269
+ "similar-code" => { "config" => { "threshold" => 20 } } ,
270
+ } ,
271
+ } ,
272
+ } )
273
+
274
+ issues = run_engine ( config ) . strip . split ( "\0 " )
275
+ expect ( issues . length ) . to eq ( 0 )
276
+ end
228
277
end
229
278
end
230
279
0 commit comments