Replace integration test with unit test
This commit is contained in:
		
							parent
							
								
									2b29c498fa
								
							
						
					
					
						commit
						5d5c22e104
					
				@ -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
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
 | 
			
		||||
@ -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)
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user