Skip to content

Instantly share code, notes, and snippets.

@beneggett
Last active December 26, 2015 09:19
Show Gist options
  • Save beneggett/7128625 to your computer and use it in GitHub Desktop.
Save beneggett/7128625 to your computer and use it in GitHub Desktop.
MiniTest Instructions

Install needed Gems

Gemfile

group :development do
  gem 'powder'
  gem 'pry-rails'
  gem 'better_errors'
  gem 'binding_of_caller'
  gem 'meta_request'
  gem 'xray-rails'
  gem 'letter_opener'
  gem 'guard'   # Use `guard init` to setup
  gem 'rb-fsevent', require: false
  gem 'guard-pow' 
  gem 'guard-minitest'
  gem 'guard-livereload' 
  gem "rack-livereload" # Need to put `config.middleware.use Rack::LiveReload` in your config/environments/development.rb file
  gem 'ruby_gntp'
end

group :development, :test do
  gem "minitest-rails", github: 'blowmage/minitest-rails'
  gem "factory_girl_rails", ">= 4.2.0"
  gem 'ffaker'
  # gem "email_spec"
end

Go through install instructions for each gem

Test your models

  • Make sure your test DB exists, there are several ways of preparing it, you want to make sure it's created and migrated to the latest.

You should only need to do one of these three:

rake db:test:prepare
rake db:test:load
RAILS_ENV=test rake db:migrate

Create a User Test

  • Setup your User factory (use ffaker if desired)

  • Use TDD approach to write tests for your existing features

  • (Optional) Use TDD to write new features

** Test validations, callbacks, methods (don't worry about the after_create: :send_welcome_email)

Create a Message Test

  • Repeat steps above for message test

test_helper:

ENV["RAILS_ENV"] = "test"
require File.expand_path("../../config/environment", __FILE__)
require "rails/test_help"
require "minitest/rails"
require "minitest/spec" # require this if you wan't spec syntax support

# To add Capybara feature tests add `gem "minitest-rails-capybara"`
# to the test group in the Gemfile and uncomment the following:
# require "minitest/rails/capybara"

# Uncomment for awesome colorful output
require "minitest/pride"

class ActiveSupport::TestCase
  include FactoryGirl::Syntax::Methods
  # Add more helper methods to be used by all tests here...
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment