Rails 电子邮件测试失败
Rails email test fails
我有以下邮件程序:
class RewardMailer < ActionMailer::Base
default from: 'dude@example.com'
def invoice_due(invoice_info)
@btc_address = invoice_info.btc_address
@alice = invoice_info.alice
@subject = invoice_info.subject
mail to: @alice, subject: @subject
end
end
和运行以下测试:
class RewardMailerTest < ActionMailer::TestCase
test 'invoice_due' do
btc_address = '1BITCOINkkkkkkkkkkkk'
mailman = 'dude@example.com'
ali = 'ali@example.com'
subj = 'I Vooshed my website'
mail = RewardMailer.invoice_due(
alice: ali,
subject: subj,
btc_address: btc_address
)
assert_equal subj, mail.subject
assert_equal [ali], mail.to
assert_equal [mailman], mail.from
end
end
给我以下烦人的错误:
ERROR["test_invoice_due", RewardMailerTest, 2015-12-20 16:27:13 +0500]
test_invoice_due#RewardMailerTest (1450610833.82s)
NoMethodError: NoMethodError: undefined method `btc_address' for #<Hash:0x00000005307348>
app/mailers/reward_mailer.rb:6:in `invoice_due'
test/mailers/reward_mailer_test.rb:10:in `block in <class:RewardMailerTest>'
app/mailers/reward_mailer.rb:6:in `invoice_due'
test/mailers/reward_mailer_test.rb:10:in `block in <class:RewardMailerTest>'
我是个白痴,但有人能解释一下为什么这行不通吗?
您在测试中将哈希传递给 RewardMailer.invoice_due
方法,但在该方法的实现中您调用了 btc_address
方法,就像哈希是一个 InvoiceInfo
对象一样。
任一:
- 在您的测试中创建一个 InvoiceInfo 对象并将其传递给
invoice_due
i = InvoiceInfo.new(btc_address: "address_here")
RewardMailer.invoice_due(i)
- 或修改您的方法以访问散列中的
btc_address
键
invoice_info[:btc_address]
我有以下邮件程序:
class RewardMailer < ActionMailer::Base
default from: 'dude@example.com'
def invoice_due(invoice_info)
@btc_address = invoice_info.btc_address
@alice = invoice_info.alice
@subject = invoice_info.subject
mail to: @alice, subject: @subject
end
end
和运行以下测试:
class RewardMailerTest < ActionMailer::TestCase
test 'invoice_due' do
btc_address = '1BITCOINkkkkkkkkkkkk'
mailman = 'dude@example.com'
ali = 'ali@example.com'
subj = 'I Vooshed my website'
mail = RewardMailer.invoice_due(
alice: ali,
subject: subj,
btc_address: btc_address
)
assert_equal subj, mail.subject
assert_equal [ali], mail.to
assert_equal [mailman], mail.from
end
end
给我以下烦人的错误:
ERROR["test_invoice_due", RewardMailerTest, 2015-12-20 16:27:13 +0500]
test_invoice_due#RewardMailerTest (1450610833.82s)
NoMethodError: NoMethodError: undefined method `btc_address' for #<Hash:0x00000005307348>
app/mailers/reward_mailer.rb:6:in `invoice_due'
test/mailers/reward_mailer_test.rb:10:in `block in <class:RewardMailerTest>'
app/mailers/reward_mailer.rb:6:in `invoice_due'
test/mailers/reward_mailer_test.rb:10:in `block in <class:RewardMailerTest>'
我是个白痴,但有人能解释一下为什么这行不通吗?
您在测试中将哈希传递给 RewardMailer.invoice_due
方法,但在该方法的实现中您调用了 btc_address
方法,就像哈希是一个 InvoiceInfo
对象一样。
任一:
- 在您的测试中创建一个 InvoiceInfo 对象并将其传递给
invoice_due
i = InvoiceInfo.new(btc_address: "address_here")
RewardMailer.invoice_due(i)
- 或修改您的方法以访问散列中的
btc_address
键invoice_info[:btc_address]