RSpec Stubs The Object In Memory - Kevin Murphy

20-Sep-2024 198
This test fails. We put a breakpoint in our test. We confirm that a post with the same database ID as draft does get the publish method called on it.Even though these objects pass the equality check, the issue is that they are not the same object in memory. Compare the object_id of the draft object to the object pulled out of the database. They’re different. The post published in DraftPost.publish_all does not have the stub applied to it.The stub operates on that draft object in memory, and only that object. Even though the other object is equal to the draft object, it is not the same as the draft object. Because of that, our assertion does not pass.
Use coupon code:

RUBYONRAILS

to get 30% discount on our bundle!
Prepare for your next tech interview with our comprehensive collection of programming interview guides. Covering JavaScript, Ruby on Rails, React, and Python, these highly-rated books offer thousands of essential questions and answers to boost your interview success. Buy our 'Ultimate Job Interview Preparation eBook Bundle' featuring 2200+ questions across multiple languages. Ultimate Job Interview Preparation eBook Bundle