mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
45 lines
925 B
Crystal
45 lines
925 B
Crystal
require "../../spec_helper"
|
|
|
|
module Ameba::Rules
|
|
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
|
|
)
|
|
subject.catch(s).should be_valid
|
|
end
|
|
|
|
it "fails if predicate name is wrong" do
|
|
s = Source.new %q(
|
|
def is_valid?(x)
|
|
end
|
|
)
|
|
subject.catch(s).should_not be_valid
|
|
end
|
|
|
|
it "reports rule, pos and message" do
|
|
s = Source.new %q(
|
|
class Image
|
|
def has_picture?(x)
|
|
true
|
|
end
|
|
end
|
|
)
|
|
subject.catch(s).should_not be_valid
|
|
|
|
error = s.errors.first
|
|
error.rule.should_not be_nil
|
|
error.pos.should eq 3
|
|
error.message.should eq(
|
|
"Favour method name 'picture?' over 'has_picture?'")
|
|
end
|
|
end
|
|
end
|