utils/inreplace: do not allow to use empty list of files

This commit is contained in:
Alexander Bayandin 2019-11-20 19:10:15 +00:00
parent 8c6c0039ab
commit b7b5a60f86
2 changed files with 8 additions and 0 deletions

View File

@ -228,6 +228,12 @@ describe Utils::Inreplace do
after { file.unlink } after { file.unlink }
it "raises error if there are no files given to replace" do
expect {
described_class.inreplace [], "d", "f"
}.to raise_error(Utils::InreplaceError)
end
it "raises error if there is nothing to replace" do it "raises error if there is nothing to replace" do
expect { expect {
described_class.inreplace file.path, "d", "f" described_class.inreplace file.path, "d", "f"

View File

@ -22,6 +22,8 @@ module Utils
def inreplace(paths, before = nil, after = nil, audit_result = true) def inreplace(paths, before = nil, after = nil, audit_result = true)
errors = {} errors = {}
errors["`paths` (first) parameter"] = ["`paths` was empty"] if paths.blank?
Array(paths).each do |path| Array(paths).each do |path|
s = File.open(path, "rb", &:read).extend(StringInreplaceExtension) s = File.open(path, "rb", &:read).extend(StringInreplaceExtension)