Use issue expectation helpers in Metrics::CyclomaticComplexity rule spec

This commit is contained in:
Sijawusz Pur Rahnama 2022-04-04 22:15:43 +02:00
parent 8a37d5bbe2
commit b54f0f0738

View file

@ -15,33 +15,35 @@ module Ameba::Rule::Metrics
end end
end end
end end
CODE CODE
describe CyclomaticComplexity do describe CyclomaticComplexity do
it "passes for empty methods" do it "passes for empty methods" do
source = Source.new %( expect_no_issues subject, <<-CRYSTAL
def hello def hello
end end
) CRYSTAL
subject.catch(source).should be_valid
end end
it "reports one issue for a complex method" do it "reports one issue for a complex method" do
subject.max_complexity = 5 rule = CyclomaticComplexity.new
rule.max_complexity = 5
source = Source.new(complex_method, "source.cr") source = Source.new(complex_method, "source.cr")
subject.catch(source).should_not be_valid rule.catch(source).should_not be_valid
issue = source.issues.first issue = source.issues.first
issue.rule.should eq subject issue.rule.should eq rule
issue.location.to_s.should eq "source.cr:1:5" issue.location.to_s.should eq "source.cr:1:5"
issue.end_location.to_s.should eq "source.cr:1:9" issue.end_location.to_s.should eq "source.cr:1:9"
issue.message.should eq "Cyclomatic complexity too high [8/5]" issue.message.should eq "Cyclomatic complexity too high [8/5]"
end end
it "doesn't report an issue for an increased threshold" do it "doesn't report an issue for an increased threshold" do
subject.max_complexity = 100 rule = CyclomaticComplexity.new
source = Source.new(complex_method, "source.cr") rule.max_complexity = 100
subject.catch(source).should be_valid
expect_no_issues rule, complex_method
end end
end end
end end