Skip to content

Instantly share code, notes, and snippets.

@dcyoung-dev
Last active January 28, 2022 10:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dcyoung-dev/d397405ea11f4a27045c9841b21299d6 to your computer and use it in GitHub Desktop.
Save dcyoung-dev/d397405ea11f4a27045c9841b21299d6 to your computer and use it in GitHub Desktop.
Setup script and templates for installing and configuring RSpec
require 'capybara'
require 'factory_bot'
RSpec.configure do |config|
config.include FactoryBot::Syntax::Methods
end
Shoulda::Matchers.configure do |config|
config.integrate do |with|
with.test_framework :rspec
with.library :rails
end
end
#!/usr/bin/env ruby
# frozen_string_literal: true
require 'fileutils'
# path to your application root.
APP_ROOT = File.expand_path('..', __dir__)
def system!(*args)
system(*args) || abort("\n== Command #{args} failed ==")
end
FileUtils.chdir APP_ROOT do
puts '== Adding spec dependencies =='
# === RSPEC === #
system! 'bundle add rspec-rails --group "development, test"'
system! 'bundle exec rails g rspec:install'
FileUtils.mkdir_p 'spec/support'
unless File.exist?("spec/support/time_helpers.rb")
FileUtils.cp "bin/templates/time_helpers.rb.sample", "spec/support/time_helpers.rb"
end
unless File.exist?("spec/support/translations.rb")
FileUtils.cp "bin/templates/translations.rb.sample", "spec/support/translations.rb"
end
# === FACTORY BOT === #
system! 'bundle add factory_bot_rails --group "development, test"'
FileUtils.mkdir_p 'spec/factories'
system! 'touch spec/factories/factories.rb'
unless File.exist?("spec/support/factory_bot.rb")
FileUtils.cp "bin/templates/factory_bot.rb.sample", "spec/support/factory_bot.rb"
end
# === CAPYBARA ===
system! 'bundle add capybara --group "development, test"'
unless File.exist?("spec/support/capybara.rb")
FileUtils.cp "bin/templates/capybara.rb.sample", "spec/support/capybara.rb"
end
# === FAKER ===
system! 'bundle add faker --group "development, test"'
# === SHOULDA MATCHERS ===
system! 'bundle add shoulda-matchers --group "development, test"'
unless File.exist?("spec/support/shoulda_matchers.rb")
FileUtils.cp "bin/templates/shoulda_matchers.rb.sample", "spec/support/shoulda_matchers.rb"
end
# === STANDARD ===
system! 'bundle add standard --group "development, test"'
# === I18N TASKS ===
system! 'bundle add i18n-tasks --group "development, test"'
end
RSpec.configure do |config|
config.include ActiveSupport::Testing::TimeHelpers
end
RSpec.configure do |config|
config.include AbstractController::Translation
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment