Isaac Sloan - Setting up MiniTest for a Rails 4 App
Banner700

Setting up MiniTest for a Rails 4 App

Getting started is easy!

Add this code:

Gemfile

gem "minitest-rails", github: "blowmage/minitest-rails"
gem "minitest-reporters"

application.rb

config.generators do |g|
  g.test_framework :minitest, spec: true, fixture: true
  g.helper false
  g.view_specs false
end

$> rails g minitest:install

test_helper.rb

Rails.env = "test"
require File.expand_path("../../config/environment", __FILE__)
require "rails/test_help"
require "minitest/rails"

# 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"

require "minitest/pride"
require "minitest/reporters"
require "minitest/autorun"
class ActiveSupport::TestCase
  Minitest::Reporters.use! Minitest::Reporters::SpecReporter.new
  ActiveRecord::Migration.check_pending!
  fixtures :all

  # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order.
end

class ActionController::TestCase
  include Devise::TestHelpers
  def create_user_and_login(email: "user@example.com", password: "isaac1sloan")
    u = User.create(email: email, password: password, password_confirmation: password)
    sign_in(u) 
  end
end
October 03, 2014
rubyrailstesting
comments powered by Disqus