mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Use issue expectation helpers in Metrics::CyclomaticComplexity
rule spec
This commit is contained in:
parent
8a37d5bbe2
commit
b54f0f0738
1 changed files with 12 additions and 10 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue