Skip to content

Instantly share code, notes, and snippets.

@trkoch
Last active August 29, 2015 14:02
Show Gist options
  • Save trkoch/236e7a20875a13ec1542 to your computer and use it in GitHub Desktop.
Save trkoch/236e7a20875a13ec1542 to your computer and use it in GitHub Desktop.
Rails Application Template (rSpec, Capybara, Poltergeist, FactoryGirl)
remove_file("test")
gem_group :development, :test do
gem "rspec-rails", "~> 3.0.0"
gem "spring-commands-rspec"
gem "factory_girl_rails", "~> 4.0"
gem "pry-rails"
gem "pry-byebug"
gem "pry-stack_explorer"
gem "pry-rescue"
end
gem_group :test do
gem "launchy"
gem "database_cleaner"
gem "poltergeist"
gem "capybara"
end
gem "therubyracer"
gsub_file("Gemfile", /^group :development, :test do\s+end\n/m, '')
gsub_file("Gemfile", /^#.*\n/, '') # Remove comments
gsub_file("Gemfile", /\n{2,}/, "\n") # No empty lines
gsub_file("Gemfile", /'/, '"') # Double quotes
gsub_file("Gemfile", /\s+(group:)/, ' \1') # Remove excess blanks
gsub_file("Gemfile", /^source.*/, "\\0\n") # Add blank line
gsub_file("Gemfile", /^group.*/, "\n\\0") # Add blank line
gsub_file("Gemfile", /^group :test.*end/m, "\\0\n")
run "bundle install"
def run_bundle; end
APP_CONFIG = <<-CONFIG
config.generators do |g|
g.test_framework :rspec,
fixtures: true,
view_specs: false,
helper_specs: false,
routing_specs: false,
controller_specs: false,
request_specs: false
g.fixture_replacement :factory_girl, dir: "spec/factories"
end
CONFIG
application APP_CONFIG
generate :'rspec:install'
RSPEC_REQUIRE = <<-CONFIG
require 'capybara/poltergeist'
Capybara.javascript_driver = :poltergeist
CONFIG
inject_into_file "spec/rails_helper.rb", RSPEC_REQUIRE, after: "require 'rspec/rails'\n"
RSPEC_DOT = <<-CONFIG
--color
--format doc
--require spec_helper
CONFIG
remove_file ".rspec"
add_file ".rspec", RSPEC_DOT
RSPEC_CONFIG = <<-CONFIG
config.before(:suite) do
DatabaseCleaner.clean_with(:truncation)
# Lint factories
begin
DatabaseCleaner.start
FactoryGirl.lint
ensure
DatabaseCleaner.clean
end
end
config.before(:each) do
DatabaseCleaner.strategy = :transaction
end
# Use truncation strategy for tests that run in separate thread
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 FactoryGirl::Syntax::Methods
# Disable should syntax
config.expect_with :rspec do |c|
c.syntax = :expect
end
CONFIG
inject_into_file "spec/rails_helper.rb", RSPEC_CONFIG, after: "RSpec.configure do |config|\n"
comment_lines "spec/rails_helper.rb", /config\.use_transactional_fixtures/
# Add ./bin to path when direnv is installed
add_file ".envrc", %{export PATH="./bin:$PATH"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment