2018-06-16 11:50:59 +00:00
|
|
|
require "../../../spec_helper"
|
2017-11-01 13:20:04 +00:00
|
|
|
|
2018-06-16 11:50:59 +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
|
2022-11-13 19:12:23 +00:00
|
|
|
def is_valid?(x)
|
2017-11-01 13:20:04 +00:00
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|
2017-11-07 20:02:51 +00:00
|
|
|
), "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(
|
2022-11-13 19:12:23 +00:00
|
|
|
"Favour method name 'valid?' over 'is_valid?'")
|
2017-11-01 13:20:04 +00:00
|
|
|
end
|
2018-04-12 12:52:09 +00:00
|
|
|
|
|
|
|
it "ignores if alternative name isn't valid syntax" do
|
2021-10-27 22:58:58 +00:00
|
|
|
expect_no_issues subject, <<-CRYSTAL
|
2018-04-12 12:52:09 +00:00
|
|
|
class Image
|
|
|
|
def is_404?(x)
|
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|
2021-10-27 22:58:58 +00:00
|
|
|
CRYSTAL
|
2018-04-12 12:52:09 +00:00
|
|
|
end
|
2017-11-01 13:20:04 +00:00
|
|
|
end
|
|
|
|
end
|