In my own work, I use Poltergeist for these tests. Poltergeist is a Ruby wrapper for the PhantomJS headless browser, so you’ll have to install PhantomJS first. I recommend using your operating system’s built-in package manager to do this, when possible. On my Mac, I use Homebrew (
brew install phantomjs). If you’re on Windows, or just not sure, download and run the installer.
group :test do # Other testing gems ... gem 'poltergeist' # Go ahead and remove selenium-webdriver, if needed end
bundle install to install the gem.
Next, configure RSpec to use it. Add the following to your spec/rails_helper.rb file. (If you’re still using RSpec 2.x, you’ll add this to spec/spec_helper.rb):
In addition to speeding up your test runs, Poltergeist provides some advanced features. I don’t use these often, but they are handy from time to time, particularly for debugging tests. I encourage you to refer to Poltergeist’s README to learn more.
I stand with the Black community against systemic racism, police violence and brutality, intolerance, and hate in the United States and worldwide. We must all demand better from our leaders, and ourselves. Stop tolerating intolerance.
While you're here, please consider making a donation to Black Girls CODE, who do great, important work to provide opportunity to underprivileged girls interested in tech, or any organization working toward equity and safety for all, not just the privileged. Thank you.
If you liked my series on practical advice for adding reliable tests to your Rails apps, check out the expanded ebook version. Lots of additional, exclusive content and a complete sample Rails application.
Ruby on Rails news and tips, and other ideas and surprises from Aaron at Everyday Rails. Delivered to your inbox on no particular set schedule.