2019-01-12 21:19:00 +00:00
|
|
|
require "../spec_helper"
|
|
|
|
|
|
|
|
module Ameba
|
|
|
|
struct GlobUtilsClass
|
|
|
|
include GlobUtils
|
|
|
|
end
|
|
|
|
|
|
|
|
subject = GlobUtilsClass.new
|
|
|
|
current_file_basename = File.basename(__FILE__)
|
|
|
|
current_file_path = "spec/ameba/#{current_file_basename}"
|
|
|
|
|
|
|
|
describe GlobUtils do
|
|
|
|
describe "#find_files_by_globs" do
|
|
|
|
it "returns a file by globs" do
|
|
|
|
subject.find_files_by_globs(["**/#{current_file_basename}"])
|
|
|
|
.should eq [current_file_path]
|
|
|
|
end
|
|
|
|
|
|
|
|
it "returns files by globs" do
|
|
|
|
subject.find_files_by_globs(["**/*_spec.cr"])
|
|
|
|
.should contain current_file_path
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't return rejected globs" do
|
|
|
|
subject
|
|
|
|
.find_files_by_globs(["**/*_spec.cr", "!**/#{current_file_basename}"])
|
|
|
|
.should_not contain current_file_path
|
|
|
|
end
|
2020-04-19 08:52:15 +00:00
|
|
|
|
|
|
|
it "doesn't return duplicated globs" do
|
|
|
|
subject
|
|
|
|
.find_files_by_globs(["**/*_spec.cr", "**/*_spec.cr"])
|
|
|
|
.count(current_file_path)
|
|
|
|
.should eq 1
|
|
|
|
end
|
2019-01-12 21:19:00 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "#expand" do
|
|
|
|
it "expands globs" do
|
|
|
|
subject.expand(["**/#{current_file_basename}"])
|
|
|
|
.should eq [current_file_path]
|
|
|
|
end
|
2020-04-19 08:52:15 +00:00
|
|
|
|
|
|
|
it "does not list duplicated files" do
|
|
|
|
subject.expand(["**/#{current_file_basename}", "**/#{current_file_basename}"])
|
|
|
|
.should eq [current_file_path]
|
|
|
|
end
|
2023-07-26 13:11:07 +00:00
|
|
|
|
|
|
|
it "raises an ArgumentError when the glob doesn't match any files" do
|
|
|
|
expect_raises(ArgumentError, "No files found matching foo/*") do
|
|
|
|
subject.expand(["foo/*"])
|
|
|
|
end
|
|
|
|
end
|
2019-01-12 21:19:00 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|