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