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.
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.