From 880362669b9f7fc94f8c58f005846cb91339d70f Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Fri, 4 Aug 2023 16:17:52 -0700 Subject: [PATCH] Add tests --- Library/Homebrew/test/dev-cmd/test_spec.rb | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/Library/Homebrew/test/dev-cmd/test_spec.rb b/Library/Homebrew/test/dev-cmd/test_spec.rb index fccb80a374..9bbb9dfe53 100644 --- a/Library/Homebrew/test/dev-cmd/test_spec.rb +++ b/Library/Homebrew/test/dev-cmd/test_spec.rb @@ -17,4 +17,40 @@ 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