ruby on rails - Clearing out ActionMailer::Base.deliveries after RSpec test -
i have following rspec test usermailer class:
require "spec_helper" describe usermailer "should send welcome emails" 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 first time, failed second time ran it. after doing little bit of debugging, appears 1st test added item actionmailer::base.deliveries array , item never got cleared out. causes first line in test fail since array not empty.
what's best way clear out actionmailer::base.deliveries array after rspec test?
since am::base.deliveries array, can initialize empty array. can rid of first check it's empty too:
describe usermailer before { actionmailer::base.deliveries = [] } "should send welcome emails" user = factory(:user) usermailer.welcome_email(user).deliver actionmailer::base.deliveries.should_not be_empty end end
Comments
Post a Comment