如何单元测试我的 JSON API 资源回调已注册为after_create
,并且调用了 send_notifications,我可以expect(MyMailer).to receive(:welcome_email)
吗?
当我尝试allow
& expect
MyResource#send_notifications 或 MyMailer.welcome_email 时,他们的电话不会被跟踪。
class MyResource < BaseResource
after_create :send_notifications
def send_notifications
MyMailer.welcome_email(_model).deliver
end
end
# rspec
RSpec.describe Creem::Jpi::V1::MyResourceResource, type: :resource do
include JsonApiResourceHelpers
let(:my_resource) { create(:my_resource) }
subject { described_class.new(my_resource, {}) }
it { expect(described_class).to be < BaseResource }
describe 'callbacks' do
xit 'how do I unit test my callbacks?'
end
end