Most Ruby mocking frameworks have the ability to mock a new object created via a constructor. However, when an object is created via ActiveRecord’s find
or find_by_*
methods, the .new
method isn’t invoked. Instead, the .instantiate
method is called.
For example, to specify :instantiate
as the object creation method using FlexMock: