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
|
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
|
||||||
|
|
Loading…
Reference in a new issue