Handle duplicated files on GlobUtils (#151)

* Handle duplicated files on GlobUtils

* Update src/ameba/glob_utils.cr

Co-Authored-By: George Dietrich <yomoejoe@gmail.com>

Co-authored-by: George Dietrich <yomoejoe@gmail.com>
This commit is contained in:
Matheus Richard 2020-04-19 05:52:15 -03:00 committed by GitHub
parent b215b34060
commit f1adf14527
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 1 deletions

View file

@ -26,6 +26,13 @@ module Ameba
.find_files_by_globs(["**/*_spec.cr", "!**/#{current_file_basename}"]) .find_files_by_globs(["**/*_spec.cr", "!**/#{current_file_basename}"])
.should_not contain current_file_path .should_not contain current_file_path
end end
it "doesn't return duplicated globs" do
subject
.find_files_by_globs(["**/*_spec.cr", "**/*_spec.cr"])
.count(current_file_path)
.should eq 1
end
end end
describe "#expand" do describe "#expand" do
@ -33,6 +40,11 @@ module Ameba
subject.expand(["**/#{current_file_basename}"]) subject.expand(["**/#{current_file_basename}"])
.should eq [current_file_path] .should eq [current_file_path]
end end
it "does not list duplicated files" do
subject.expand(["**/#{current_file_basename}", "**/#{current_file_basename}"])
.should eq [current_file_path]
end
end end
end end
end end

View file

@ -25,7 +25,7 @@ module Ameba
globs.map do |glob| globs.map do |glob|
glob += "/**/*.cr" if File.directory?(glob) glob += "/**/*.cr" if File.directory?(glob)
Dir[glob] Dir[glob]
end.flatten end.flatten.uniq!
end end
private def rejected_globs(globs) private def rejected_globs(globs)