2018-06-16 11:50:59 +00:00
|
|
|
require "../../../spec_helper"
|
2017-10-31 20:11:49 +00:00
|
|
|
|
2018-06-16 11:50:59 +00:00
|
|
|
module Ameba::Rule::Style
|
2017-10-31 20:11:49 +00:00
|
|
|
subject = UnlessElse.new
|
|
|
|
|
|
|
|
describe UnlessElse do
|
|
|
|
it "passes if unless hasn't else" do
|
2021-10-27 23:13:24 +00:00
|
|
|
expect_no_issues subject, <<-CRYSTAL
|
2017-10-31 20:11:49 +00:00
|
|
|
unless something
|
|
|
|
:ok
|
|
|
|
end
|
2021-10-27 23:13:24 +00:00
|
|
|
CRYSTAL
|
2017-10-31 20:11:49 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it "fails if unless has else" do
|
2022-12-19 14:27:20 +00:00
|
|
|
source = expect_issue subject, <<-CRYSTAL
|
2017-10-31 20:11:49 +00:00
|
|
|
unless something
|
2021-10-27 23:13:24 +00:00
|
|
|
# ^^^^^^^^^^^^^^ error: Favour if over unless with else
|
2017-10-31 20:11:49 +00:00
|
|
|
:one
|
|
|
|
else
|
|
|
|
:two
|
|
|
|
end
|
2021-10-27 23:13:24 +00:00
|
|
|
CRYSTAL
|
2022-12-19 14:27:20 +00:00
|
|
|
|
|
|
|
expect_correction source, <<-CRYSTAL
|
|
|
|
if something
|
|
|
|
:two
|
|
|
|
else
|
|
|
|
:one
|
|
|
|
end
|
|
|
|
CRYSTAL
|
2017-10-31 20:11:49 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|