ActionMailer testing ArgumentError: wrong number of arguments (0 for 1)
ActionMailer testing ArgumentError: wrong number of arguments (0 for 1)
无法弄清楚为什么 bundle exec rake test
命令会失败,但是当我手动尝试发送电子邮件时,它可以正常工作并按应有的方式显示。
错误信息:
ArgumentError:参数数量错误(0 代表 1)并突出显示
def stock_alert_email(stock)
来自 user_mailer.rb
user_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
user_mailer_test.rb
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
where I call the mail to send
UserMailer.stock_alert_email(@stock).deliver_now
当我在上面的 ^^ 行之前使用 binding.pry 时,我看到 @stock 是
[1] pry(main)> @stock
=> ["AAPL", 114.21]
问题出在这一行
email = UserMailer.stock_alert_email().deliver_now
您没有向 stock_alert_email
传递任何参数,而它需要一个参数。
无法弄清楚为什么 bundle exec rake test
命令会失败,但是当我手动尝试发送电子邮件时,它可以正常工作并按应有的方式显示。
错误信息:
ArgumentError:参数数量错误(0 代表 1)并突出显示
def stock_alert_email(stock)
来自 user_mailer.rb
user_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
user_mailer_test.rb
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
where I call the mail to send
UserMailer.stock_alert_email(@stock).deliver_now
当我在上面的 ^^ 行之前使用 binding.pry 时,我看到 @stock 是
[1] pry(main)> @stock
=> ["AAPL", 114.21]
问题出在这一行
email = UserMailer.stock_alert_email().deliver_now
您没有向 stock_alert_email
传递任何参数,而它需要一个参数。