ruby 当测试一个邮件方法时,如何在rspec中传递参数?

a64a0gku  于 2022-11-04  发布在  Ruby
关注(0)|答案(1)|浏览(189)
expect(UserMailer).to receive(UserMailer.addon_purchased).with(event_order_id: @event_order.id)

我正在使用上面的代码。我需要做哪些更改才能使其正常工作?
我的邮件方法

@event_order = EventOrder.find(params[:event_order_id])

    # TECH DEBT: why is .first relevant?
    @ticket = @event_order.addons.first.event_ticket
    if @ticket.blank?
      Rails.logger.error "ticket purchased but no ticket found for Order# - #{@event_order.id}"
      raise StandardError.new("ticket not found")
    end
lnvxswe2

lnvxswe21#

假设addon_purchased是一个类方法,您需要修改代码,如下所示

expect(UserMailer).to receive(:addon_purchased).with(event_order_id: @event_order.id)

参考:https://relishapp.com/rspec/rspec-mocks/docs/basics/expecting-messages

相关问题