Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4569304
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T19:12:00+00:00 2026-05-21T19:12:00+00:00

I have the following RSpec test for my UserMailer class: require spec_helper describe UserMailer

  • 0

I have the following RSpec test for my UserMailer class:

require "spec_helper"

describe UserMailer do
  it "should send welcome emails" do
    ActionMailer::Base.deliveries.should be_empty
    user = Factory(:user)
    UserMailer.welcome_email(user).deliver
    ActionMailer::Base.deliveries.should_not be_empty
  end
end

This test passed the first time, but failed the second time I ran it. After doing a little bit of debugging, it appears that the 1st test added an item to the ActionMailer::Base.deliveries array and that item never got cleared out. That causes the first line in the test to fail since the array is not empty.

What’s the best way to clear out the ActionMailer::Base.deliveries array after an RSpec test?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T19:12:01+00:00Added an answer on May 21, 2026 at 7:12 pm
    RSpec.describe UserMailer do
      before do
        # ActionMailer::Base.deliveries is a regular array
        ActionMailer::Base.deliveries = []
    
        # or use ActionMailer::Base.deliveries.clear
      end
    
      it "sends welcome email" do
        user = create(:user)
        UserMailer.welcome_email(user).deliver_now
        expect(ActionMailer::Base.deliveries).to be_present
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following request rspec test: describe CRUD do it should list users
I have the following RSpec example which is passing: describe UsersController do it should
I have following Rspec test: describe Productlimit do before(:each) do @productlimit = Factory.create(:productlimit, :user
I am writing rspec test for my Cars class, and have a question regarding
I have the following Rspec test: it Password reset instructions do user = Factory(:user)
My rspec title test is failing with: 1) HomeController Get 'index should have the
If I have rspec test like following: context main context do before(:all) do #
I have following class. In this, Iris is another class with some attributes. public
I have following class public abstract class Rule { protected Rule() { Nodes =
I have following situation: class TextBoxCellControl : TextBox, IDataGridViewCellControl class EnhancedTextBoxCellControl : Panel, IDataGridViewCell

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.