我嘗試測驗我的郵件程式,但.count我的 .Mailer.rb
def prices_mailer(recipient, prices, sender)
@sender = sender.fullname
email = recipient.email
@name = recipient.fullname
@prices = prices
@prices_count = @prices.count
@subject = 'test'
set_meta_data(__method__)
mail(to:email, subject: @subject, from: sender)
end
當我嘗試使用 rspec 進行測驗時,這就是我正在做的
describe 'prices_mailer' do
let(:price) { create(:price) }
let(:recipient) { '[email protected]' }
let(:sender) { '[email protected]' }
let(:mail) { described_class.prices_mailer(recipient, price, sender_email) }
end
it 'renders the headers' do
expect(mail.subject).to eq('test')
end
當我運行規范時,出現以下錯誤:
NoMethodError: undefined method count for #<Price
有誰知道如何解決這個問題?
uj5u.com熱心網友回復:
您的郵件程式需要一個陣列或 ActiveRecord 關系作為第二個引數:
def prices_mailer(recipient, prices, sender)
引數名稱是復數,您正在呼叫#count它。
但是您的規格正在傳遞單一價格:
described_class.prices_mailer(recipient, price, sender_email)
要么更新您的規格以發送陣列:
described_class.prices_mailer(recipient, [price], sender_email)
或更新您的郵件以處理單一價格:
def prices_mailer(recipient, prices, sender)
prices = Array(prices)
#...
Array(prices)將處理陣列,AR 關系,單個值,... for prices。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/389843.html
