All these useful tips (and more!) taken from http://ruby.railstutorial.org/chapters/
This is based on Rails 3.2, but should work on Rails 4.0.
(skip standard test unit and instead will use RSpec)
$ cd ~/rails_projects
$ rails new MyApp --skip-test-unit
$ cd MyApp
Edit local ./Gemfile and make sure to include important gems (rspec, capybara, spork)
Then install new gems
$ bundle update
$ bundle install
$ rails generate rspec:install
$ bundle exec spork --bootstrap
-
Edit ./spec/spec_helper.rb and move all environment (at the end of the file) in the 'prefork' block. Also include Capybara DSL.
-
Edit ./.rspec and add '--drb'
-
Start everything (spork + rails server)
$ bundle exec foreman start
$ git init
$ git add .
$ git commit -m "Initialize repository"
Setup remote - Depends on server (github, bitbucket, etc.)
$ git remote add origin [email protected]:<username>/myapp.git
Then push to remote
$ git push -u origin master
$ heroku create
$ git push heroku master
$ heroku open
$ heroku logs
Like...
$ rails generate controller MyController user task --no-test-framework
or
$ rails g model MyModel content:string model_id:integer
Can also undo 'generate' actions - need to use the exact same arguments than with 'generate'
$ rails destroy controller MyController user task
Manually generate tests
$ rails generate integration_test mycontroller_pages
And run them manually
$ bundle exec rspec spec/
Do not forget to prepare test DB and restart Spork (especially when updating routes or doing migrations)
$ bundle exec rake db:migrate
$ bundle exec rake db:test:prepare
...and stop Spork (CTRL+C) and restart it:
$ bundle exec foreman start
Needs https://github.com/maltize/sublime-text-2-ruby-tests
If using RVM, might also needs to set "check_for_rvm": true,
in '~/Library/Application\ Support/Sublime\ Text\ 2/Packages/RubyTest/RubyTest.sublime-settings'
Then from ST2, use CMD-Shift-R/T/E
shortcuts to start tests
Once in a while, run rspec spec/
from CLI to confirm that the entire test suite is still green
Output parameters in a view (in dev only)
<%= debug(params) if Rails.env.development? %>