Ruby on rails ActionMailer测试参数错误:参数数目错误(0表示1)
无法理解为什么Ruby on rails ActionMailer测试参数错误:参数数目错误(0表示1),ruby-on-rails,rake,actionmailer,Ruby On Rails,Rake,Actionmailer,无法理解为什么bundle exec rake test命令失败,但当我手动尝试发送电子邮件时,它会正常工作并显示 错误消息: ArgumentError:参数数目错误(0代表1)并突出显示 def stock\u alert\u电子邮件(stock)fromuser\u mailer.rb def stock_alert_email(stock) @stock = stock mail(to: 'email@email.org', subject: "Stock Alert!
bundle exec rake test
命令失败,但当我手动尝试发送电子邮件时,它会正常工作并显示
错误消息:
ArgumentError:参数数目错误(0代表1)并突出显示
def stock\u alert\u电子邮件(stock)
fromuser\u mailer.rb
def stock_alert_email(stock)
@stock = stock
mail(to: 'email@email.org', subject: "Stock Alert! %s has reached %s" % [@stock[0].to_s, @stock[1].to_s])
end
test "stock_alert_email" do
email = UserMailer.stock_alert_email().deliver_now
assert_not ActionMailer::Base.deliveries.empty?
# Test the body of the sent email contains what we expect it to
assert_equal ['email@email.org'], email.from
assert_equal ['email@email.org'], email.to
assert_equal "Stock Alert! %s has reached %s" % [@stock[0].to_s, @stock[1].to_s], email.subject
assert_equal read_fixture('stock_alert_email').join, email.body.to_s
end
user\u mailer.rb
def stock_alert_email(stock)
@stock = stock
mail(to: 'email@email.org', subject: "Stock Alert! %s has reached %s" % [@stock[0].to_s, @stock[1].to_s])
end
test "stock_alert_email" do
email = UserMailer.stock_alert_email().deliver_now
assert_not ActionMailer::Base.deliveries.empty?
# Test the body of the sent email contains what we expect it to
assert_equal ['email@email.org'], email.from
assert_equal ['email@email.org'], email.to
assert_equal "Stock Alert! %s has reached %s" % [@stock[0].to_s, @stock[1].to_s], email.subject
assert_equal read_fixture('stock_alert_email').join, email.body.to_s
end
user\u mailer\u test.rb
def stock_alert_email(stock)
@stock = stock
mail(to: 'email@email.org', subject: "Stock Alert! %s has reached %s" % [@stock[0].to_s, @stock[1].to_s])
end
test "stock_alert_email" do
email = UserMailer.stock_alert_email().deliver_now
assert_not ActionMailer::Base.deliveries.empty?
# Test the body of the sent email contains what we expect it to
assert_equal ['email@email.org'], email.from
assert_equal ['email@email.org'], email.to
assert_equal "Stock Alert! %s has reached %s" % [@stock[0].to_s, @stock[1].to_s], email.subject
assert_equal read_fixture('stock_alert_email').join, email.body.to_s
end
我呼叫邮件发送的地方
UserMailer.stock_alert_email(@stock).deliver_now
当我在上面的^^行之前使用binding.pry时,我看到@stock是
[1] pry(main)> @stock
=> ["AAPL", 114.21]
问题就在这一行
email = UserMailer.stock_alert_email().deliver_now
您没有将任何参数传递给股票警报\u电子邮件
,而它需要一个参数