Rspec没有发送带有Json帖子请求的电子邮件

时间:2015-01-22 21:53:28

标签: ruby-on-rails json rspec

我的规格:

      context 'with valid data' do
        describe 'refers other users' do
          before(:each) do
            post '/shop/referrals', valid_referral_params
            ActionMailer::Base.perform_deliveries = true
            ActionMailer::Base.deliveries.clear
          end

        def valid_referral_params
          { "shop_referral"=>{"sender_email"=>"sender@hotmail.com", "receiver_email_one"=>"myfriend@hotmail.com",
          "receiver_email_two"=>"myfriendd@hotmail.com", "receiver_email_three"=>"myfriendddddd@hotmail.com"}, format: :json }
        end
      end

以下测试未通过:

  it { expect(ActionMailer::Base.deliveries.size).to eq 4 }

我发送了4封电子邮件,目前为expected 4 got 0,当我删除ActionMailer::Base.deliveries.clear时,我收到expected 4 got 12

从我的模特:

def send_notifications
  ReferralMailer.referral_sender_email(sender_email).deliver!
  reciever_email_collection.each do |email|
    ReferralMailer.referral_receiver_email(email).deliver!
  end
end

reciever_email_collection = [myfriend1@hotmail.com, myfriend2@hotmail.com, myfriend3@hotmail.com]

也有 在配置中config.action_mailer.delivery_method = :test

非常感谢任何帮助。谢谢!

1 个答案:

答案 0 :(得分:1)

我没有尝试重现这个问题,但它看起来就像你在发布请求后清理邮件队列一样。您是否尝试在post之前移动清除?