There are several options for running your tests headlessly. The first thing to consider is whether you actually need to run headless. Most options for this have limitations and require trade-offs.
Traditionally PhantomJS has been an option for running headlessly. The driver for this virtual browser has been deprecated, though, so it is no longer supported in Watir.
Perhaps the best option for running headlessly is using the Headless gem. The biggest limitation for this is that it only works on Unix based systems. It is the actual browser run in a virtual GUI. This is a great option for using a real world browser, albeit on a minimally used platform.
Code for the before hook:
Code for the after hook:
Browser specific options
Both Chrome and Firefox have implemented headless modes for their browsers that work on all platforms. Recognize that this option does not include all of the browser code, so not all of the browser features are implemented, and this will not be an exact replication of what a user will see in a real browser.