なんかこれすげえ詰まった・・・。

./test/test_helper.rb

ENV['RAILS_ENV'] ||= 'test'
require File.expand_path('../../config/environment', __FILE__)
require 'rails/test_help'

module ActiveSupport
  class TestCase
    DatabaseCleaner.strategy = :transaction

    setup do
      DatabaseCleaner.start
    end

    teardown do
      DatabaseCleaner.clean
      logout
    end
  end
end

def integration_test?
  defined?(post)
end

def login(user)
  return unless integration_test?
  post session_url, params: { session: { email: user.email, password: "12345678" } }
end

def logout
  return unless integration_test?
  delete session_url
end

./test/controllers/user_controller_test.rb

class UsersControllerTest < ActionDispatch::IntegrationTest
  setup do
    @activated_user = User.where_activated(true).first
    @unactivated_user = User.where_activated(false).first
  end

  test "should display activation notice" do
    login @unactivated_user

    get user_url(name: @unactivated_user.name)
    assert_response :success
    assert_select '.activation-notice', 1
  end
end

Minitest with Capybara log in method | Treehouse Community