Here’s how I usually setup my test environment on Rails. I’m using mainly RSpec and Capybara, so nothing new under the sun, but this should provide a mindless copy and paste to get you (mainly me) started.
First of all, the gems used. This configuration is in part taken from the book “Testing with RSpec” by Aaron Summer:
group:development,:testdogem'rspec-rails'gem'factory_girl_rails'gem'rb-fsevent',require:falseifRUBY_PLATFORM=~/darwin/i# only on OSXgem'guard-rspec'endgroup:testdogem'shoulda-matchers'gem'faker'gem'capybara'gem'poltergeist'gem'database_cleaner'# DatabaseCleaner required to test user authentication protected routesgem'launchy'# Provides the awesome save_and_open_page method in your capybara specsend
A pretty basic setup, RSpec with shoulda matchers, FactoryGirl + Faker for cool mocks and Capybara with Poltergeist as webdriver.
You might want to install PhantomJS (used by Poltergeist). In Mac OSX you can just use brew:
brew install phantomjs
With that out of the way the next step is to setup RSpec
rails g rspec:install
I like to customize rspec with the dotted (or the documentation if I’m feeling verbose) and colored notation by adding a .rspec file.
This sets up DatabaseCleaner and the webdriver for Capybara. It also tells RSpec to skip tests marked as :slow.
Almost there, now it’s time to setup a couple of tools that makes testing less cumbersome.
First of all, let’s setup Guard.
guard init rspec
… and that’s about it.
Let’s finish off by configuring Zeus if needed (or wanted). That’s pretty straightforward, we just need to change the test environment command in the zeus.json generated by zeus init: