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

61 lines
1.3 KiB
Crystal
Raw Normal View History

require "../../../spec_helper"
2017-11-01 13:20:04 +00:00
module Ameba::Rule::Style
2017-11-01 13:20:04 +00:00
subject = PredicateName.new
describe PredicateName do
it "passes if predicate name is correct" do
s = Source.new %q(
def valid?(x)
end
class Image
def picture?(x)
end
end
2017-11-23 17:58:59 +00:00
def allow_this_picture?
end
2017-11-01 13:20:04 +00:00
)
2017-11-01 20:05:41 +00:00
subject.catch(s).should be_valid
2017-11-01 13:20:04 +00:00
end
it "fails if predicate name is wrong" do
s = Source.new %q(
def is_valid?(x)
end
)
2017-11-01 20:05:41 +00:00
subject.catch(s).should_not be_valid
2017-11-01 13:20:04 +00:00
end
it "reports rule, pos and message" do
s = Source.new %q(
class Image
def has_picture?(x)
true
end
end
), "source.cr"
2017-11-01 20:05:41 +00:00
subject.catch(s).should_not be_valid
2017-11-01 13:20:04 +00:00
2018-06-10 21:15:12 +00:00
issue = s.issues.first
issue.rule.should_not be_nil
2018-09-07 12:07:03 +00:00
issue.location.to_s.should eq "source.cr:2:3"
2018-11-24 17:38:13 +00:00
issue.end_location.to_s.should eq "source.cr:4:5"
2018-06-10 21:15:12 +00:00
issue.message.should eq(
2017-11-01 13:20:04 +00:00
"Favour method name 'picture?' over 'has_picture?'")
end
it "ignores if alternative name isn't valid syntax" do
s = Source.new %q(
class Image
def is_404?(x)
true
end
end
)
subject.catch(s).should be_valid
end
2017-11-01 13:20:04 +00:00
end
end