Skip to content

Instantly share code, notes, and snippets.

@ychubachi
Forked from samnang/rails31init.md
Last active December 11, 2015 15:28
Show Gist options
  • Save ychubachi/4620703 to your computer and use it in GitHub Desktop.
Save ychubachi/4620703 to your computer and use it in GitHub Desktop.
Rails 3.2 with Haml, Simple Form, Bootstrap, Rspec, Cucumber, Factory Girl, Database Cleaner, Spork, and Guard

Install Rails 3.2.11 and Bundler (2013-01-24)

gem install rails bundler

Generate new app, skipping Test::Unit file generation

rails new my_app -T --skip-bundle

Set up Gemfile

Put this in the Gemfile.

gem 'haml-rails'
gem 'simple_form'

group :development, :test do
  gem 'thin'
  gem "rspec-rails",        :git => "git://github.com/rspec/rspec-rails.git"
  gem "rspec",              :git => "git://github.com/rspec/rspec.git"
  gem "rspec-core",         :git => "git://github.com/rspec/rspec-core.git"
  gem "rspec-expectations", :git => "git://github.com/rspec/rspec-expectations.git"
  gem "rspec-mocks",        :git => "git://github.com/rspec/rspec-mocks.git"
  gem 'rspec-instafail'
  gem 'cucumber-rails', :require => false
  gem 'webrat'
  gem 'capybara'
  gem 'factory_girl_rails'
  gem 'database_cleaner'
  gem 'rb-fsevent'
  gem 'growl'
  gem 'rb-inotify', '~> 0.8.8'
  gem 'guard-rails'
  gem 'guard-bundler'
  gem 'guard-migrate'
  gem 'guard-spork'
  gem 'guard-rspec'
  gem 'guard-cucumber'
  gem 'pry-rails'
end

I live on edge of rspec because cucumber-rails had a side effect to rspec gem at this moment. I could not run rake db:migrate.

Install our gems, and scope them to our app

bundle install --path vendor

Use this for all subsequent ````bundle install``` commands. Why? http://ryan.mcgeary.org/2011/02/09/vendor-everything-still-applies/

Configure generators to skip view spec generation, and use webrat methods/matchers

In your config/application.rb, put this:

config.generators do |g|
  g.test_framework :rspec, :view_specs => false, :webrat => true
end

run install tasks for our gems

rails g rspec:install
rails g cucumber:install --spork

Setup spork.spork --bootstrap

bundle exec spork --bootstrap

Then edit spec/spec_helper.rb and move everything into the prefork section. The prefork section will be called when every rspec runs.

Setup database cleaner for RSpec

Edit spec/spec_helper.rb.

Put this in the prefork section:

require 'database_cleaner'
DatabaseCleaner.strategy = :truncation

Put this in the each_run section:

DatabaseCleaner.clean

Factory Girl

Comment out the config.fixture_path line in spec/spec_helper.rb...the comment above implies it shouldn't be used if we're not using ActiveRecord fixtures.

RSpec Instafail

echo '--colour
--drb
--require rspec/instafail
--format RSpec::Instafail' > .rspec

The --drb is needed for spork and --colour is for color, because it's pretty.

Install simple_form with Bootstrap

rails g simple_form:install --bootstrap
wget http://twitter.github.com/bootstrap/assets/bootstrap.zip
unzip bootstrap.zip 
mv bootstrap/css/* app/assets/stylesheets/
mv bootstrap/js/* app/assets/javascripts/
mv bootstrap/img/* app/assets/images/
rm -r bootstrap bootstrap.zip

Pry

Now rails c will startup using pry. You can also add bindings.pry anyplace and your app will stop there with a pry prompt until you exit it.

See Also:

Guard

Run this commands for bundler, migrate, rspec spork:

bundle exec guard init

You may have to monkey withy our Guardfile some but the order should be right. Spork must be started before rspec.

Initialize git

git init .
git add .
git commit -a -m 'initial commit'

Generate a scaffold

rails g scaffold blog title:string article:string
rake db:migrate

Start guard

bundle exec guard
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment