Test event production without defining a subject
NotGrm opened this issue · 3 comments
As reported on Slack
I received a undefined method topic' for #<Model ...
error when writing come model specs in my Rails app because my model was producing Kafka events.
The source of the bug seems to be related to this line which forces me to define my test subject as a Karakfa testing consumer instead of an instance on my model class.
But as I do not consume any event from the topic on which I produce the event I am unable to use the consumer_for
helper and have to define test double to avoid the bug
@mensfeld wrote this in response to my question
need to decommission the subject from consumer reference and then for consumer specs use the subject but otherwise direct reference
NoMethodError:
undefined method `topic' for #<Visit id: "02d1b80e-4eae-4143-bde3-51ddc9a447a9", visited_at: "2022-10-19 09:04:58.147965000 +0000", visitor_id: "7e44f979-692d-4a4f-9ea8-03bdd2113e19", page_path: "0.3938326796841043">
I can repro with the example rails app. Trivial to fix.