Set up rbenv
$ cd
$ git clone https://github.com/rbenv/rbenv.git ~/.rbenv
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc'
$ ~/.rbenv/bin/rbenv initFollow the instructions on how to initialize rbenv to enable shims and autocompletion.
$ source .bashrc # or restart your shell
$ type rbenv
#=> "rbenv is a function"
$ git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
$ rbenv install 2.3.1 # or whatever ruby versionSet a ruby version for your project; create a .ruby-version file at the project root:
echo '2.3.1` > .ruby-versiongem install bundlerUbuntu:
sudo apt-get install postgresqlFollow set-up instructions here
Arch Linux:
sudo pacman -S postgresqlFollow set-up instructions here
Mac OS: Use Postgres.app
rails new myappname --database=postgresql -T # use rspec insteadCheck that config/database.yml is set up correctly for postgres. Ensure that the username and password match your postgresql user. (To check the list of users, log into the postgres shell by psql -U postgres, then run \du in the shell.)
Example config/database.yml:
default: &default
adapter: postgresql
encoding: unicode
pool: 5
timeout: 5000
username: aqi
password:
development:
<<: *default
database: sample_app_development
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: sample_app_test
production:
<<: *default
database: sample_app_productionTo set up the development database:
./bin/rake db:createAdd gem 'slim-rails to your Gemfile and bundle install. Generated templates will now use slim by default.
Add gem 'simple_form' to your Gemfile and bundle install.
Add gem 'bootstrap-sass' to your Gemfile and bundle install.
Add the gems to your Gemfile and bundle install:
group :development, :test do
gem 'rspec-rails'
end
group :test do
gem "factory_girl_rails"
gem "capybara"
gem "shoulda-matchers"
endAdd the following to spec/rails_helper.rb:
# rails_helper.rb
# Keep the test and development databases in sync
# so there is no need to `rake db:test:prepare`
ActiveRecord::Migration.maintain_test_schema!
RSpec.configure do |config|
# ... default configs ...
# Make routes available in
config.include Rails.application.routes.url_helpers
# Use Capybara
config.include Capybara::DSL
# Use Shoulda-Matchers
config.include(Shoulda::Matchers::ActiveModel, type: :model)
config.include(Shoulda::Matchers::ActiveRecord, type: :model)
# Use FactoryGirl
config.include FactoryGirl::Syntax::Methods
endAdd the following to spec/spec_helper.rb:
# spec_helper.rb
RSpec.configure do |config|
# ...
# Use only the new 'expect' syntax
config.expect_with :rspec do |c|
c.syntax = :expect
end
endIf the project was generated with TestUnit, remove the test directory:
rm -rf testThen set up rspec:
rails g rspec:installCreate a binstub for the rspec command so you don't have to keep prefixing it with bundle exec:
bundle binstubs rspec-coreTo run all specs:
./bin/rspec Devise:
Add gem 'devise' to your Gemfile and bundle install
Run the generator:
rails g devise:installTo use Devise helpers in your specs, include the following in spec/rails_helper.rb:
require 'spec_helper'
require 'rspec/rails'
require 'devise'
RSpec.configure do |config|
# Use Devise helpers
config.include Devise::TestHelpers, type: :controller
config.include Devise::TestHelpers, type: :view
endSorcery:
Add gem 'sorcery' to your Gemfile and bundle install
Run the generator:
rails g sorcery:installTo use Sorcery helpers in your specs, include the following in spec/rails_helper.rb:
RSpec.configure do |config|
# Use Sorcery helpers
config.include Sorcery::TestHelpers::Rails::Controller, type: :controller
config.include Sorcery::TestHelpers::Rails::Integration, type: :feature
end