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

43 lines
1 KiB
Crystal
Raw Normal View History

require "../../../spec_helper"
2017-11-04 20:54:27 +00:00
module Ameba
subject = Rule::Style::MethodNames.new
2017-11-04 20:54:27 +00:00
private def it_reports_method_name(name, expected, *, file = __FILE__, line = __LINE__)
it "reports method name #{expected}", file, line do
2021-10-27 22:58:58 +00:00
rule = Rule::Style::MethodNames.new
expect_issue rule, <<-CRYSTAL, name: name, file: file, line: line
2021-10-27 22:58:58 +00:00
def %{name}; end
# ^{name} error: Method name should be underscore-cased: #{expected}, not %{name}
CRYSTAL
2017-11-04 20:54:27 +00:00
end
end
describe Rule::Style::MethodNames do
2017-11-04 20:54:27 +00:00
it "passes if method names are underscore-cased" do
2021-10-27 22:58:58 +00:00
expect_no_issues subject, <<-CRYSTAL
2017-11-04 20:54:27 +00:00
class Person
def first_name
end
def date_of_birth
end
def homepage_url
end
def valid?
end
def name
end
end
2021-10-27 22:58:58 +00:00
CRYSTAL
2017-11-04 20:54:27 +00:00
end
2021-10-27 22:58:58 +00:00
it_reports_method_name "firstName", "first_name"
it_reports_method_name "date_of_Birth", "date_of_birth"
it_reports_method_name "homepageURL", "homepage_url"
2017-11-04 20:54:27 +00:00
end
end