#Rails with Rspec, Capybara (with selenium driver), FactoryGirl #
rails new my_app -T --skip-bundle
# in Gemfile
group :test do
gem 'database_cleaner'
gem 'capybara'
gem 'factory_girl_rails'
gem 'rspec-rails'
end
Bundle Install
# in config/application.rb
config.generators do |g|
g.test_framework :rspec, :views => false, :fixture => true
g.fixture_replacement :factory_girl, :dir => 'spec/factories'
end
rails generate rspec:install
# in spec/spec_helper.rb
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
# Add this to load Capybara integration:
require 'capybara/rspec'
require 'capybara/rails'
# spec/support/database_cleaner.rb
DatabaseCleaner.strategy = :truncation
RSpec.configure do |config|
config.use_transactional_fixtures = false
config.before :each do
DatabaseCleaner.start
end
config.after :each do
DatabaseCleaner.clean
end
end