Utilize Source#spec?

This commit is contained in:
Vitalii Elenhaupt 2021-02-03 17:14:03 +02:00
parent ecad80a96b
commit f8c22a6e77
No known key found for this signature in database
GPG key ID: CD0BF17825928BC0
3 changed files with 19 additions and 2 deletions

View file

@ -23,6 +23,18 @@ module Ameba
end
end
describe "#spec?" do
it "returns true if the source is a spec file" do
s = Source.new "", "./source_spec.cr"
s.spec?.should be_true
end
it "returns false if the source is not a spec file" do
s = Source.new "", "./source.cr"
s.spec?.should be_false
end
end
describe "#matches_path?" do
it "returns true if source's path is matched" do
s = Source.new "", "source.cr"

View file

@ -53,7 +53,7 @@ module Ameba::Rule::Lint
SPEC_ITEM_NAMES = %w(describe context it pending)
def test(source)
return unless source.path.ends_with?("_spec.cr")
return unless source.spec?
AST::NodeVisitor.new self, source
end

View file

@ -53,7 +53,12 @@ module Ameba
File.expand_path(path)
end
# Returns true if *filepath* matches the source's path, false if it does not.
# Returns `true` if the source is a spec file, `false` otherwise.
def spec?
path.ends_with?("_spec.cr")
end
# Returns `true` if *filepath* matches the source's path, `false` if it does not.
def matches_path?(filepath)
path == filepath || path == File.expand_path(filepath)
end