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

59 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
2021-10-27 22:58:58 +00:00
expect_no_issues subject, <<-CRYSTAL
2017-11-01 13:20:04 +00:00
def valid?(x)
end
class Image
def picture?(x)
end
end
2017-11-23 17:58:59 +00:00
def allow_this_picture?
end
2021-10-27 22:58:58 +00:00
CRYSTAL
2017-11-01 13:20:04 +00:00
end
it "fails if predicate name is wrong" do
2021-10-27 22:58:58 +00:00
expect_issue subject, <<-CRYSTAL
2017-11-01 13:20:04 +00:00
def is_valid?(x)
2021-10-27 22:58:58 +00:00
# ^^^^^^^^^^^^^^ error: Favour method name 'valid?' over 'is_valid?'
2017-11-01 13:20:04 +00:00
end
2021-10-27 22:58:58 +00:00
CRYSTAL
2017-11-01 13:20:04 +00:00
end
it "reports rule, pos and message" do
s = Source.new %q(
class Image
def is_valid?(x)
2017-11-01 13:20:04 +00:00
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(
"Favour method name 'valid?' over 'is_valid?'")
2017-11-01 13:20:04 +00:00
end
it "ignores if alternative name isn't valid syntax" do
2021-10-27 22:58:58 +00:00
expect_no_issues subject, <<-CRYSTAL
class Image
def is_404?(x)
true
end
end
2021-10-27 22:58:58 +00:00
CRYSTAL
end
2017-11-01 13:20:04 +00:00
end
end