From 5d5c22e104b878be743204486e1dbc7388ef613c Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Mon, 7 Aug 2023 17:36:13 -0700 Subject: [PATCH] Replace integration test with unit test --- Library/Homebrew/formula.rb | 2 +- Library/Homebrew/test/dev-cmd/test_spec.rb | 36 ---------------------- Library/Homebrew/test/formula_spec.rb | 20 ++++++++++++ Library/Homebrew/utils/inreplace.rb | 2 +- 4 files changed, 22 insertions(+), 38 deletions(-) diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index d88d01ec43..99e1d208ad 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -2559,7 +2559,7 @@ class Formula before: T.nilable(T.any(Pathname, Regexp, String)), after: T.nilable(T.any(Pathname, String, Symbol)), audit_result: T::Boolean, - block: T.nilable(T.proc.params(s: StringInreplaceExtension).void), + block: T.nilable(T.proc.params(s: StringInreplaceExtension).void), ).void } def inreplace(paths, before = nil, after = nil, audit_result = true, &block) # rubocop:disable Style/OptionalBooleanParameter diff --git a/Library/Homebrew/test/dev-cmd/test_spec.rb b/Library/Homebrew/test/dev-cmd/test_spec.rb index 9bbb9dfe53..fccb80a374 100644 --- a/Library/Homebrew/test/dev-cmd/test_spec.rb +++ b/Library/Homebrew/test/dev-cmd/test_spec.rb @@ -17,40 +17,4 @@ describe "brew test" do .and not_to_output.to_stderr .and be_a_success end - - describe "using inreplace" do - it "replaces text in file", :integration_test do - install_test_formula "testball", <<~RUBY - test do - (testpath/"file.txt").write "1" - inreplace testpath/"file.txt" do |s| - s.gsub! "1", "2" - end - assert_equal "2", (testpath/"file.txt").read - end - RUBY - - expect { brew "test", "--verbose", "testball" } - .to output(/Testing testball/).to_stdout - .and not_to_output.to_stderr - .and be_a_success - end - - it "fails when assertion fails", :integration_test do - install_test_formula "testball", <<~RUBY - test do - (testpath/"file.txt").write "1" - inreplace testpath/"file.txt" do |s| - s.gsub! "1", "2" - end - assert_equal "3", (testpath/"file.txt").read - end - RUBY - - expect { brew "test", "--verbose", "testball" } - .to output(/Testing testball/).to_stdout - .and output(/Expected: "3"\n Actual: "2"/).to_stderr - .and be_a_failure - end - end end diff --git a/Library/Homebrew/test/formula_spec.rb b/Library/Homebrew/test/formula_spec.rb index 5f4a6765d4..eabdc075b2 100644 --- a/Library/Homebrew/test/formula_spec.rb +++ b/Library/Homebrew/test/formula_spec.rb @@ -464,6 +464,26 @@ describe Formula do expect { f.inreplace([]) }.to raise_error(BuildError) end + + specify "replaces text in file" do + file = Tempfile.new("test") + File.binwrite(file, <<~EOS) + ab + bc + cd + EOS + f = formula do + url "https://brew.sh/test-1.0.tbz" + end + f.inreplace(file.path) do |s| + s.gsub!("bc", "yz") + end + expect(File.binread(file)).to eq <<~EOS + ab + yz + cd + EOS + end end describe "::installed_with_alias_path" do diff --git a/Library/Homebrew/utils/inreplace.rb b/Library/Homebrew/utils/inreplace.rb index 76e7cca5e2..648aebeb93 100644 --- a/Library/Homebrew/utils/inreplace.rb +++ b/Library/Homebrew/utils/inreplace.rb @@ -41,7 +41,7 @@ module Utils before: T.nilable(T.any(Pathname, Regexp, String)), after: T.nilable(T.any(Pathname, String, Symbol)), audit_result: T::Boolean, - block: T.nilable(T.proc.params(s: StringInreplaceExtension).void), + block: T.nilable(T.proc.params(s: StringInreplaceExtension).void), ).void } def self.inreplace(paths, before = nil, after = nil, audit_result: true, &block)