Use issue expectation helpers in Lint::RandZero rule spec

This commit is contained in:
Sijawusz Pur Rahnama 2022-04-04 21:14:45 +02:00
parent c58d4cc65a
commit 7f85434c85

View file

@ -5,22 +5,25 @@ module Ameba::Rule::Lint
subject = RandZero.new subject = RandZero.new
it "passes if it is not rand(1) or rand(0)" do it "passes if it is not rand(1) or rand(0)" do
s = Source.new %( expect_no_issues subject, <<-CRYSTAL
rand(1.0) rand(1.0)
rand(0.11) rand(0.11)
rand(2) rand(2)
) CRYSTAL
subject.catch(s).should be_valid
end end
it "fails if it is rand(0)" do it "fails if it is rand(0)" do
s = Source.new "rand(0)" expect_issue subject, <<-CRYSTAL
subject.catch(s).should_not be_valid rand(0)
# ^^^^^ error: rand(0) always returns 0
CRYSTAL
end end
it "fails if it is rand(1)" do it "fails if it is rand(1)" do
s = Source.new "rand(1)" expect_issue subject, <<-CRYSTAL
subject.catch(s).should_not be_valid rand(1)
# ^^^^^ error: rand(1) always returns 0
CRYSTAL
end end
it "reports rule, location and a message" do it "reports rule, location and a message" do