我正在尝试编写一个测试,我需要由预期块创建的值来编写断言。
class Identification < ApplicationRecord
include Wisper::Publisher
after_save :publish_identification_declined
private
def publish_identification_declined
if status_previously_changed? && status == "declined"
broadcast(:identification_declined, identification: self)
end
end
end
我试图做这样的事情,但不幸identification_a
的是最终没有被设置。
require "rails_helper"
RSpec.describe Identification do
it "publish event identification_declined" do
identification_a = nil
expect { identification_a = create(:identification, :declined, id: 1) }
.to broadcast(:identification_declined, identification: identification_a)
end
end
我也有一种感觉,这可能不是一个好主意。
另一种方法可能是使用instance_of
匹配器,但我不知道如何检查它是否是正确的实例。