Skip to content

Instantly share code, notes, and snippets.

@CGA1123
Created December 28, 2016 18:06
Show Gist options
  • Save CGA1123/6772774924a9dae6c8187f83e818d339 to your computer and use it in GitHub Desktop.
Save CGA1123/6772774924a9dae6c8187f83e818d339 to your computer and use it in GitHub Desktop.
Simple Rails Test Script, Resets Database, Runs RSpec, & Rubocop
#!/usr/bin/env ruby
require 'pathname'
# path to your application root.
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
Dir.chdir APP_ROOT do
test_env = 'test'
puts "Application Environment: #{test_env}"
# Resets the test database
puts "Setting Up Database..."
puts "Drop Database"
system "RAILS_ENV=#{test_env} bundle exec rake db:drop"
puts "Create Database"
system "RAILS_ENV=#{test_env} bundle exec rake db:create"
puts "Load Database Schema"
system "RAILS_ENV=#{test_env} bundle exec rake db:schema:load"
# Run the rspec testing framework
# options enabled are: --format documentation
puts "\nRun RSpec"
puts "$ RAILS_ENV=#{test_env} bundle exec rspec -f d"
system "RAILS_ENV=#{test_env} bundle exec rspec -f d"
# Run Rubocop
# option enabled are: --format fuubar, --display-cop-names, --extra-details
puts "\nRun Rubocop"
puts "$ bundle exec rubocop -f fu -D -E"
system 'bundle exec rubocop -f fu -D -E'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment