@@ -186,9 +186,49 @@ def self.from_remediation_amount(amount)
186
186
187
187
expect ( issues . length ) . to eq ( 0 )
188
188
end
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
201
+ end
202
+ end
203
+ describe 'similar2' do
204
+ before { subject.type = 'js' }
205
+ it 'returns true' do
206
+ expect(subject.js?).to be true
207
+ end
208
+ end
209
+ EORUBY
210
+
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
+ output = run_engine ( config ) . strip . split ( "\0 " ) . first . strip
221
+ json = JSON . parse ( output )
222
+
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
+ } )
228
+ end
189
229
end
190
230
191
- describe "#calculate_points(mass) " do
231
+ describe "#calculate_points" do
192
232
let ( :analyzer ) { Ruby ::Main . new ( engine_config : engine_conf ) }
193
233
let ( :base_points ) { Ruby ::Main ::BASE_POINTS }
194
234
let ( :points_per ) { Ruby ::Main ::POINTS_PER_OVERAGE }
@@ -198,9 +238,10 @@ def self.from_remediation_amount(amount)
198
238
it "calculates mass overage points" do
199
239
mass = threshold + 10
200
240
overage = mass - threshold
241
+ violation = OpenStruct . new ( mass : mass , inner_check_name : "identical-code" )
201
242
202
243
expected_points = base_points + overage * points_per
203
- points = analyzer . calculate_points ( mass )
244
+ points = analyzer . calculate_points ( violation )
204
245
205
246
expect ( points ) . to eq ( expected_points )
206
247
end
@@ -210,9 +251,10 @@ def self.from_remediation_amount(amount)
210
251
it "calculates mass overage points" do
211
252
mass = threshold - 5
212
253
overage = mass - threshold
254
+ violation = OpenStruct . new ( mass : mass , inner_check_name : "identical-code" )
213
255
214
256
expected_points = base_points + overage * points_per
215
- points = analyzer . calculate_points ( mass )
257
+ points = analyzer . calculate_points ( violation )
216
258
217
259
expect ( points ) . to eq ( expected_points )
218
260
end
@@ -222,9 +264,10 @@ def self.from_remediation_amount(amount)
222
264
it "calculates mass overage points" do
223
265
mass = threshold
224
266
overage = mass - threshold
267
+ violation = OpenStruct . new ( mass : mass , inner_check_name : "identical-code" )
225
268
226
269
expected_points = base_points + overage * points_per
227
- points = analyzer . calculate_points ( mass )
270
+ points = analyzer . calculate_points ( violation )
228
271
229
272
expect ( points ) . to eq ( expected_points )
230
273
end
0 commit comments