utils/inreplace: do not allow to use empty list of files
This commit is contained in:
parent
8c6c0039ab
commit
b7b5a60f86
@ -228,6 +228,12 @@ describe Utils::Inreplace do
|
||||
|
||||
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
|
||||
expect {
|
||||
described_class.inreplace file.path, "d", "f"
|
||||
|
||||
@ -22,6 +22,8 @@ module Utils
|
||||
def inreplace(paths, before = nil, after = nil, audit_result = true)
|
||||
errors = {}
|
||||
|
||||
errors["`paths` (first) parameter"] = ["`paths` was empty"] if paths.blank?
|
||||
|
||||
Array(paths).each do |path|
|
||||
s = File.open(path, "rb", &:read).extend(StringInreplaceExtension)
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user