@@ -186,9 +186,49 @@ def self.from_remediation_amount(amount)
186186
187187 expect ( issues . length ) . to eq ( 0 )
188188 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
189229 end
190230
191- describe "#calculate_points(mass) " do
231+ describe "#calculate_points" do
192232 let ( :analyzer ) { Ruby ::Main . new ( engine_config : engine_conf ) }
193233 let ( :base_points ) { Ruby ::Main ::BASE_POINTS }
194234 let ( :points_per ) { Ruby ::Main ::POINTS_PER_OVERAGE }
@@ -198,9 +238,10 @@ def self.from_remediation_amount(amount)
198238 it "calculates mass overage points" do
199239 mass = threshold + 10
200240 overage = mass - threshold
241+ violation = OpenStruct . new ( mass : mass , inner_check_name : "identical-code" )
201242
202243 expected_points = base_points + overage * points_per
203- points = analyzer . calculate_points ( mass )
244+ points = analyzer . calculate_points ( violation )
204245
205246 expect ( points ) . to eq ( expected_points )
206247 end
@@ -210,9 +251,10 @@ def self.from_remediation_amount(amount)
210251 it "calculates mass overage points" do
211252 mass = threshold - 5
212253 overage = mass - threshold
254+ violation = OpenStruct . new ( mass : mass , inner_check_name : "identical-code" )
213255
214256 expected_points = base_points + overage * points_per
215- points = analyzer . calculate_points ( mass )
257+ points = analyzer . calculate_points ( violation )
216258
217259 expect ( points ) . to eq ( expected_points )
218260 end
@@ -222,9 +264,10 @@ def self.from_remediation_amount(amount)
222264 it "calculates mass overage points" do
223265 mass = threshold
224266 overage = mass - threshold
267+ violation = OpenStruct . new ( mass : mass , inner_check_name : "identical-code" )
225268
226269 expected_points = base_points + overage * points_per
227- points = analyzer . calculate_points ( mass )
270+ points = analyzer . calculate_points ( violation )
228271
229272 expect ( points ) . to eq ( expected_points )
230273 end
0 commit comments