In appearance, you do not have a target with identifier 1 in the database, so when you refer to self.target , the return value is nil. What would I do in your case, first create a target, and then pass your identifier to the attribute hashes:
target = Traget.create! attributes = { label: { name: "test", labeling: { target_type: "Link", target_id: target.id } } }
This way you do not need to drown anything. If you really have to stub the method, you can use the RSpecs any_instance method:
Labeling.any_instance.stub(:update_target).and_return(true)
source share