Installs RSpec with FactoryBot and ShouldaMatchers configured
Used 18 times
B
Ben Morrall
Usage
Run this command in your Rails app directory in the terminal:
rails app:template LOCATION="https://railsbytes.com/script/VeKsaB"
Template Source
Review the code before running this template on your machine.
def do_bundle
# Custom bundle command ensures dependencies are correctly installed
Bundler.with_unbundled_env { run "bundle install" }
end
def edit_file(path)
File.write(path, yield(File.read(path)))
end
# Test suite
gem_group :development, :test do
gem "rspec-rails"
gem "factory_bot_rails"
gem "faker"
gem "shoulda-matchers"
end
# run "bundle install"
do_bundle
rails_command "generate rspec:install"
# factory_bot_rails
file "spec/support/factory_bot.rb", <<-CODE
RSpec.configure do |config|
config.include FactoryBot::Syntax::Methods
end
CODE
# shoulda-matchers
file "spec/support/shoulda_matchers.rb", <<-CODE
Shoulda::Matchers.configure do |config|
config.integrate do |with|
with.test_framework :rspec
with.library :rails
end
end
CODE
# require support files
uncomment_lines "spec/rails_helper.rb", /Rails\.root.+spec.+support/
# uncomment extra configuration
edit_file("./spec/spec_helper.rb") do |content|
# delete block comment wrapper
content["=begin"] = ""
content["=end"] = ""
content
end
append_to_file ".gitignore", "spec/examples.txt\n"