我遇到了我的測試一個Rspec的測試:NotificationMailer.user_notification(個體經營)返回nil
Rspec的
it 'should call send_email_notification on NotificationMailer' do
expect(NotificationMailer).to receive(:user_notification).with(an_instance_of(User))
FactoryGirl.create(:user, shop: Shop.new)
end
方法麻煩:
def send_email_notification
if user? && self.shop.email_notifications
NotificationMailer.user_notification(self).deliver_now
end
end
未定義的方法` deliver_now'爲零:NilClass
這意味着NotificationMailer.user_notification(self)在測試期間返回nil。但是,當我在真正的本地環境中運行binding.pry時,NotificationMailer.user_notification(self)會返回適當的對象。這意味着我的測試不起作用...
你會解決什麼問題?
人,這是我收到過的最好的答案之一。謝謝 –