Use issue expectation helpers in Lint::EmptyLoop rule spec

This commit is contained in:
Sijawusz Pur Rahnama 2022-04-04 21:23:17 +02:00
parent 3cbb388393
commit 5283ae4a96

View file

@ -5,7 +5,7 @@ module Ameba::Rule::Lint
subject = EmptyLoop.new
it "does not report if there are not empty loops" do
s = Source.new %(
expect_no_issues subject, <<-CRYSTAL
a = 1
while a < 10
@ -19,54 +19,50 @@ module Ameba::Rule::Lint
loop do
a += 1
end
)
subject.catch(s).should be_valid
CRYSTAL
end
it "reports if there is an empty while loop" do
s = Source.new %(
expect_issue subject, <<-CRYSTAL
a = 1
while true
# ^^^^^^^^ error: Empty loop detected
end
)
subject.catch(s).should_not be_valid
CRYSTAL
end
it "doesn't report if while loop has non-literals in cond block" do
s = Source.new %(
expect_no_issues subject, <<-CRYSTAL
a = 1
while a = gets.to_s
# nothing here
end
)
subject.catch(s).should be_valid
CRYSTAL
end
it "reports if there is an empty until loop" do
s = Source.new %(
expect_issue subject, <<-CRYSTAL
do_something
until false
# ^^^^^^^^^ error: Empty loop detected
end
)
subject.catch(s).should_not be_valid
CRYSTAL
end
it "doesn't report if until loop has non-literals in cond block" do
s = Source.new %(
expect_no_issues subject, <<-CRYSTAL
until socket_open?
end
)
subject.catch(s).should be_valid
CRYSTAL
end
it "reports if there an empty loop" do
s = Source.new %(
expect_issue subject, <<-CRYSTAL
a = 1
loop do
# ^^^^^ error: Empty loop detected
end
)
subject.catch(s).should_not be_valid
CRYSTAL
end
it "reports rule, message and location" do