shard-ameba/spec/ameba/rule/style/unless_else_spec.cr

45 lines
1,011 B
Crystal
Raw Normal View History

require "../../../spec_helper"
2017-10-31 20:11:49 +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
2021-10-27 23:13:24 +00:00
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
2017-10-31 20:11:49 +00:00
end
it "reports rule, pos and message" do
s = Source.new %(
unless something
:one
else
:two
end
), "source.cr"
2017-11-01 20:05:41 +00:00
subject.catch(s).should_not be_valid
2017-10-31 20:11:49 +00:00
2018-06-10 21:15:12 +00:00
issue = s.issues.first
issue.should_not be_nil
issue.rule.should_not be_nil
2018-09-07 12:07:03 +00:00
issue.location.to_s.should eq "source.cr:1:1"
2018-11-24 17:38:13 +00:00
issue.end_location.to_s.should eq "source.cr:5:3"
2018-06-10 21:15:12 +00:00
issue.message.should eq "Favour if over unless with else"
2017-10-31 20:11:49 +00:00
end
end
end