Use issue expectation helpers in Lint::UselessConditionInWhen rule spec

This commit is contained in:
Sijawusz Pur Rahnama 2022-04-04 21:07:53 +02:00
parent c8daaf4324
commit c89d32fcf6

View file

@ -5,25 +5,24 @@ module Ameba::Rule::Lint
describe UselessConditionInWhen do describe UselessConditionInWhen do
it "passes if there is not useless condition" do it "passes if there is not useless condition" do
s = Source.new %( expect_no_issues subject, <<-CRYSTAL
case case
when utc? when utc?
io << " UTC" io << " UTC"
when local? when local?
Format.new(" %:z").format(self, io) if utc? Format.new(" %:z").format(self, io) if utc?
end end
) CRYSTAL
subject.catch(s).should be_valid
end end
it "fails if there is useless if condition" do it "fails if there is useless if condition" do
s = Source.new %( expect_issue subject, <<-CRYSTAL
case case
when utc? when utc?
io << " UTC" if utc? io << " UTC" if utc?
# ^^^^ error: Useless condition in when detected
end end
) CRYSTAL
subject.catch(s).should_not be_valid
end end
it "reports rule, location and message" do it "reports rule, location and message" do