diff --git a/Library/Homebrew/test/utils/inreplace_spec.rb b/Library/Homebrew/test/utils/inreplace_spec.rb index 4283323f2a..20c91672d9 100644 --- a/Library/Homebrew/test/utils/inreplace_spec.rb +++ b/Library/Homebrew/test/utils/inreplace_spec.rb @@ -57,7 +57,7 @@ describe Utils::Inreplace do it "substitutes pathname within file" do # For a specific instance of this, see https://github.com/Homebrew/homebrew-core/blob/a8b0b10/Formula/loki.rb#L48 described_class.inreplace(file.path) do |s| - s.gsub!(Pathname("b"), "f") + s.gsub!(Pathname("b"), Pathname("f")) end expect(File.binread(file)).to eq <<~EOS a diff --git a/Library/Homebrew/utils/string_inreplace_extension.rb b/Library/Homebrew/utils/string_inreplace_extension.rb index 92fc0ecb43..4c4d4917d4 100644 --- a/Library/Homebrew/utils/string_inreplace_extension.rb +++ b/Library/Homebrew/utils/string_inreplace_extension.rb @@ -31,12 +31,12 @@ class StringInreplaceExtension # # @api public sig { - params(before: T.any(Pathname, Regexp, String), after: String, audit_result: T::Boolean) + params(before: T.any(Pathname, Regexp, String), after: T.any(Pathname, String), audit_result: T::Boolean) .returns(T.nilable(String)) } def gsub!(before, after, audit_result = true) # rubocop:disable Style/OptionalBooleanParameter before = before.to_s if before.is_a?(Pathname) - result = inreplace_string.gsub!(before, after) + result = inreplace_string.gsub!(before, after.to_s) errors << "expected replacement of #{before.inspect} with #{after.inspect}" if audit_result && result.nil? result end