Testing after_save hooks in Rails 4.2 with MiniTest
A valid approach would be check if NotificationMailer.team_invitation was called. In order to get this job done, you'll need first of all change this NotificationMailer.team_invitation hard-coded call to something injected. Something like this:

class TeamMembership &lt; ActiveRecord::Base
  # other methods

  after_create :invite_user_to_team!

  def notification_method(notification_service = NotificationMailer)
    @notification = notification_service
  end

  private
  def invite_user_to_team!
    @notification.team_invitation(team, user)
    nil
  end
end


Now, you can create an expectation over NotificationMailer. Inside your test, you can define your mock and define its behavior:

class TeamMemberTest &lt; ActiveSupport::TestCase
  def test_after_create_new_team_member_it_should_be_notified
    notification = Minitest::Mock.new
    notification.expects(:team_invitation).with(team, user).once
    # your TeamMember class working to create new
  end
end


I hope it helps :)