Skip to content

Instantly share code, notes, and snippets.

@koko-u
Last active December 19, 2015 06:09
Show Gist options
  • Save koko-u/5909525 to your computer and use it in GitHub Desktop.
Save koko-u/5909525 to your computer and use it in GitHub Desktop.
rails application template with RSpec and Guard
gem "i18n_generators"
gem_group :development, :test do
gem "factory_girl_rails"
gem "rspec-rails"
gem "capybara"
gem "capybara-webkit"
gem "launchy"
gem "guard-rspec"
gem "guard-livereload"
gem "rb-inotify"
gem "pry-rails"
gem "quiet_assets"
gem "spring-commands-rspec"
gem "database_cleaner"
gem "awesome_print"
end
gem_group :production do
gem 'pg'
gem 'rails_12factor'
end
insert_into_file 'Gemfile', after: "source 'https://rubygems.org'\n" do <<-'RUBY'
ruby '2.1.1'
RUBY
end
gsub_file('Gemfile', /(gem 'sqlite3')\Z/) { "$1, :group => :development" }
comment_lines 'Gemfile', /gem 'jbuilder'/
run "bundle install #{'--path=vendor/bundle' if yes?('install into vendor/bundle?')} --without production"
generate("i18n_locale", "ja")
generate("rspec:install")
run "bundle exec guard init rspec"
run "bundle exec guard init livereload"
gsub_file 'Guardfile', /(guard\s+:rspec\s+)do/, '\1,cmd: \'spring rspec\' do'
append_file 'Guardfile', 'notification :emacs'
gsub_file 'spec/spec_helper.rb', 'config.use_transactional_fixtures = true',
'config.use_transactional_fixtures = false'
add_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
add_file('spec/support/capybara_driver.rb', <<CONFIG)
RSpec.configure do |config|
config.before(:all, js: true) do
Capybara.current_driver = :webkit
end
config.after(:all, js: true) do
Capybara.use_default_driver
end
end
CONFIG
add_file('config/spring.rb', <<SPRING)
Spring.watch 'spec/factories'
SPRING
application <<-APP
config.generators do |g|
g.view_specs false
end
APP
empty_directory('spec/features')
secret_token_file = 'config/initializers/secret_token.rb'
remove_file(secret_token_file)
add_file(secret_token_file, <<"SECRET")
# Be sure to restart your server when you modify this file.
# Your secret key is used for verifying the integrity of signed cookies.
# If you change this key, all old signed cookies will become invalid!
# Make sure the secret is at least 30 characters and all random,
# no regular words or you'll be exposed to dictionary attacks.
# You can use `rake secret` to generate a secure secret key.
# Make sure your secret_key_base is kept private
# if you're sharing your code publicly.
require 'securerandom'
def secure_token
token_file = Rails.root.join('.secret')
if File.exist?(token_file)
File.read(token_file).chomp
else
token = SecureRandom.hex(64)
File.write(token_file, token)
token
end
end
#{app_name.camelize}::Application.config.secret_key_base = secure_token
SECRET
append_file '.gitignore' do <<-IGNORE
vendor/bundle
.secret
IGNORE
end
git :init
git add: "."
git commit: %Q{ -m 'initial commit' }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment