I used to prefer seeing my feature specs run in the browser but lately I’ve been preferring to run them headlessly. It’s a little faster that way and I find it a little less disruptive.
Sometimes I still find myself wanting to see a certain test in the browser though. Seeing the test run in the browser can make diagnosis of any problems much easier.
What would be ideal is if I could do something like the following. To run a spec headlessly, I could do this:
$ rspec spec/features/create_customer_spec.rb
To see the same spec run in the browser, I could do this:
$ SHOW_BROWSER=true rspec spec/features/create_customer_spec.rb
To my surprise and delight, I was able to code something up that turned my dream into reality.
Turns out the desired functionality can be implemented by creating a file called `spec/support/webdriver.rb`:
Thanks to Reddit user jrochkind for helping me improve this solution.