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
CODE
CODE
describe CyclomaticComplexity do
it "passes for empty methods" do
source = Source.new %(
expect_no_issues subject, <<-CRYSTAL
def hello
end
)
subject.catch(source).should be_valid
CRYSTAL
end
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")
subject.catch(source).should_not be_valid
rule.catch(source).should_not be_valid
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.end_location.to_s.should eq "source.cr:1:9"
issue.message.should eq "Cyclomatic complexity too high [8/5]"
end
it "doesn't report an issue for an increased threshold" do
subject.max_complexity = 100
source = Source.new(complex_method, "source.cr")
subject.catch(source).should be_valid
rule = CyclomaticComplexity.new
rule.max_complexity = 100
expect_no_issues rule, complex_method
end
end
end