brew search

brainless cherries My friend Stephen’s photo of a beer that we shared, one that was gifted by another friend, Etay

There are a number of websites that allow you to search for Homebrew packages, such as Braumeister. With Homebrew itself, this is done with brew search:

brew search didn’t have an integration test when I found it. My new test boosted its coverage from 16% to 71% (yay), though a big chunk of its behavior still remains untested (boo). Oh well. In the new test, a formula file is written to the Homebrew/homebrew-core tap (in the exact same way that it’s done in several other integration tests, e.g., for brew home and brew log). As is done in the test for brew desc, it makes the same assertions that the desc_cache.json file is created during the course of the test (this time, when the --desc flag is passed to brew search). It also asserts that testball (the test formula file) is a search result for these four calls to brew search:

brew search
brew search testball
brew search homebrew/homebrew-core/testball
brew search --desc Some test

It then proceeds to test these lines in cmd/search.rb. Like brew home, brew search employs Homebrew’s exec_browser utility method to navigate your web browser to the desired path. An efficient, DRY way to test the six different flags is to create a single hash and then iterate over the hash to make the relevant assertions: