I'm sure this is answered somewhere; I can't seem to phrase my google search right though. I'm trying to test that a method is called on an object, but the method isn't called on the specific object in the spec. The method is called on the last item in a collection, which I've confirmed is the same underlying object as the one in the spec. I'm not sure how clear that was, so here is an example:
expect(@email).to receive(:send) # fails
puts @user.emails.last == @email # true
@user.emails.last.send
As a sanity check, this spec passes. However the code I'm testing has @user.emails.last.send in it, so I'm trying to figure out how to make the spec above pass.
expect(@email).to receive(:send) # passes
@email.send
Edit:
@user.emails.last.equal?(@email) returns false, so as suspected by @spickermann
and @Grzegorz the @user.emails.last and @email are two instances of the same object. So I guess what I'm asking is how can I test that the send method was called on a specific object (ignoring what particular instance of that object it was called on). My question is actually the same as this one that I just found Rspec: Test if instance method was called on specific record with ActiveRecord.