2017-11-01 13:20:04 +00:00
|
|
|
require "../../spec_helper"
|
|
|
|
|
2017-11-07 21:50:25 +00:00
|
|
|
module Ameba::Rule
|
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-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
|
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
|
|
|
|
|
|
|
error = s.errors.first
|
|
|
|
error.rule.should_not be_nil
|
2017-11-07 20:02:51 +00:00
|
|
|
error.location.to_s.should eq "source.cr:3:11"
|
2017-11-01 13:20:04 +00:00
|
|
|
error.message.should eq(
|
|
|
|
"Favour method name 'picture?' over 'has_picture?'")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|