Skip to content

Instantly share code, notes, and snippets.

@nbrandaleone
Last active March 17, 2020 18:32
Show Gist options
  • Select an option

  • Save nbrandaleone/b9e0e2497eb2bda547a71be3d1af4545 to your computer and use it in GitHub Desktop.

Select an option

Save nbrandaleone/b9e0e2497eb2bda547a71be3d1af4545 to your computer and use it in GitHub Desktop.
Rails Launching Cheatsheet

Get Launching Cheat Sheet provided by RubyThursday.com -- updated Sept. 2017 -- Includes updates from Rails 5.1

  1. Open terminal and check versions of Ruby and Rails against production server params or to make sure you are using the most recent stable versions. $ ruby -v $ rvm list $ rvm list known $ rvm install ruby 2.4.1 $ rvm list $ ruby -v $ gem install rails $ rails -v

  2. Navigate to where you want to create your app. $ cd ~/Sites

  3. Create new repo/app without unit tests and using postgres as database You need to have Postres installed first -- https://wiki.postgresql.org/wiki/Detailed_installation_guides

$ rails new {name} -T -d postgresql example: $ rails new ruby_thursday -T -d postgresql or if needing to a specific version of rails: $ rails 4.1.0 new ruby_thursday -T -d postgresql

  1. Navigate into new app $ cd ruby_thursday

  2. Set up git $ git init

  3. Set up Github and make first commit copy/paste from Github to create remote repo $ git add . $ git commit -m "Initial commit"

  4. Open app in favorite text editor. $ subl .

  5. Set Ruby version in Gemfile ruby '2.4.1'

  6. Set up preferred test and development gems

#Option 1: with 'capybara-webkit' -- you need to have QT installed first https://github.com/thoughtbot/capybara-webkit/wiki/Installing-Qt-and-compiling-capybara-webkit.

group :development, :test do
	gem 'pry'
gem 'pry-nav'
gem 'pry-rails'
gem 'rspec-rails'
gem 'factory_bot_rails'
	#other option comes with Rails -- gem 'byebug', platform: :mri
end	

group :development do
	gem 'better_errors'
gem 'binding_of_caller'
	gem 'listen'
	gem 'letter_opener'
	gem 'spring'
	gem 'spring-watcher-listen'
end

group :test do gem 'capybara-email' gem 'capybara-webkit' gem 'database_cleaner' gem 'faker' #some older RubySnacks reference 'ffaker' gem 'simple_bdd' gem 'shoulda-matchers' end

#Option 2: with 'selenium-webdriver' group :development, :test do gem 'pry' gem 'pry-nav' gem 'pry-rails' gem 'rspec-rails' gem 'factory_bot_rails' #other option comes with Rails -- gem 'byebug', platform: :mri end

group :development do
	gem 'better_errors'
gem 'binding_of_caller'
	gem 'listen'
	gem 'letter_opener'
	gem 'spring'
	gem 'spring-watcher-listen'
end

group :test do gem 'capybara-email' gem 'database_cleaner' gem 'faker' #some older RubySnacks reference 'ffaker' gem 'selenium-webdriver' gem 'simple_bdd' gem 'shoulda-matchers' end

  1. Install the gems $ bundle

  2. Create database $ rails db:create #rake db:create still works too

  3. Install rspec $ rails generate rspec:install

  4. Edit or create rails_helper.rb

#Replace with below for Option 1: with 'capybara-webkit' ENV['RAILS_ENV'] ||= 'test' require File.expand_path('../../config/environment', FILE) # Prevent database truncation if the environment is production abort("The Rails environment is running in production mode!") if Rails.env.production? require 'spec_helper' require 'rspec/rails' require 'capybara/rspec' require 'simple_bdd' require 'shoulda/matchers' Capybara.javascript_driver = :webkit

ActiveRecord::Migration.maintain_test_schema!

RSpec.configure do |config|
	config.fixture_path = "#{::Rails.root}/spec/fixtures"

	config.use_transactional_fixtures = false
	
config.before(:suite) do
	  DatabaseCleaner.strategy = :truncation
	  DatabaseCleaner.clean_with(:truncation)
	end	

	config.before(:each) do
	  DatabaseCleaner.start
	end

	config.after(:each) do
	  DatabaseCleaner.clean
	end

config.include SimpleBdd, type: :feature
	
	Shoulda::Matchers.configure do |config|
	  config.integrate do |with|
	    with.test_framework :rspec
	    with.library :rails
	  end
	end
	
	config.infer_spec_type_from_file_location!

	config.filter_rails_from_backtrace!		

end

#Replace with below for Option 2: with 'selenium-webdriver'
	#Note: if selenium-webdriver gem does not update to newest Firefox version fast enough for you
	#you can download a specific version of Firefox and configure to use that version in tests
	#example: 
		#Capybara.register_driver :selenium do |app|
			#require 'selenium/webdriver'
			#Selenium::WebDriver::Firefox::Binary.path = "/home/user/Sites/firefox46/firefox"
			#Capybara::Selenium::Driver.new(app, :browser => :firefox)
		#end
ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
# Prevent database truncation if the environment is production
abort("The Rails environment is running in production mode!") if Rails.env.production?
require 'spec_helper'
require 'rspec/rails'
require 'capybara/rspec'
require 'simple_bdd'
require 'shoulda/matchers'

ActiveRecord::Migration.maintain_test_schema!

RSpec.configure do |config|

	config.fixture_path = "#{::Rails.root}/spec/fixtures"

	config.use_transactional_fixtures = false

	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
	
	config.include SimpleBdd, type: :feature
	
	Shoulda::Matchers.configure do |config|
	  config.integrate do |with|
	    with.test_framework :rspec
	    with.library :rails
	  end
	end
	
	config.infer_spec_type_from_file_location!

	config.filter_rails_from_backtrace!	

end
  1. Commit set up $ git add . $ git commit -m "Set up app with development gems and rspec"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment