Fix type regression
This commit is contained in:
		
							parent
							
								
									09885cad3a
								
							
						
					
					
						commit
						cec3daf6be
					
				@ -7,7 +7,7 @@ describe Utils::Inreplace do
 | 
				
			|||||||
  let(:file) { Tempfile.new("test") }
 | 
					  let(:file) { Tempfile.new("test") }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  before do
 | 
					  before do
 | 
				
			||||||
    file.write <<~EOS
 | 
					    File.binwrite(file, <<~EOS)
 | 
				
			||||||
      a
 | 
					      a
 | 
				
			||||||
      b
 | 
					      b
 | 
				
			||||||
      c
 | 
					      c
 | 
				
			||||||
@ -52,4 +52,18 @@ describe Utils::Inreplace do
 | 
				
			|||||||
      end.to raise_error(Utils::Inreplace::Error)
 | 
					      end.to raise_error(Utils::Inreplace::Error)
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
  end
 | 
					  end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  describe "#gsub!" 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")
 | 
				
			||||||
 | 
					      end
 | 
				
			||||||
 | 
					      expect(File.binread(file)).to eq <<~EOS
 | 
				
			||||||
 | 
					        a
 | 
				
			||||||
 | 
					        f
 | 
				
			||||||
 | 
					        c
 | 
				
			||||||
 | 
					      EOS
 | 
				
			||||||
 | 
					    end
 | 
				
			||||||
 | 
					  end
 | 
				
			||||||
end
 | 
					end
 | 
				
			||||||
 | 
				
			|||||||
@ -31,10 +31,11 @@ class StringInreplaceExtension
 | 
				
			|||||||
  #
 | 
					  #
 | 
				
			||||||
  # @api public
 | 
					  # @api public
 | 
				
			||||||
  sig {
 | 
					  sig {
 | 
				
			||||||
    params(before: T.any(Regexp, String), after: String, audit_result: T::Boolean)
 | 
					    params(before: T.any(Pathname, Regexp, String), after: String, audit_result: T::Boolean)
 | 
				
			||||||
      .returns(T.nilable(String))
 | 
					      .returns(T.nilable(String))
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  def gsub!(before, after, audit_result = true) # rubocop:disable Style/OptionalBooleanParameter
 | 
					  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)
 | 
				
			||||||
    errors << "expected replacement of #{before.inspect} with #{after.inspect}" if audit_result && result.nil?
 | 
					    errors << "expected replacement of #{before.inspect} with #{after.inspect}" if audit_result && result.nil?
 | 
				
			||||||
    result
 | 
					    result
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user