Skip to content

Instantly share code, notes, and snippets.

@dwayne
Last active July 28, 2021 20:04
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dwayne/6e44bda8a9f28d9353ee to your computer and use it in GitHub Desktop.
Save dwayne/6e44bda8a9f28d9353ee to your computer and use it in GitHub Desktop.
Keep track of my setup for Ruby and Rails tools
install: --no-document # See http://guides.rubygems.org/command-reference/#gem-install
update: --no-document # See http://guides.rubygems.org/command-reference/#gem-update
:backtrace: true
# Refs:
# - http://guides.rubyonrails.org/rails_application_templates.html
# - http://www.rubydoc.info/github/wycats/thor/Thor/Actions
# - http://devblog.avdi.org/2012/08/31/configuring-database_cleaner-with-rails-rspec-capybara-and-selenium/
def add_extra_gems
gem_group :development, :test do
gem 'rspec-rails', '~> 3.0'
gem 'factory_girl_rails'
gem 'pry'
gem 'pry-rails'
gem 'pry-byebug'
end
gem_group :test do
gem 'shoulda-matchers', require: false
gem 'capybara'
gem 'timecop'
gem 'database_cleaner'
gem 'launchy'
end
end
def setup_rspec
generate :'rspec:install'
append_file '.rspec' do
'--format documentation'
end
run 'bundle binstubs rspec-core'
end
def setup_factory_girl_rails
file 'spec/support/factory_girl.rb', <<-CONFIG
RSpec.configure do |config|
config.include FactoryGirl::Syntax::Methods
config.before(:suite) do
FactoryGirl.lint
end
end
CONFIG
file 'spec/factories/.keep'
end
def setup_database_cleaner
file 'spec/support/database_cleaner.rb', <<-CONFIG
RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
end
config.before(:each) do
DatabaseCleaner.strategy = :transaction
end
config.before(:each, js: true) do
DatabaseCleaner.strategy = :truncation
end
config.before(:each) do
DatabaseCleaner.start
end
config.after(:each) do
DatabaseCleaner.clean
end
end
CONFIG
end
def convert_readme_to_markdown
run 'mv README.rdoc README.md'
end
def create_and_migrate_db
rake 'db:create'
rake 'db:create', env: 'test'
end
def init_git_repo
git :init
git add: '.'
git commit: '-m "Initial commit"'
end
def main
add_extra_gems
after_bundle do
setup_rspec
setup_factory_girl_rails
convert_readme_to_markdown
create_and_migrate_db
init_git_repo
end
end
main

Set up rbenv

Install rbenv:

$ git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
$ echo 'eval "$(rbenv init -)"' >> ~/.bashrc
$ . ~/.bashrc

Check if rbenv was set up:

$ type rbenv
# => "rbenv is a function"

Then install rbenv-build to manage Ruby versions:

$ git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build

Usage

$ rbenv install 2.1.2
$ rbenv global 2.1.2
@dwayne
Copy link
Author

dwayne commented Sep 13, 2014

When you update my-application-template.rb don't forget to update the link in ~/.railsrc as well.

@dwayne
Copy link
Author

dwayne commented Feb 13, 2015

My previous .railsrc

--template=https://gist.githubusercontent.com/dwayne/6e44bda8a9f28d9353ee/raw/7250f3a3d09cbd05c767c4bd54037de177c94d7f/my-application-template.rb
--database=postgresql
--skip-test-unit
--skip-bundle

@dwayne
Copy link
Author

dwayne commented Jun 16, 2015

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