-
-
Save ml242/7756337 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# README | |
# pass in this file when creating a rails project | |
# | |
# for example: | |
# rails _3.2.14_ new awesome_app -d postgresql -m ~/rails_setup.rb | |
remove_file "README.rdoc" | |
create_file "README.md", "TODO" | |
gem_group :development, :test do | |
gem "rspec-rails" | |
gem "guard-rspec" | |
gem "capybara" | |
gem "database_cleaner" | |
gem "capybara-webkit" | |
gem "selenium-webdriver" | |
gem "jasmine" | |
gem "pry-rails" | |
gem "awesome_print" | |
end | |
gem_group :development do | |
gem "annotate" | |
gem "quiet_assets" | |
gem "binding_of_caller" | |
gem "meta_request" | |
gem "rails-erd" | |
gem "better_errors" | |
gem "terminal-notifier-guard" | |
end | |
gem 'simplecov', :require => false, :group => :test | |
gem 'thin' if yes? "Do you want to use Thin?" | |
gem 'haml-rails' if yes? "Do you want to use Haml" | |
# Rspec | |
run "bundle install" | |
generate "rspec:install" | |
generate "jasmine:install" | |
run "bundle exec guard init" | |
# Removing test directory | |
run "rm -rf test" | |
insert_into_file 'config/application.rb', :after => "require 'rails/all'\n" do | |
"if Rails.env.test? | |
require 'simplecov' | |
SimpleCov.start | |
end" | |
end | |
insert_into_file 'spec/spec_helper.rb', :after => "require 'rspec/autorun'\n" do | |
"require 'capybara/rails'" | |
end | |
create_file "spec/support/database_cleaner.rb" | |
append_to_file "spec/support/database_cleaner.rb" do <<-DATABASE_CLEANER_CONFIG | |
Capybara.javascript_driver = :webkit # Selenium works, but not as well | |
RSpec.configure do |config| | |
config.use_transactional_fixtures = false | |
# Use transactions by default | |
config.before :each do | |
DatabaseCleaner.strategy = :truncation | |
end | |
# Switch to truncation for javascript tests, but *only clean used tables* | |
config.before :each, :js => true do | |
DatabaseCleaner.strategy = :truncation, {:pre_count => true} | |
end | |
config.before :each do | |
DatabaseCleaner.start | |
end | |
config.after :each do | |
DatabaseCleaner.clean | |
end | |
end | |
DATABASE_CLEANER_CONFIG | |
end | |
remove_file "config/database.yml" | |
create_file "config/database.yml" do <<-DATABASE_YML | |
development: | |
adapter: postgresql | |
encoding: unicode | |
database: <%= File.basename(Rails.root) %>_development | |
pool: 5 | |
host: localhost | |
username: <%= ENV['PG_USERNAME'] %> | |
password: | |
test: | |
adapter: postgresql | |
encoding: unicode | |
database: <%= File.basename(Rails.root) %>_test | |
pool: 5 | |
host: localhost | |
username: <%= ENV['PG_USERNAME'] %> | |
password: | |
DATABASE_YML | |
end | |
create_file ".travis.yml" do <<-TRAVIS | |
language: ruby | |
rvm: | |
- 1.9.3 | |
before_script: | |
- "sh -e /etc/init.d/xvfb start" | |
- "export DISPLAY=:99.0" | |
- "export JASMINE_SPEC_FORMAT=documentation" | |
script: | |
- "bundle exec rake travis:run" | |
env: | |
- PG_USERNAME='postgres' | |
TRAVIS | |
end | |
if yes? "Do you want a welcome controller?" | |
generate :controller, "welcome index --no-helper --no-assets --no-controller-specs --no-view-specs" | |
route "root to: 'welcome#index'" | |
remove_file "public/index.html" | |
end | |
rakefile("testing.rake") do <<-TASK | |
namespace :travis do | |
desc "Prepare DB and run Tests" | |
task :run do | |
["db:create", "db:migrate RAILS_ENV=test", "spec", "jasmine:ci"].each do |cmd| | |
puts "Starting to run \#{cmd}..." | |
system("bundle exec rake \#{cmd}") | |
raise "\#{cmd} failed!" unless $?.exitstatus == 0 | |
end | |
end | |
end | |
namespace :spec do | |
desc "Run the code examples in spec/features" | |
task :features do | |
Rails.env = ENV['RAILS_ENV'] = 'test' | |
ENV['SPEC'] = "spec/features/**/*_spec.rb" | |
Rake::Task['spec'].invoke | |
end | |
end | |
namespace :guard do | |
desc "Start Guard" | |
task :run do | |
system("bundle exec guard") | |
end | |
end | |
TASK | |
end | |
# Remove requires trees | |
gsub_file "app/assets/javascripts/application.js", /^\/\/= require_tree .$/, "" | |
gsub_file "app/assets/stylesheets/application.css", /^*= require_tree .$/, "" | |
if yes? "Install Backbone?" | |
{ | |
json2: "https://raw.github.com/douglascrockford/JSON-js/master/json2.js", | |
handlebars: "http://builds.handlebarsjs.com.s3.amazonaws.com/handlebars-latest.js", | |
underscore: "http://underscorejs.org/underscore.js", | |
backbone: "http://backbonejs.org/backbone.js" | |
} | |
.each do |file_name, source| | |
get source, "vendor/assets/javascripts/#{file_name}.js" | |
append_to_file "app/assets/javascripts/application.js", "//= require #{file_name}\n" | |
end | |
create_file "app/assets/javascripts/app.js" | |
append_to_file "app/assets/javascripts/application.js", "//= require app\n" | |
end | |
["rake db:create", "rake db:migrate", "RAILS_ENV=test rake db:migrate"].each do |cmd| | |
run cmd | |
end | |
if yes? "git init?" | |
git :init | |
git add: ".", commit: "-m 'new rails project'" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment