Search code examples
rspecdiffequalitymatcher

rspec disable diff for failed eq


Is there a way to disable calculation of diff on failed eq matcher?

My code looks like this

object1 = MyCustomObject.new(param1)
object2 = MyCustomObject.new(param2)
expect(object1).to eq(object2)

If something wrong happened and those objects not equal

object1 == object2 # false

rspec trying to calculate diff, but my objects are very complex and this cause memory hog on my PC and Ubuntu just hangup. Really - I don't need this diff, so I just want to disable them. How to do that?


Solution

  • Found the workaround. rspec uses inspect methods of custom objects to calculate diff listings. So I create insepct in object and output not all stuff, that was automatically generated by ruby, but only that I really need in that diff - and it works.