Skip to content

Instantly share code, notes, and snippets.

@tkfm-yamaguchi
Last active August 29, 2015 13:59
Show Gist options
  • Save tkfm-yamaguchi/10957928 to your computer and use it in GitHub Desktop.
Save tkfm-yamaguchi/10957928 to your computer and use it in GitHub Desktop.
Init rails 4.1
# rspec3' generator ( 'rspec:install' ) creates .spec
# with '--warnings' as default.
# That causes printing the messages like below:
#
# vendor/bundle/ruby/2.1.0/gems/celluloid-0.15.2/lib/celluloid/tasks.rb:76: warning: global variable `$CELLULOID_DEBUG' not initialized
# vendor/bundle/ruby/2.1.0/gems/guard-2.6.1/lib/guard/interactor.rb:64: warning: instance variable @enabled not initialized
#
# This is very messy especially when using guard + spring because it puts the messages continuously.
# I hate that so that remove the option.
diff --git a/.rspec b/.rspec
index 0d786ba..83e16f8 100644
--- a/.rspec
+++ b/.rspec
@@ -1,3 +1,2 @@
--color
---warnings
--require spec_helper
--- a/config/environments/development.rb
+++ b/config/environments/development.rb
@@ -34,4 +34,7 @@
# Raises error for missing translations
# config.action_view.raise_on_missing_translations = true
+
+ # Live Reload
+ config.middleware.use Rack::LiveReload
end
source 'https://rubygems.org'
gem 'rails', '4.2.3'
gem 'sqlite3'
gem 'rails_config' # define consts using YAML
gem 'therubyracer', platforms: :ruby
gem 'uglifier', '>= 1.3.0'
gem 'sass-rails', '~> 5.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'haml-rails'
gem 'jbuilder', '~> 2.0'
gem 'bootstrap-sass'
gem 'jquery-rails'
gem 'turbolinks'
gem 'simple_form'
group :doc do
gem 'sdoc', '~> 0.4.0'
end
group :development do
gem 'quiet_assets'
# Live Reload
gem 'guard-livereload', require: false
gem 'rack-livereload'
end
group :development, :test do
gem 'spring'
gem 'web-console', '~> 2.0'
gem 'hirb-unicode'
gem 'pry-rails'
gem 'pry-byebug'
gem 'better_errors'
gem 'binding_of_caller'
end
group :test do
gem 'rspec-rails'
gem 'guard-rspec'
gem 'spring-commands-rspec'
gem 'factory_girl_rails'
gem 'database_cleaner'
end
group :production do
gem 'lograge' # simplify the rails http log
end
# in config/initializers
Rails.application.configure do
config.generators do |gen|
gen.test_framework :rspec, fixture: true
gen.fixture_replacement :factory_girl,
dir: "spec/support/factories"
gen.javascript_engine :coffee
gen.stylesheet_engine :sass
gen.template_engine :haml
end
end
group :rspec do
guard :rspec, cmd: "bundle exec spring rspec" do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
# Rails example
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
watch('config/routes.rb') { "spec/routing" }
watch('app/controllers/application_controller.rb') { "spec/controllers" }
# Capybara features specs
watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
# Turnip features and steps
watch(%r{^spec/acceptance/(.+)\.feature$})
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
end
end
group :livereload do
guard 'livereload' do
watch(%r{app/views/.+\.(erb|haml|slim)$})
watch(%r{app/helpers/.+\.rb})
watch(%r{public/.+\.(css|js|html)})
watch(%r{config/locales/.+\.yml})
# Rails Assets Pipeline
watch(%r{(app|vendor)(/assets/\w+/(.+\.(css|js|html|png|jpg))).*}) { |m| "/assets/#{m[3]}" }
end
end
# terminal execution example
rails new -B -T app_name
cd app_name
# EDIT: Gemfile
bundle install --path vendor/bundle
bundle binstub rspec-core guard spring
export PATH=`pwd`/bin:$PATH
rails g simple_form:install --bootstrap
rails g rspec:install
guard init
spring binstub --all
# EDIT: .spec
# EDIT: Guardfile
# EDIT: spec/rails_helper.rb
# EDIT: config/initializers/generators.rb
# EDIT: config/environments/development.rb
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
--- a/spec/rails_helper.rb
+++ b/spec/rails_helper.rb
@@ -39,4 +39,7 @@
# the seed, which is printed after each run.
# --seed 1234
config.order = "random"
+
+ # Use factory girl for fixture
+ config.include FactoryGirl::Syntax::Methods
end
@tkfm-yamaguchi
Copy link
Author

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