Skip to content

Commit 2813326

Browse files
author
Will Fleming
committed
add spec for cyclomatic complexity issues
1 parent 3786ac9 commit 2813326

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed

spec/cc/engine/rubocop_spec.rb

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,46 @@ def method
161161
assert_equal location, result["location"]
162162
end
163163

164+
it "includes complete method body for cyclomatic complexity issue" do
165+
create_source_file("my_script", <<-EORUBY)
166+
#!/usr/bin/env ruby
167+
168+
def method(a,b,c,d,e,f,g)
169+
r = 1
170+
if a
171+
if !b
172+
if c
173+
if !d
174+
if e
175+
if !f
176+
(1..g).each do |n|
177+
r = (r * n) - n
178+
end
179+
end
180+
end
181+
end
182+
end
183+
end
184+
end
185+
r
186+
end
187+
EORUBY
188+
output = run_engine
189+
assert includes_check?(output, "Metrics/CyclomaticComplexity")
190+
191+
json = JSON.parse('[' + output.split("\u0000").join(',') + ']')
192+
193+
result = json.select { |i| i && i["check_name"] =~ /Metrics\/CyclomaticComplexity/ }.first
194+
location = {
195+
"path" => "my_script",
196+
"positions" => {
197+
"begin" => { "column"=>11, "line"=>3 },
198+
"end" => { "column"=>14, "line"=>21 }
199+
}
200+
}
201+
assert_equal location, result["location"]
202+
end
203+
164204
def includes_check?(output, cop_name)
165205
issues = output.split("\0").map { |x| JSON.parse(x) }
166206

0 commit comments

Comments
 (0)