这是我正在try 测试的代码:
Appsignal.send_error(error) do |transaction|
transaction.set_tags({
customer_communication_id: customer_communication_id,
interaction_reason_id: interaction_reason_id,
})
end
我想测试三件事:
- 错误正在被传递.
- 该set_tag在块中被调用.
- 在设置标记调用中设置了正确的标记.
对于测试1:
expect(Appsignal).to receive(:send_error).with(an_instance_of(ActiveRecord::RecordNotFound))
这起到了预期的作用.
我try 了几种方法,但不知道如何测试2和3. 在#3上,我想用如下内容来测试标记是否正确:
hash_including(customer_communication_id: customer_communication.id, interaction_reason_id: InteractionReason::PAYMENT_REMINDER_TEXT.id)