Skip to content

Instantly share code, notes, and snippets.

@JStans12
Last active January 6, 2017 03:17
Show Gist options
  • Save JStans12/86963b733db3060ed276f35447615253 to your computer and use it in GitHub Desktop.
Save JStans12/86963b733db3060ed276f35447615253 to your computer and use it in GitHub Desktop.
Rails_The_Way_I_Like_it

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 }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment