Generate a new project without the included testing and with a postgres database:
rails new MyApp -T --database=postgresql
Add rspec, capybara, factory_girl, launchy and database cleaner to gemfile:
group :development, :test do
gem 'rspec-rails'
gem 'capybara'
gem 'factory_girl_rails'
gem 'launchy'
gem 'database_cleaner'
end
Install gems and generate rspec files:
bundle
rails g rspec:install
Create directory and folder for factory girl:
mkdir spec/support
touch spec/support/factory_girl.rb
Add Rspec configuration to factory_girl.rb:
RSpec.configure do |config|
config.include FactoryGirl::Syntax::Methods
config.before(:suite) do
begin
DatabaseCleaner.start
FactoryGirl.lint
ensure
DatabaseCleaner.clean
end
end
end
in spec_helper.rb
require 'database_cleaner'
RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.strategy = :transaction
DatabaseCleaner.clean_with(:truncation)
end
config.around(:each) do |example|
DatabaseCleaner.cleaning do
example.run
end
end
end
Uncomment this line from rails_helper.rb
Dir[Rails.root.join('spec/support/**/*.rb')].each { |f| require f }