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

45 lines
913 B
Crystal
Raw Normal View History

2017-10-31 20:11:49 +00:00
require "../../spec_helper"
2017-11-07 21:50:25 +00:00
module Ameba::Rule
2017-10-31 20:11:49 +00:00
subject = UnlessElse.new
describe UnlessElse do
it "passes if unless hasn't else" do
s = Source.new %(
unless something
:ok
end
)
2017-11-01 20:05:41 +00:00
subject.catch(s).should be_valid
2017-10-31 20:11:49 +00:00
end
it "fails if unless has else" do
s = Source.new %(
unless something
:one
else
:two
end
)
2017-11-01 20:05:41 +00:00
subject.catch(s).should_not be_valid
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
error = s.errors.first
error.should_not be_nil
error.rule.should_not be_nil
error.location.to_s.should eq "source.cr:2:9"
2017-10-31 20:11:49 +00:00
error.message.should eq "Favour if over unless with else"
end
end
end